summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_themes_incognito.js
blob: 6daa6dd812cb766645bbce0a22625c27838ad780 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";

add_task(async function test_theme_incognito_not_allowed() {
  let windowExtension = ExtensionTestUtils.loadExtension({
    incognitoOverride: "spanning",
    async background() {
      const theme = {
        colors: {
          frame: "black",
          tab_background_text: "black",
        },
      };
      let window = await browser.windows.create({ incognito: true });
      browser.test.onMessage.addListener(async message => {
        if (message == "update") {
          browser.theme.update(window.id, theme);
          return;
        }
        await browser.windows.remove(window.id);
        browser.test.sendMessage("done");
      });
      browser.test.sendMessage("ready", window.id);
    },
    manifest: {
      permissions: ["theme"],
    },
  });
  await windowExtension.startup();
  let wId = await windowExtension.awaitMessage("ready");

  async function background(windowId) {
    const theme = {
      colors: {
        frame: "black",
        tab_background_text: "black",
      },
    };

    browser.theme.onUpdated.addListener(() => {
      browser.test.log("got theme onChanged");
      browser.test.fail("theme");
    });
    await browser.test.assertRejects(
      browser.theme.getCurrent(windowId),
      /Invalid window ID/,
      "API should reject getting window theme"
    );
    await browser.test.assertRejects(
      browser.theme.update(windowId, theme),
      /Invalid window ID/,
      "API should reject updating theme"
    );
    await browser.test.assertRejects(
      browser.theme.reset(windowId),
      /Invalid window ID/,
      "API should reject reseting theme on window"
    );

    browser.test.sendMessage("start");
  }

  let extension = ExtensionTestUtils.loadExtension({
    background: `(${background})(${wId})`,
    manifest: {
      permissions: ["theme"],
    },
  });

  await extension.startup();
  await extension.awaitMessage("start");
  windowExtension.sendMessage("update");

  windowExtension.sendMessage("close");
  await windowExtension.awaitMessage("done");
  await windowExtension.unload();
  await extension.unload();
});