tor-browser

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

test_create_channel_chrome_url.js (952B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 
      5 "use strict";
      6 
      7 const { NetUtil } = ChromeUtils.importESModule(
      8  "resource://gre/modules/NetUtil.sys.mjs"
      9 );
     10 
     11 function testURL(url) {
     12  Services.io.newChannelFromURI(
     13    NetUtil.newURI(url),
     14    null, // aLoadingNode
     15    Services.scriptSecurityManager.getSystemPrincipal(),
     16    null, // aTriggeringPrincipal
     17    Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
     18    Ci.nsIContentPolicy.TYPE_OTHER
     19  );
     20 }
     21 
     22 add_task(async function test_create_channel_with_chrome_url() {
     23  try {
     24    testURL("chrome://path");
     25    Assert.ok(false);
     26  } catch (e) {
     27    // Chrome url fails canonicalization
     28    Assert.equal(e.result, Cr.NS_ERROR_FAILURE);
     29  }
     30 
     31  try {
     32    testURL("chrome://path/path/path");
     33    Assert.ok(false);
     34  } catch (e) {
     35    // Chrome url passes canonicalization
     36    Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
     37  }
     38 });