зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1324163 - Make sure loadFrameScript() is called before postMessage() for Indexeddb prompt tests, r=janv
This commit is contained in:
Родитель
45a6d9565c
Коммит
3704e21b9a
|
@ -16,7 +16,6 @@ support-files =
|
|||
[browser_forgetThisSite.js]
|
||||
[browser_permissionsPromptAllow.js]
|
||||
[browser_permissionsPromptDeny.js]
|
||||
skip-if = os == 'mac' # bug 1324163
|
||||
[browser_permissionsPromptWorker.js]
|
||||
[browser_perwindow_privateBrowsing.js]
|
||||
[browser_bug839193.js]
|
||||
|
|
|
@ -7,30 +7,38 @@ const testPageURL = "http://mochi.test:8888/browser/" +
|
|||
"dom/indexedDB/test/browser_permissionsPrompt.html";
|
||||
const notificationID = "indexedDB-permissions-prompt";
|
||||
|
||||
function promiseMessage(aMessage, browser) {
|
||||
return ContentTask.spawn(browser.selectedBrowser, aMessage, async function(aMessage) {
|
||||
await new Promise((resolve, reject) => {
|
||||
content.addEventListener("message", function(event) {
|
||||
is(event.data, aMessage, "received " + aMessage);
|
||||
if (event.data == aMessage)
|
||||
resolve();
|
||||
else
|
||||
reject();
|
||||
}, {once: true});
|
||||
function waitForMessage(aMessage, browser) {
|
||||
return new Promise((resolve, reject) => {
|
||||
function contentScript() {
|
||||
// eslint-disable-next-line no-undef
|
||||
addEventListener("message", function(event) {
|
||||
browser.messageManager.sendAsyncMessage("testLocal:exception",
|
||||
{exception: event.data});
|
||||
}, {once: true}, true);
|
||||
}
|
||||
|
||||
let script = "data:,(" + contentScript.toString() + ")();";
|
||||
|
||||
let mm = browser.selectedBrowser.messageManager;
|
||||
|
||||
mm.addMessageListener("testLocal:exception", function listener(msg) {
|
||||
mm.removeMessageListener("testLocal:exception", listener);
|
||||
mm.removeDelayedFrameScript(script);
|
||||
is(msg.data.exception, aMessage, "received " + aMessage);
|
||||
if (msg.data.exception == aMessage) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
|
||||
mm.loadFrameScript(script, true);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test1() {
|
||||
removePermission(testPageURL, "indexedDB");
|
||||
|
||||
info("creating tab");
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
||||
|
||||
info("loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function() {
|
||||
ok(true, "prompt showing");
|
||||
});
|
||||
|
@ -42,7 +50,12 @@ add_task(async function test1() {
|
|||
ok(true, "prompt hidden");
|
||||
});
|
||||
|
||||
await promiseMessage("InvalidStateError", gBrowser);
|
||||
info("creating tab");
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
||||
|
||||
info("loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
await waitForMessage("InvalidStateError", gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "indexedDB"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
|
@ -54,23 +67,22 @@ add_task(async function test2() {
|
|||
info("creating private window");
|
||||
let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
|
||||
|
||||
registerPopupEventHandler("popupshowing", function() {
|
||||
ok(false, "prompt showing");
|
||||
}, win);
|
||||
registerPopupEventHandler("popupshown", function() {
|
||||
ok(false, "prompt shown");
|
||||
}, win);
|
||||
registerPopupEventHandler("popuphidden", function() {
|
||||
ok(false, "prompt hidden");
|
||||
}, win);
|
||||
|
||||
info("creating private tab");
|
||||
win.gBrowser.selectedTab = win.gBrowser.addTab();
|
||||
|
||||
info("loading test page: " + testPageURL);
|
||||
win.gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function() {
|
||||
ok(false, "prompt showing");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function() {
|
||||
ok(false, "prompt shown");
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function() {
|
||||
ok(false, "prompt hidden");
|
||||
});
|
||||
await promiseMessage("InvalidStateError", win.gBrowser);
|
||||
await waitForMessage("InvalidStateError", win.gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "indexedDB"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
|
@ -81,13 +93,6 @@ add_task(async function test2() {
|
|||
});
|
||||
|
||||
add_task(async function test3() {
|
||||
info("creating tab");
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
||||
|
||||
info("loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function() {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
|
@ -98,7 +103,12 @@ add_task(async function test3() {
|
|||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
|
||||
await promiseMessage("InvalidStateError", gBrowser);
|
||||
info("creating tab");
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
||||
|
||||
info("loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
await waitForMessage("InvalidStateError", gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "indexedDB"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
|
|
|
@ -5,32 +5,45 @@
|
|||
|
||||
var gActiveListeners = {};
|
||||
|
||||
function registerPopupEventHandler(eventName, callback) {
|
||||
// These event (un)registration handlers only work for one window, DONOT use
|
||||
// them with multiple windows.
|
||||
function registerPopupEventHandler(eventName, callback, win) {
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
gActiveListeners[eventName] = function(event) {
|
||||
if (event.target != PopupNotifications.panel)
|
||||
if (event.target != win.PopupNotifications.panel)
|
||||
return;
|
||||
PopupNotifications.panel.removeEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
win.PopupNotifications.panel.removeEventListener(
|
||||
eventName,
|
||||
gActiveListeners[eventName]);
|
||||
delete gActiveListeners[eventName];
|
||||
|
||||
callback.call(PopupNotifications.panel);
|
||||
callback.call(win.PopupNotifications.panel);
|
||||
}
|
||||
PopupNotifications.panel.addEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
win.PopupNotifications.panel.addEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
}
|
||||
|
||||
function unregisterPopupEventHandler(eventName)
|
||||
function unregisterPopupEventHandler(eventName, win)
|
||||
{
|
||||
PopupNotifications.panel.removeEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
win.PopupNotifications.panel.removeEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
delete gActiveListeners[eventName];
|
||||
}
|
||||
|
||||
function unregisterAllPopupEventHandlers()
|
||||
function unregisterAllPopupEventHandlers(win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
for (let eventName in gActiveListeners) {
|
||||
PopupNotifications.panel.removeEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
win.PopupNotifications.panel.removeEventListener(
|
||||
eventName,
|
||||
gActiveListeners[eventName]);
|
||||
}
|
||||
gActiveListeners = {};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче