summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_browserAction_incognito.js
blob: e3f9ea97fa02f2c8e199640b2bbe754a087b0cbc (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

async function testIncognito(incognitoOverride) {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      browser_action: {
        default_area: "navbar",
      },
    },
    incognitoOverride,
  });

  // We test three windows, the public window, a private window prior
  // to extension start, and one created after.  This tests that CUI
  // creates the widgets (or not) as it should.
  let p1 = await BrowserTestUtils.openNewBrowserWindow({ private: true });
  await extension.startup();
  let p2 = await BrowserTestUtils.openNewBrowserWindow({ private: true });

  let action = getBrowserActionWidget(extension);
  await showBrowserAction(extension);
  await showBrowserAction(extension, p1);
  await showBrowserAction(extension, p2);

  ok(!!action.forWindow(window).node, "popup exists in non-private window");

  for (let win of [p1, p2]) {
    let node = action.forWindow(win).node;
    if (incognitoOverride == "spanning") {
      ok(!!node, "popup exists in private window");
    } else {
      ok(!node, "popup does not exist in private window");
    }

    await BrowserTestUtils.closeWindow(win);
  }
  await extension.unload();
}

add_task(async function test_browserAction_not_allowed() {
  await testIncognito();
});

add_task(async function test_browserAction_allowed() {
  await testIncognito("spanning");
});