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

Cu.import("resource://gre/modules/Preferences.jsm");

function* testBackgroundPage(expected) {
  let extension = ExtensionTestUtils.loadExtension({
    async background() {
      browser.test.assertEq(window, browser.extension.getBackgroundPage(),
                            "Caller should be able to access itself as a background page");
      browser.test.assertEq(window, await browser.runtime.getBackgroundPage(),
                            "Caller should be able to access itself as a background page");

      browser.test.sendMessage("incognito", browser.extension.inIncognitoContext);
    },
  });

  yield extension.startup();

  let incognito = yield extension.awaitMessage("incognito");
  equal(incognito, expected.incognito, "Expected incognito value");

  yield extension.unload();
}

add_task(function* test_background_incognito() {
  do_print("Test background page incognito value with permanent private browsing disabled");

  yield testBackgroundPage({incognito: false});

  do_print("Test background page incognito value with permanent private browsing enabled");

  Preferences.set("browser.privatebrowsing.autostart", true);
  do_register_cleanup(() => {
    Preferences.reset("browser.privatebrowsing.autostart");
  });

  yield testBackgroundPage({incognito: true});
});