summaryrefslogtreecommitdiffstats
path: root/chrome/test/unit/test_create_channel_chrome_url.js
blob: 19c154cba81c2a2e3a744349c02c04f8b84998c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

"use strict";

const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");

function testURL(url) {
  Services.io.newChannelFromURI(
    NetUtil.newURI(url),
    null, // aLoadingNode
    Services.scriptSecurityManager.getSystemPrincipal(),
    null, // aTriggeringPrincipal
    Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
    Ci.nsIContentPolicy.TYPE_OTHER
  );
}

add_task(async function test_create_channel_with_chrome_url() {
  try {
    testURL("chrome://path");
    Assert.ok(false);
  } catch (e) {
    // Chrome url fails canonicalization
    Assert.equal(e.result, Cr.NS_ERROR_FAILURE);
  }

  try {
    testURL("chrome://path/path/path");
    Assert.ok(false);
  } catch (e) {
    // Chrome url passes canonicalization
    Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
  }
});