зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1416153 - Part 0: Fix tests that uses BrowserTestUtils.waitForNewTab to perform the registration of the next event handler instantly inside the new tab event handler. r=Gijs
This commit is contained in:
Родитель
21905d169e
Коммит
53546e0355
|
@ -153,9 +153,7 @@ function delayedStartupFinished(aWindow) {
|
|||
* @resolves With the tab once it's loaded.
|
||||
*/
|
||||
function someTabLoaded(aWindow) {
|
||||
return BrowserTestUtils.waitForNewTab(gTestWindow.gBrowser).then((tab) => {
|
||||
return BrowserTestUtils.browserStopped(tab.linkedBrowser).then(() => tab);
|
||||
});
|
||||
return BrowserTestUtils.waitForNewTab(gTestWindow.gBrowser, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -138,13 +138,21 @@ add_task(async function test_ignoring_window_opener() {
|
|||
|
||||
await BrowserTestUtils.withNewTab(url, async function(browser) {
|
||||
// Clicking the link will spawn a new tab.
|
||||
let loaded = BrowserTestUtils.waitForNewTab(gBrowser, newTabURL);
|
||||
let stateChangePromise;
|
||||
let tabOpenPromise = new Promise(resolve => {
|
||||
gBrowser.tabContainer.addEventListener("TabOpen", event => {
|
||||
let tab = event.target;
|
||||
let newTabBrowser = tab.linkedBrowser;
|
||||
stateChangePromise = waitForInsecureLoginFormsStateChange(newTabBrowser, 2);
|
||||
resolve(tab);
|
||||
}, { once: true });
|
||||
});
|
||||
|
||||
await ContentTask.spawn(browser, {}, function() {
|
||||
content.document.getElementById("link").click();
|
||||
});
|
||||
let tab = await loaded;
|
||||
browser = tab.linkedBrowser;
|
||||
await waitForInsecureLoginFormsStateChange(browser, 2);
|
||||
let tab = await tabOpenPromise;
|
||||
await stateChangePromise;
|
||||
|
||||
// Open the identity popup.
|
||||
let { gIdentityHandler } = gBrowser.ownerGlobal;
|
||||
|
|
|
@ -22,7 +22,7 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
// Open new file:// tab from JavaScript in first file:// page.
|
||||
let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, openedUriString);
|
||||
let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, openedUriString, true);
|
||||
await ContentTask.spawn(tab.linkedBrowser, openedUriString, uri => {
|
||||
content.open(uri, "_blank");
|
||||
});
|
||||
|
@ -33,7 +33,6 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
let openedBrowser = openedTab.linkedBrowser;
|
||||
await BrowserTestUtils.browserLoaded(openedBrowser);
|
||||
|
||||
// Ensure that new file:// tab can be navigated to web content.
|
||||
openedBrowser.loadURI("http://example.org/");
|
||||
|
|
|
@ -30,7 +30,6 @@ add_task(async function test_view_source_in_tab() {
|
|||
}, async function(browser) {
|
||||
let sourceTab = await openViewSource(browser);
|
||||
let sourceBrowser = sourceTab.linkedBrowser;
|
||||
await waitForSourceLoaded(sourceBrowser);
|
||||
|
||||
await ContentTask.spawn(sourceBrowser, null, async function() {
|
||||
Assert.equal(content.document.body.id, "viewsource",
|
||||
|
@ -58,7 +57,6 @@ add_task(async function test_view_source_in_window() {
|
|||
url: "http://example.com",
|
||||
}, async function(browser) {
|
||||
let sourceWin = await openViewSource(browser);
|
||||
await waitForSourceLoaded(sourceWin);
|
||||
await ContentTask.spawn(sourceWin.gBrowser, null, async function() {
|
||||
Assert.equal(content.document.body.id, "viewsource",
|
||||
"View source mode enabled");
|
||||
|
|
|
@ -16,8 +16,6 @@ async function checkFrameSource() {
|
|||
gBrowser.removeTab(sourceTab);
|
||||
});
|
||||
|
||||
await waitForSourceLoaded(sourceTab);
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
let textContent = await ContentTask.spawn(browser, {}, async function() {
|
||||
return content.document.body.textContent;
|
||||
|
|
|
@ -47,27 +47,53 @@ function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) {
|
|||
});
|
||||
}
|
||||
|
||||
function waitForViewSourceWindow() {
|
||||
return new Promise(resolve => {
|
||||
let windowListener = {
|
||||
onOpenWindow(xulWindow) {
|
||||
let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
win.addEventListener("load", function() {
|
||||
if (win.document.documentElement.getAttribute("windowtype") !=
|
||||
WINDOW_TYPE) {
|
||||
return;
|
||||
}
|
||||
// Found the window
|
||||
resolve(win);
|
||||
Services.wm.removeListener(windowListener);
|
||||
}, {once: true});
|
||||
},
|
||||
onCloseWindow() {},
|
||||
onWindowTitleChange() {}
|
||||
};
|
||||
Services.wm.addListener(windowListener);
|
||||
});
|
||||
/**
|
||||
* Wait for view source tab or window after calling given function to open it.
|
||||
*
|
||||
* @param open - a function to open view source.
|
||||
* @returns the new tab or window which shows the source.
|
||||
*/
|
||||
async function waitForViewSourceTabOrWindow(open) {
|
||||
let sourceLoadedPromise;
|
||||
let tabOrWindowPromise;
|
||||
if (Services.prefs.getBoolPref("view_source.tab")) {
|
||||
tabOrWindowPromise = new Promise(resolve => {
|
||||
gBrowser.tabContainer.addEventListener("TabOpen", event => {
|
||||
let tab = event.target;
|
||||
sourceLoadedPromise = waitForSourceLoaded(tab);
|
||||
resolve(tab);
|
||||
}, { once: true });
|
||||
});
|
||||
} else {
|
||||
tabOrWindowPromise = new Promise(resolve => {
|
||||
let windowListener = {
|
||||
onOpenWindow(xulWindow) {
|
||||
let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
win.addEventListener("load", function() {
|
||||
if (win.document.documentElement.getAttribute("windowtype") !=
|
||||
WINDOW_TYPE) {
|
||||
return;
|
||||
}
|
||||
// Found the window
|
||||
sourceLoadedPromise = waitForSourceLoaded(win);
|
||||
resolve(win);
|
||||
Services.wm.removeListener(windowListener);
|
||||
}, {once: true});
|
||||
},
|
||||
onCloseWindow() {},
|
||||
onWindowTitleChange() {}
|
||||
};
|
||||
Services.wm.addListener(windowListener);
|
||||
});
|
||||
}
|
||||
|
||||
await open();
|
||||
|
||||
let tabOrWindow = await tabOrWindowPromise;
|
||||
await sourceLoadedPromise;
|
||||
|
||||
return tabOrWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,16 +103,9 @@ function waitForViewSourceWindow() {
|
|||
* @returns the new tab or window which shows the source.
|
||||
*/
|
||||
function openViewSource(browser) {
|
||||
let openPromise;
|
||||
if (Services.prefs.getBoolPref("view_source.tab")) {
|
||||
openPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
|
||||
} else {
|
||||
openPromise = waitForViewSourceWindow();
|
||||
}
|
||||
|
||||
window.BrowserViewSource(browser);
|
||||
|
||||
return openPromise;
|
||||
return waitForViewSourceTabOrWindow(() => {
|
||||
window.BrowserViewSource(browser);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,20 +126,13 @@ async function openViewPartialSource(aCSSSelector) {
|
|||
{ type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
|
||||
await popupShownPromise;
|
||||
|
||||
let openPromise;
|
||||
if (Services.prefs.getBoolPref("view_source.tab")) {
|
||||
openPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
|
||||
} else {
|
||||
openPromise = waitForViewSourceWindow();
|
||||
}
|
||||
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
|
||||
let item = document.getElementById("context-viewpartialsource-selection");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
await popupHiddenPromise;
|
||||
|
||||
return openPromise;
|
||||
return waitForViewSourceTabOrWindow(async () => {
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
|
||||
let item = document.getElementById("context-viewpartialsource-selection");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
await popupHiddenPromise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,15 +157,13 @@ async function openViewFrameSourceTab(aCSSSelector) {
|
|||
EventUtils.synthesizeMouseAtCenter(frameContextMenu, {});
|
||||
await popupShownPromise;
|
||||
|
||||
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
|
||||
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(frameContextMenu, "popuphidden");
|
||||
let item = document.getElementById("context-viewframesource");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
await popupHiddenPromise;
|
||||
|
||||
return newTabPromise;
|
||||
return waitForViewSourceTabOrWindow(async () => {
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(frameContextMenu, "popuphidden");
|
||||
let item = document.getElementById("context-viewframesource");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
await popupHiddenPromise;
|
||||
});
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
|
@ -198,12 +208,7 @@ async function openDocumentSelect(aURI, aCSSSelector) {
|
|||
content.getSelection().selectAllChildren(element);
|
||||
});
|
||||
|
||||
let tabOrWindow = await openViewPartialSource(aCSSSelector);
|
||||
|
||||
// Wait until the source has been loaded.
|
||||
await waitForSourceLoaded(tabOrWindow);
|
||||
|
||||
return tabOrWindow;
|
||||
return openViewPartialSource(aCSSSelector);
|
||||
}
|
||||
|
||||
function pushPrefs(...aPrefs) {
|
||||
|
|
|
@ -6,14 +6,12 @@ add_task(async function() {
|
|||
async function verify(link, button) {
|
||||
info("Clicking " + link);
|
||||
|
||||
let waitForNewTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
|
||||
let loadedPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
|
||||
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#" + link, { button },
|
||||
gBrowser.selectedBrowser);
|
||||
|
||||
let newtab = await waitForNewTabPromise;
|
||||
|
||||
await BrowserTestUtils.browserLoaded(newtab.linkedBrowser);
|
||||
let newtab = await loadedPromise;
|
||||
|
||||
let result = await ContentTask.spawn(newtab.linkedBrowser, { }, async function() {
|
||||
return (content.document.getElementById("enabled").textContent == "true");
|
||||
|
|
Загрузка…
Ссылка в новой задаче