Bug 1613796 - Return false when browser.permissions.request isn't called on the active tab. r=robwu

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
William Durand 2020-04-03 12:36:01 +00:00
Родитель b81d8b0f5d
Коммит f511c55b0e
3 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -184,6 +184,7 @@ skip-if = debug || os != 'win' # FIXME: re-enable on debug build (bug 1442822)
[browser_ext_port_disconnect_on_crash.js] [browser_ext_port_disconnect_on_crash.js]
skip-if = !e10s || !crashreporter # the tab's process is killed during the test. Without e10s the parent process would die too skip-if = !e10s || !crashreporter # the tab's process is killed during the test. Without e10s the parent process would die too
[browser_ext_port_disconnect_on_window_close.js] [browser_ext_port_disconnect_on_window_close.js]
[browser_ext_request_permissions.js]
[browser_ext_runtime_openOptionsPage.js] [browser_ext_runtime_openOptionsPage.js]
[browser_ext_runtime_openOptionsPage_uninstall.js] [browser_ext_runtime_openOptionsPage_uninstall.js]
[browser_ext_search.js] [browser_ext_search.js]

Просмотреть файл

@ -0,0 +1,38 @@
"use strict";
add_task(async function test_permissions_prompt() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
optional_permissions: ["history"],
},
background: () => {
browser.tabs.create({
url: browser.runtime.getURL("test.html"),
active: false,
});
},
files: {
"test.html": `<!DOCTYPE html><script src="test.js"></script>`,
"test.js": async () => {
const result = await new Promise(resolve => {
browser.test.withHandlingUserInput(() => {
resolve(browser.permissions.request({ permissions: ["history"] }));
});
});
browser.test.assertFalse(
result,
"permissions.request() from a hidden tab should be ignored"
);
browser.test.sendMessage("done");
},
},
});
await extension.startup();
await extension.awaitMessage("done");
// The extension tab is automatically closed upon unload.
await extension.unload();
});

Просмотреть файл

@ -372,6 +372,11 @@ var ExtensionsUI = {
await pending; await pending;
} }
// Make sure the tab is the active tab in the window.
if (window.gBrowser.selectedBrowser !== browser) {
return false;
}
let promise = new Promise(resolve => { let promise = new Promise(resolve => {
function eventCallback(topic) { function eventCallback(topic) {
let doc = this.browser.ownerDocument; let doc = this.browser.ownerDocument;