tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_simple_unknown_uris.js (2302B)


      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/. */
      4 
      5 /*
      6 *  Test that default uri is bypassable by an unknown protocol that is
      7 *  present in the bypass list (and the pref is enabled)
      8 */
      9 "use strict";
     10 
     11 const {
     12  checkInputAndSerializationMatch,
     13  checkSerializationMissingSecondColon,
     14 } = ChromeUtils.importESModule(
     15  "resource://testing-common/simple_unknown_uri_helpers.sys.mjs"
     16 );
     17 
     18 function inChildProcess() {
     19  return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
     20 }
     21 
     22 function run_test() {
     23  // In-Parent-only process pref setup
     24  if (!inChildProcess()) {
     25    // child-test sets these in test_simple_unknown_uris_wrap.js
     26    Services.prefs.setBoolPref("network.url.useDefaultURI", true);
     27    Services.prefs.setBoolPref(
     28      "network.url.simple_uri_unknown_schemes_enabled",
     29      true
     30    );
     31    Services.prefs.setCharPref(
     32      "network.url.simple_uri_unknown_schemes",
     33      "simpleprotocol,otherproto"
     34    );
     35  }
     36 
     37  // sanity check: non-nested special url is fine
     38  checkInputAndSerializationMatch("https://example.com/");
     39 
     40  // nsStandardURL removes second colon when nesting protocols
     41  checkSerializationMissingSecondColon("https://https://example.com/");
     42 
     43  // no-bypass for unknown protocol uses defaultURI
     44  checkSerializationMissingSecondColon(
     45    "nonsimpleprotocol://https://example.com"
     46  );
     47 
     48  // an unknown protocol in the bypass list will use simpleURI
     49  checkInputAndSerializationMatch("simpleprotocol://https://example.com");
     50 
     51  // setCharPref not accessible from child process
     52  if (!inChildProcess()) {
     53    // check that pref update removes simpleprotocol from bypass list
     54    Services.prefs.setCharPref(
     55      "network.url.simple_uri_unknown_schemes",
     56      "otherproto"
     57    );
     58    checkSerializationMissingSecondColon(
     59      "simpleprotocol://https://example.com"
     60    );
     61 
     62    // check that spaces are parsed out
     63    Services.prefs.setCharPref(
     64      "network.url.simple_uri_unknown_schemes",
     65      " simpleprotocol , otherproto "
     66    );
     67    checkInputAndSerializationMatch("simpleprotocol://https://example.com");
     68    checkInputAndSerializationMatch("otherproto://https://example.com");
     69  }
     70 }