summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/test_ext_inIncognitoContext_window.html
blob: 5b369025814ca6defd2cc07902368416cd769f95 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>WebExtension test</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

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

add_task(async function test_in_incognito_context_true() {
  function background() {
    browser.runtime.onMessage.addListener(msg => {
      browser.test.assertEq(true, msg, "inIncognitoContext is true");
      browser.test.notifyPass("inIncognitoContext");
    });

    browser.windows.create({url: browser.runtime.getURL("/tab.html"), incognito: true});
  }

  function tabScript() {
    browser.runtime.sendMessage(browser.extension.inIncognitoContext);
  }

  let extension = ExtensionTestUtils.loadExtension({
    background,
    files: {
      "tab.js": tabScript,
      "tab.html": `<!DOCTYPE html><html><head>
        <meta charset="utf-8">
        <script src="tab.js"><\/script>
      </head></html>`,
    },
    incognitoOverride: "spanning",
  });

  await extension.startup();
  await extension.awaitFinish("inIncognitoContext");
  await extension.unload();
});

</script>

</body>
</html>