forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1525718 fix setting private permission when private browsing r=rpl
Setting the permission has to happen after the call to parseManifest so it may be set if the manifest is already cached. Also grant permission when installed from permanent private browsing. Differential Revision: https://phabricator.services.mozilla.com/D18879 --HG-- extra : moz-landing-system : lando
- Loading branch information
1 parent
99c8e0c
commit b9a80cb
Showing
2 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,17 @@ | |
/* vim: set sts=2 sw=2 et tw=80: */ | ||
"use strict"; | ||
|
||
const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm"); | ||
const {ExtensionPermissions} = ChromeUtils.import("resource://gre/modules/ExtensionPermissions.jsm"); | ||
|
||
AddonTestUtils.init(this); | ||
AddonTestUtils.overrideCertDB(); | ||
AddonTestUtils.createAppInfo("[email protected]", "XPCShell", "1", "1"); | ||
AddonTestUtils.usePrivilegedSignatures = false; | ||
|
||
add_task(async function test_background_incognito() { | ||
info("Test background page incognito value with permanent private browsing enabled"); | ||
await AddonTestUtils.promiseStartupManager(); | ||
|
||
Services.prefs.setBoolPref("extensions.allowPrivateBrowsingByDefault", false); | ||
Services.prefs.setBoolPref("browser.privatebrowsing.autostart", true); | ||
|
@@ -12,8 +21,16 @@ add_task(async function test_background_incognito() { | |
Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault"); | ||
}); | ||
|
||
let extensionId = "@permTest"; | ||
// We do not need to override incognito here, an extension installed during | ||
// permanent private browsing gets the permission during install. | ||
let extension = ExtensionTestUtils.loadExtension({ | ||
incognitoOverride: "spanning", | ||
useAddonManager: "permanent", | ||
manifest: { | ||
applications: { | ||
gecko: {id: extensionId}, | ||
}, | ||
}, | ||
async background() { | ||
browser.test.assertEq(window, browser.extension.getBackgroundPage(), | ||
"Caller should be able to access itself as a background page"); | ||
|
@@ -23,12 +40,42 @@ add_task(async function test_background_incognito() { | |
browser.test.assertEq(browser.extension.inIncognitoContext, true, | ||
"inIncognitoContext is true for permanent private browsing"); | ||
|
||
browser.test.notifyPass("incognito"); | ||
browser.test.sendMessage("incognito"); | ||
}, | ||
}); | ||
|
||
// Startup reason is ADDON_INSTALL | ||
await extension.startup(); | ||
|
||
await extension.awaitFinish("incognito"); | ||
await extension.awaitMessage("incognito"); | ||
|
||
let addon = await AddonManager.getAddonByID(extensionId); | ||
await addon.disable(); | ||
|
||
// Permission remains when an extension is disabled. | ||
let perms = await ExtensionPermissions.get(extensionId); | ||
equal(perms.permissions.length, 1, "one permission"); | ||
equal(perms.permissions[0], "internal:privateBrowsingAllowed", "internal permission present"); | ||
|
||
// Startup reason is ADDON_ENABLE, the permission is | ||
// not granted in this case, but the extension should | ||
// still have permission. | ||
await addon.enable(); | ||
await Promise.all([ | ||
extension.awaitStartup(), | ||
extension.awaitMessage("incognito"), | ||
]); | ||
|
||
// ExtensionPermissions should still have it. | ||
perms = await ExtensionPermissions.get(extensionId); | ||
equal(perms.permissions.length, 1, "one permission"); | ||
equal(perms.permissions[0], "internal:privateBrowsingAllowed", "internal permission present"); | ||
|
||
// This is the same as uninstall, no permissions after. | ||
await extension.unload(); | ||
|
||
perms = await ExtensionPermissions.get(extensionId); | ||
equal(perms.permissions.length, 0, "no permission"); | ||
|
||
await AddonTestUtils.promiseShutdownManager(); | ||
}); |