summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/test_chrome_ext_trustworthy_origin.html
blob: 573c088065d7450c91b205cf79df5fbe886dca6d (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE HTML>
<html>
<head>
  <title>WebExtension test</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="chrome_head.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="text/javascript">
"use strict";

/**
 * This test is asserting that moz-extension: URLs are recognized as trustworthy local origins
 */

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
                                   "@mozilla.org/contentsecuritymanager;1",
                                   "nsIContentSecurityManager");

add_task(function* () {
  function background() {
    browser.test.sendMessage("ready", browser.runtime.getURL("/test.html"));
  }

  let extensionData = {
    background,
    files: {
      "test.html": `<html><head></head><body></body></html>`,
    },
  };

  let extension = ExtensionTestUtils.loadExtension(extensionData);
  yield extension.startup();

  let url = yield extension.awaitMessage("ready");

  let uri = NetUtil.newURI(url);
  let principal = Services.scriptSecurityManager.getCodebasePrincipal(uri);
  is(gContentSecurityManager.isOriginPotentiallyTrustworthy(principal), true);

  yield extension.unload();
});
</script>

</body>
</html>