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:
Tooru Fujisawa 2017-11-24 07:50:12 +09:00
Родитель 21905d169e
Коммит 53546e0355
7 изменённых файлов: 81 добавлений и 77 удалений

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

@ -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,8 +47,25 @@ function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) {
});
}
function waitForViewSourceWindow() {
return new Promise(resolve => {
/**
* 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)
@ -59,6 +76,7 @@ function waitForViewSourceWindow() {
return;
}
// Found the window
sourceLoadedPromise = waitForSourceLoaded(win);
resolve(win);
Services.wm.removeListener(windowListener);
}, {once: true});
@ -68,6 +86,14 @@ function waitForViewSourceWindow() {
};
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();
}
return waitForViewSourceTabOrWindow(() => {
window.BrowserViewSource(browser);
return openPromise;
});
}
/**
@ -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();
}
return waitForViewSourceTabOrWindow(async () => {
let popupHiddenPromise =
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
let item = document.getElementById("context-viewpartialsource-selection");
EventUtils.synthesizeMouseAtCenter(item, {});
await popupHiddenPromise;
return openPromise;
});
}
/**
@ -145,15 +157,13 @@ async function openViewFrameSourceTab(aCSSSelector) {
EventUtils.synthesizeMouseAtCenter(frameContextMenu, {});
await popupShownPromise;
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
return waitForViewSourceTabOrWindow(async () => {
let popupHiddenPromise =
BrowserTestUtils.waitForEvent(frameContextMenu, "popuphidden");
let item = document.getElementById("context-viewframesource");
EventUtils.synthesizeMouseAtCenter(item, {});
await popupHiddenPromise;
return newTabPromise;
});
}
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");