Bug 1088710 - part 3: wait for STATE_STOP as well as load, r?mconley
MozReview-Commit-ID: 3ztx6kPOdON
--- a/browser/components/customizableui/test/browser_967000_button_charEncoding.js
+++ b/browser/components/customizableui/test/browser_967000_button_charEncoding.js
@@ -20,17 +20,17 @@ add_task(function*() {
ok(charEncodingButton, "The Character Encoding button was added to the Panel Menu");
is(charEncodingButton.getAttribute("disabled"), "true",
"The Character encoding button is initially disabled");
let panelHidePromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHidePromise;
- let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE, true);
+ let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE, true, true);
yield PanelUI.show();
ok(!charEncodingButton.hasAttribute("disabled"), "The Character encoding button gets enabled");
let characterEncodingView = document.getElementById("PanelUI-characterEncodingView");
let subviewShownPromise = subviewShown(characterEncodingView);
charEncodingButton.click();
yield subviewShownPromise;
--- a/browser/components/customizableui/test/browser_987640_charEncoding.js
+++ b/browser/components/customizableui/test/browser_987640_charEncoding.js
@@ -8,17 +8,17 @@ const TEST_PAGE = "http://mochi.test:888
add_task(function*() {
info("Check Character Encoding panel functionality");
// add the Character Encoding button to the panel
CustomizableUI.addWidgetToArea("characterencoding-button",
CustomizableUI.AREA_PANEL);
- let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE, true);
+ let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE, true, true);
yield PanelUI.show();
let charEncodingButton = document.getElementById("characterencoding-button");
let characterEncodingView = document.getElementById("PanelUI-characterEncodingView");
let subviewShownPromise = subviewShown(characterEncodingView);
charEncodingButton.click();
yield subviewShownPromise;
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -78,33 +78,36 @@ this.BrowserTestUtils = {
* will be called to open a foreground tab. Defaults to "about:blank".
* @param {boolean} waitForLoad
* True to wait for the page in the new tab to load. Defaults to true.
*
* @return {Promise}
* Resolves when the tab is ready and loaded as necessary.
* @resolves The new tab.
*/
- openNewForegroundTab(tabbrowser, opening = "about:blank", aWaitForLoad = true) {
+ openNewForegroundTab(tabbrowser, opening = "about:blank", aWaitForLoad = true, aWaitForStateStop = true) {
let tab;
let promises = [
BrowserTestUtils.switchTab(tabbrowser, function () {
if (typeof opening == "function") {
opening();
tab = tabbrowser.selectedTab;
}
else {
tabbrowser.selectedTab = tab = tabbrowser.addTab(opening);
}
})
];
if (aWaitForLoad) {
promises.push(BrowserTestUtils.browserLoaded(tab.linkedBrowser));
}
+ if (aWaitForStateStop) {
+ promises.push(BrowserTestUtils.browserStopped(tab.linkedBrowser));
+ }
return Promise.all(promises).then(() => tab);
},
/**
* Switches to a tab and resolves when it is ready.
*
* @param {tabbrowser} tabbrowser
@@ -174,16 +177,45 @@ this.BrowserTestUtils = {
mm.removeMessageListener("browser-test-utils:loadEvent", onLoad);
resolve(msg.data.url);
}
});
});
},
/**
+ * Waits for the web progress listener associated with this tab to fire a
+ * STATE_STOP for the toplevel document.
+ *
+ * @param {xul:browser} browser
+ * A xul:browser.
+ *
+ * @return {Promise}
+ * @resolves When STATE_STOP reaches the tab's progress listener
+ */
+ browserStopped(browser) {
+ return new Promise(resolve => {
+ let wpl = {
+ onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
+ if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
+ aWebProgress.isTopLevel) {
+ browser.webProgress.removeProgressListener(wpl);
+ resolve();
+ };
+ },
+ onSecurityChange() {},
+ onStatusChange() {},
+ onLocationChange() {},
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener2, Ci.nsIWebProgressListener])
+ };
+ browser.webProgress.addProgressListener(wpl);
+ });
+ },
+
+ /**
* Waits for the next tab to open and load a given URL.
*
* The method doesn't wait for the tab contents to load.
*
* @param {tabbrowser} tabbrowser
* The tabbrowser to look for the next new tab in.
* @param {string} url
* A string URL to look for in the new tab. If null, allows any non-blank URL.