зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1630211 - P3. Use new domWindowOpenedAndLoaded where we can. r=Gijs
Remove duplicated code; and properly wait for the window to be loaded where needed. Differential Revision: https://phabricator.services.mozilla.com/D72879
This commit is contained in:
Родитель
27013ebd1b
Коммит
a50346320b
|
@ -20,7 +20,7 @@ add_task(async function() {
|
|||
ok(homeButton, "home button present");
|
||||
|
||||
async function drop(dragData, homepage) {
|
||||
let setHomepageDialogPromise = BrowserTestUtils.domWindowOpened();
|
||||
let setHomepageDialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
|
||||
EventUtils.synthesizeDrop(
|
||||
dragSrcElement,
|
||||
|
@ -34,7 +34,6 @@ add_task(async function() {
|
|||
|
||||
let setHomepageDialog = await setHomepageDialogPromise;
|
||||
ok(true, "dialog appeared in response to home button drop");
|
||||
await BrowserTestUtils.waitForEvent(setHomepageDialog, "load", false);
|
||||
|
||||
let setHomepagePromise = new Promise(function(resolve) {
|
||||
let observer = {
|
||||
|
|
|
@ -7,35 +7,6 @@
|
|||
|
||||
const PAGE = `data:text/html,<a id="target" href="%23" onclick="window.open('http://www.example.com', '_blank', 'width=100,height=100');">Click me</a>`;
|
||||
|
||||
/**
|
||||
* Returns a Promise that resolves when a new window has
|
||||
* opened, and the "load" event has fired in that window.
|
||||
* We can't use BrowserTestUtils.domWindowOpened directly,
|
||||
* because by the time the "then" on the Promise runs,
|
||||
* DOMContentLoaded and load may have already run in the new
|
||||
* window. However, we want to be very explicit about what
|
||||
* events we're waiting for, and not rely on a quirk of our
|
||||
* Promises infrastructure.
|
||||
*/
|
||||
function promiseNewWindow() {
|
||||
return new Promise(resolve => {
|
||||
let observer = (win, topic, data) => {
|
||||
if (topic == "domwindowopened") {
|
||||
Services.ww.unregisterNotification(observer);
|
||||
win.addEventListener(
|
||||
"load",
|
||||
function() {
|
||||
resolve(win);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Services.ww.registerNotification(observer);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a new window is opened from content, focus moves
|
||||
* to the initial browser in that window once the window has finished
|
||||
|
@ -48,7 +19,7 @@ add_task(async function test_focus_browser() {
|
|||
gBrowser,
|
||||
},
|
||||
async function(browser) {
|
||||
let newWinPromise = promiseNewWindow();
|
||||
let newWinPromise = BrowserTestUtils.domWindowOpenedAndLoaded(null);
|
||||
let delayedStartupPromise = BrowserTestUtils.waitForNewWindow();
|
||||
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#target", {}, browser);
|
||||
|
@ -88,7 +59,7 @@ add_task(async function test_no_steal_focus() {
|
|||
gBrowser,
|
||||
},
|
||||
async function(browser) {
|
||||
let newWinPromise = promiseNewWindow();
|
||||
let newWinPromise = BrowserTestUtils.domWindowOpenedAndLoaded(null);
|
||||
let delayedStartupPromise = BrowserTestUtils.waitForNewWindow();
|
||||
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#target", {}, browser);
|
||||
|
|
|
@ -12,7 +12,7 @@ add_task(async function setup() {
|
|||
});
|
||||
|
||||
add_task(async function test_open_import() {
|
||||
let promiseImportWindow = BrowserTestUtils.domWindowOpened();
|
||||
let promiseImportWindow = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("menu-button", {}, browser);
|
||||
|
@ -42,10 +42,6 @@ add_task(async function test_open_import() {
|
|||
info("waiting for Import to get opened");
|
||||
let importWindow = await promiseImportWindow;
|
||||
ok(true, "Import opened");
|
||||
await TestUtils.waitForCondition(
|
||||
() => importWindow.document.readyState == "complete",
|
||||
"waiting for Import to fully load before closing it so observers will be correctly removed"
|
||||
);
|
||||
|
||||
importWindow.close();
|
||||
});
|
||||
|
|
|
@ -53,7 +53,7 @@ Tests the alwaysOnTop window feature for the Windows OS.
|
|||
ok(false, "This test is only designed to run on Windows.");
|
||||
} else {
|
||||
add_task(async function() {
|
||||
let normalWinOpened = BrowserTestUtils.domWindowOpened();
|
||||
let normalWinOpened = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
window.openDialog("about:blank",
|
||||
"_blank", "chrome,width=100,height=100,noopener", null);
|
||||
let normalWin = await normalWinOpened;
|
||||
|
@ -61,7 +61,7 @@ Tests the alwaysOnTop window feature for the Windows OS.
|
|||
assertAlwaysOnTop(normalWin, false);
|
||||
await BrowserTestUtils.closeWindow(normalWin);
|
||||
|
||||
let alwaysOnTopWinOpened = BrowserTestUtils.domWindowOpened();
|
||||
let alwaysOnTopWinOpened = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
window.openDialog("about:blank",
|
||||
"_blank", "chrome,width=100,height=100,alwaysOnTop,noopener", null);
|
||||
let alwaysOnTopWin = await alwaysOnTopWinOpened;
|
||||
|
|
|
@ -101,7 +101,7 @@ async function openHelperAppDialog(launcher) {
|
|||
"@mozilla.org/helperapplauncherdialog;1"
|
||||
].createInstance(Ci.nsIHelperAppLauncherDialog);
|
||||
|
||||
let helperAppDialogShownPromise = BrowserTestUtils.domWindowOpened();
|
||||
let helperAppDialogShownPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
try {
|
||||
helperAppDialog.show(launcher, window, "foopy");
|
||||
} catch (ex) {
|
||||
|
@ -113,8 +113,6 @@ async function openHelperAppDialog(launcher) {
|
|||
}
|
||||
let dlg = await helperAppDialogShownPromise;
|
||||
|
||||
await BrowserTestUtils.waitForEvent(dlg, "load", false);
|
||||
|
||||
is(
|
||||
dlg.location.href,
|
||||
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
|
||||
|
|
Загрузка…
Ссылка в новой задаче