summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xrays.js
blob: 30ec8ceced40c44a6c0d72235dffb8c75301849c (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
54
55
56
57
58
59
"use strict";

// ExtensionContent.sys.mjs needs to know when it's running from xpcshell,
// to use the right timeout for content scripts executed at document_idle.
ExtensionTestUtils.mockAppInfo();

const server = createHttpServer();
server.registerDirectory("/data/", do_get_file("data"));

const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;

add_task(async function test_contentscript_xrays() {
  async function contentScript() {
    let unwrapped = window.wrappedJSObject;

    browser.test.assertEq(
      "undefined",
      typeof test,
      "Should not have named X-ray property access"
    );
    browser.test.assertEq(
      undefined,
      window.test,
      "Should not have named X-ray property access"
    );
    browser.test.assertEq(
      "object",
      typeof unwrapped.test,
      "Should always have non-X-ray named property access"
    );

    browser.test.notifyPass("contentScriptXrays");
  }

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      content_scripts: [
        {
          matches: ["http://*/*/file_sample.html"],
          js: ["content_script.js"],
        },
      ],
    },

    files: {
      "content_script.js": contentScript,
    },
  });

  await extension.startup();
  let contentPage = await ExtensionTestUtils.loadContentPage(
    `${BASE_URL}/file_sample.html`
  );

  await extension.awaitFinish("contentScriptXrays");

  await contentPage.close();
  await extension.unload();
});