1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Test that default uri is bypassable by an unknown protocol that is
7 * present in the bypass list (and the pref is enabled)
11 function inChildProcess() {
12 return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
16 // In-Parent-only process pref setup
17 if (!inChildProcess()) {
18 Services.prefs.setBoolPref("network.url.useDefaultURI", true);
19 Services.prefs.setBoolPref(
20 "network.url.some_schemes_bypass_defaultURI_fallback",
24 Services.prefs.setCharPref(
25 "network.url.simple_uri_schemes",
26 "simpleprotocol,otherproto"
30 // check valid url is fine
31 let uri = NetUtil.newURI("https://example.com/");
32 Assert.equal(uri.spec, "https://example.com/"); // same
34 // nsStandardURL removes second colon when nesting protocols
35 let uri1 = NetUtil.newURI("https://https://example.com/");
36 Assert.equal(uri1.spec, "https://https//example.com/");
38 // defaultUri removes second colon
39 // no-bypass protocol uses defaultURI
40 let uri2 = NetUtil.newURI("nonsimpleprotocol://https://example.com");
41 Assert.equal(uri2.spec, "nonsimpleprotocol://https//example.com");
43 // simpleURI keeps the second colon
44 // an unknown protocol in the bypass list will use simpleURI
45 // despite network.url.useDefaultURI being enabled
46 let same = "simpleprotocol://https://example.com";
47 let uri3 = NetUtil.newURI(same);
48 Assert.equal(uri3.spec, same); // simple uri keeps second colon
50 // setCharPref not accessible from child process
51 if (!inChildProcess()) {
52 // check that pref update removes simpleprotocol from bypass list
53 Services.prefs.setCharPref("network.url.simple_uri_schemes", "otherproto");
54 let uri4 = NetUtil.newURI("simpleprotocol://https://example.com");
55 Assert.equal(uri4.spec, "simpleprotocol://https//example.com"); // default uri removes second colon
57 // check that spaces are parsed out
58 Services.prefs.setCharPref(
59 "network.url.simple_uri_schemes",
60 " simpleprotocol , otherproto "
62 let uri5 = NetUtil.newURI("simpleprotocol://https://example.com");
63 Assert.equal(uri5.spec, "simpleprotocol://https://example.com"); // simple uri keeps second colon
64 let uri6 = NetUtil.newURI("otherproto://https://example.com");
65 Assert.equal(uri6.spec, "otherproto://https://example.com"); // simple uri keeps second colon