summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_background_api_injection.js
blob: 2a0bdba156538ffb9f6cb6c17b9174df98a63b39 (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
"use strict";

const server = createHttpServer({ hosts: ["example.com"] });
server.registerDirectory("/data/", do_get_file("data"));

add_task(async function testBackgroundWindow() {
  // Background navigates to http:-URL.
  // TODO bug 1286083: Disallow background navigation.
  allow_unsafe_parent_loads_when_extensions_not_remote();

  let extension = ExtensionTestUtils.loadExtension({
    background() {
      browser.test.log("background script executed");
      window.location =
        "http://example.com/data/file_privilege_escalation.html";
    },
  });

  let awaitConsole = new Promise(resolve => {
    Services.console.registerListener(function listener(message) {
      if (/WebExt Privilege Escalation/.test(message.message)) {
        Services.console.unregisterListener(listener);
        resolve(message);
      }
    });
  });

  await extension.startup();

  let message = await awaitConsole;
  ok(
    message.message.includes(
      "WebExt Privilege Escalation: typeof(browser) = undefined"
    ),
    "Document does not have `browser` APIs."
  );

  await extension.unload();

  revert_allow_unsafe_parent_loads_when_extensions_not_remote();
});