зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1369581 - Requesting an optional permission that does not cause a prompt should succeed, r=aswan
Currently, if an extension requests one or more optional permissions, and those permissions do not cause a prompt to be displayed, the framework will reject that request and not grant any permissions. This should be the opposite in that we should grant permission to those optional permissions event though no prompt is displayed. MozReview-Commit-ID: 6SeyFSv92Lo --HG-- extra : rebase_source : 08ba28ca7920c9d37af28afa24d9602813b4470b
This commit is contained in:
Родитель
754a9682b2
Коммит
2c05852936
|
@ -3,5 +3,9 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"extends": [
|
"extends": [
|
||||||
"plugin:mozilla/browser-test"
|
"plugin:mozilla/browser-test"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"env": {
|
||||||
|
"webextensions": true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@ support-files =
|
||||||
[browser_permissions_installTrigger.js]
|
[browser_permissions_installTrigger.js]
|
||||||
[browser_permissions_local_file.js]
|
[browser_permissions_local_file.js]
|
||||||
[browser_permissions_mozAddonManager.js]
|
[browser_permissions_mozAddonManager.js]
|
||||||
|
[browser_permissions_optional.js]
|
||||||
[browser_permissions_unsigned.js]
|
[browser_permissions_unsigned.js]
|
||||||
skip-if = require_signing
|
skip-if = require_signing
|
||||||
[browser_update_checkForUpdates.js]
|
[browser_update_checkForUpdates.js]
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
"use strict";
|
||||||
|
add_task(async function test_request_permissions_without_prompt() {
|
||||||
|
async function pageScript() {
|
||||||
|
const NO_PROMPT_PERM = "activeTab";
|
||||||
|
window.addEventListener("keypress", async () => {
|
||||||
|
let permGranted = await browser.permissions.request(
|
||||||
|
{permissions: [NO_PROMPT_PERM]});
|
||||||
|
browser.test.assertTrue(permGranted,
|
||||||
|
`${NO_PROMPT_PERM} permission was granted.`);
|
||||||
|
let perms = await browser.permissions.getAll();
|
||||||
|
browser.test.assertTrue(perms.permissions.includes(NO_PROMPT_PERM),
|
||||||
|
`${NO_PROMPT_PERM} permission exists.`)
|
||||||
|
browser.test.sendMessage("permsGranted");
|
||||||
|
}, {once: true});
|
||||||
|
browser.test.sendMessage("pageReady");
|
||||||
|
}
|
||||||
|
|
||||||
|
let extension = ExtensionTestUtils.loadExtension({
|
||||||
|
background() {
|
||||||
|
browser.test.sendMessage("ready", browser.runtime.getURL("page.html"));
|
||||||
|
},
|
||||||
|
files: {
|
||||||
|
"page.html": `<html><head><script src="page.js"></script></head></html>`,
|
||||||
|
"page.js": pageScript,
|
||||||
|
},
|
||||||
|
manifest: {
|
||||||
|
"optional_permissions": [
|
||||||
|
"activeTab"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await extension.startup();
|
||||||
|
|
||||||
|
let url = await extension.awaitMessage("ready");
|
||||||
|
let win = window.open(url);
|
||||||
|
await extension.awaitMessage("pageReady");
|
||||||
|
|
||||||
|
let winutils = SpecialPowers.getDOMWindowUtils(win);
|
||||||
|
winutils.sendKeyEvent("keypress", KeyEvent.DOM_VK_A, 0, 0);
|
||||||
|
await extension.awaitMessage("permsGranted");
|
||||||
|
|
||||||
|
await extension.unload();
|
||||||
|
});
|
|
@ -234,7 +234,7 @@ this.ExtensionsUI = {
|
||||||
|
|
||||||
// If we don't have any promptable permissions, just proceed
|
// If we don't have any promptable permissions, just proceed
|
||||||
if (strings.msgs.length == 0) {
|
if (strings.msgs.length == 0) {
|
||||||
resolve();
|
resolve(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче