fune/browser/components/extensions/test/browser/browser_ext_windows_incognito.js
Shane Caraveo 050ca2e7d4 Bug 1511636: update incognito support to use pref and permissions r=rpl,aswan,kmag
This changes the policy to use the pref and permissions rather than a boolean flag.  Using permissions gets us proper settings on startup without introducing any new overhead.  Going this way flips our tests around so rather than testing an override to turn off private browsing support, we test overrides to enable private browsing support.

Differential Revision: https://phabricator.services.mozilla.com/D14482

--HG--
extra : moz-landing-system : lando
2019-01-28 18:10:47 +00:00

52 lines
2.4 KiB
JavaScript

/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(async function test_window_incognito() {
SpecialPowers.pushPrefEnv({set: [
["extensions.allowPrivateBrowsingByDefault", false],
]});
const url = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/file_iframe_document.html";
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["http://mochi.test/"],
},
background() {
browser.test.onMessage.addListener(async pbw => {
await browser.test.assertRejects(browser.windows.get(pbw.windowId),
/Invalid window ID/,
"should not be able to get incognito window");
await browser.test.assertRejects(browser.windows.remove(pbw.windowId),
/Invalid window ID/,
"should not be able to remove incognito window");
await browser.test.assertRejects(browser.windows.getCurrent(),
/Invalid window/,
"should not be able to get incognito top window");
await browser.test.assertRejects(browser.windows.getLastFocused(),
/Invalid window/,
"should not be able to get incognito focused window");
await browser.test.assertRejects(browser.windows.create({incognito: true}),
/Extension does not have permission for incognito mode/,
"should not be able to create incognito window");
await browser.test.assertRejects(browser.windows.update(pbw.windowId, {focused: true}),
/Invalid window ID/,
"should not be able to update incognito window");
let windows = await browser.windows.getAll();
browser.test.assertEq(1, windows.length, "unable to get incognito window");
browser.test.notifyPass("pass");
});
},
});
let winData = await getIncognitoWindow(url);
await extension.startup();
extension.sendMessage(winData.details);
await extension.awaitFinish("pass");
await BrowserTestUtils.closeWindow(winData.win);
await extension.unload();
});