зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1088710 - part 3: wait for STATE_STOP as well as load, r=mconley
MozReview-Commit-ID: 3ztx6kPOdON --HG-- extra : rebase_source : 4ddfbdf9c641e020dba66e5c642513f8dd0fb061
This commit is contained in:
Родитель
0a197aae91
Коммит
3b845c302c
|
@ -25,7 +25,7 @@ add_task(function*() {
|
|||
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");
|
||||
|
|
|
@ -13,7 +13,7 @@ add_task(function*() {
|
|||
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");
|
||||
|
|
|
@ -78,12 +78,15 @@ 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.
|
||||
* @param {boolean} waitForStateStop
|
||||
* True to wait for the web progress listener to send STATE_STOP for the
|
||||
* document in the tab. Defaults to false.
|
||||
*
|
||||
* @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 = false) {
|
||||
let tab;
|
||||
let promises = [
|
||||
BrowserTestUtils.switchTab(tabbrowser, function () {
|
||||
|
@ -100,6 +103,9 @@ this.BrowserTestUtils = {
|
|||
if (aWaitForLoad) {
|
||||
promises.push(BrowserTestUtils.browserLoaded(tab.linkedBrowser));
|
||||
}
|
||||
if (aWaitForStateStop) {
|
||||
promises.push(BrowserTestUtils.browserStopped(tab.linkedBrowser));
|
||||
}
|
||||
|
||||
return Promise.all(promises).then(() => tab);
|
||||
},
|
||||
|
@ -178,6 +184,42 @@ this.BrowserTestUtils = {
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 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(filter);
|
||||
filter.removeProgressListener(wpl);
|
||||
resolve();
|
||||
};
|
||||
},
|
||||
onSecurityChange() {},
|
||||
onStatusChange() {},
|
||||
onLocationChange() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIWebProgressListener,
|
||||
Ci.nsIWebProgressListener2,
|
||||
]),
|
||||
};
|
||||
const filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
|
||||
.createInstance(Ci.nsIWebProgress);
|
||||
filter.addProgressListener(wpl, Ci.nsIWebProgress.NOTIFY_ALL);
|
||||
browser.webProgress.addProgressListener(filter, Ci.nsIWebProgress.NOTIFY_ALL);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Waits for the next tab to open and load a given URL.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче