mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Bug 1649879 - Use webprogress events instead of waitForDocLoadAndStopIt in browser_progress_keyword_search_handling.js. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D82803
This commit is contained in:
parent
17fbf88433
commit
6dade78e50
@ -14,6 +14,21 @@ add_task(async function setup() {
|
||||
Services.prefs.clearUserPref(kDocChanPref);
|
||||
});
|
||||
await Services.search.init();
|
||||
|
||||
// Create an engine to use for the test.
|
||||
await Services.search.addEngineWithDetails("MozSearch1", {
|
||||
method: "GET",
|
||||
template: "https://example.com/?q={searchTerms}",
|
||||
});
|
||||
|
||||
let originalEngine = await Services.search.getDefault();
|
||||
let engineDefault = Services.search.getEngineByName("MozSearch1");
|
||||
await Services.search.setDefault(engineDefault);
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
await Services.search.setDefault(originalEngine);
|
||||
await Services.search.removeEngine(engineDefault);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
@ -26,18 +41,18 @@ add_task(async function test_unknown_host() {
|
||||
Services.prefs.setBoolPref(kDocChanPref, docChan);
|
||||
await BrowserTestUtils.withNewTab("about:blank", async browser => {
|
||||
const kNonExistingHost = "idontreallyexistonthisnetwork";
|
||||
let searchPromise = BrowserTestUtils.waitForDocLoadAndStopIt(
|
||||
Services.uriFixup.keywordToURI(kNonExistingHost).preferredURI.spec,
|
||||
let searchPromise = BrowserTestUtils.browserStarted(
|
||||
browser,
|
||||
() => {
|
||||
ok(kButton.hasAttribute("displaystop"), "Should be showing stop");
|
||||
return true;
|
||||
}
|
||||
Services.uriFixup.keywordToURI(kNonExistingHost).preferredURI.spec
|
||||
);
|
||||
|
||||
gURLBar.value = kNonExistingHost;
|
||||
gURLBar.select();
|
||||
EventUtils.synthesizeKey("KEY_Enter");
|
||||
|
||||
await searchPromise;
|
||||
ok(kButton.hasAttribute("displaystop"), "Should be showing stop");
|
||||
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => !kButton.hasAttribute("displaystop")
|
||||
);
|
||||
|
@ -524,20 +524,20 @@ var BrowserTestUtils = {
|
||||
|
||||
/**
|
||||
* Waits for the web progress listener associated with this tab to fire a
|
||||
* STATE_STOP for the toplevel document.
|
||||
* state change that matches checkFn for the toplevel document.
|
||||
*
|
||||
* @param {xul:browser} browser
|
||||
* A xul:browser.
|
||||
* @param {String} expectedURI (optional)
|
||||
* A specific URL to check the channel load against
|
||||
* @param {Boolean} checkAborts (optional, defaults to false)
|
||||
* Whether NS_BINDING_ABORTED stops 'count' as 'real' stops
|
||||
* (e.g. caused by the stop button or equivalent APIs)
|
||||
* @param {Function} checkFn
|
||||
* If checkFn(aStateFlags, aStatus) returns false, the state change
|
||||
* is ignored and we continue to wait.
|
||||
*
|
||||
* @return {Promise}
|
||||
* @resolves When STATE_STOP reaches the tab's progress listener
|
||||
* @resolves When the desired state change reaches the tab's progress listener
|
||||
*/
|
||||
browserStopped(browser, expectedURI, checkAborts = false) {
|
||||
waitForBrowserStateChange(browser, expectedURI, checkFn) {
|
||||
return new Promise(resolve => {
|
||||
let wpl = {
|
||||
onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
||||
@ -548,14 +548,13 @@ var BrowserTestUtils = {
|
||||
aStatus.toString(16) +
|
||||
"\n"
|
||||
);
|
||||
if (
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
|
||||
(checkAborts || aStatus != Cr.NS_BINDING_ABORTED) &&
|
||||
aWebProgress.isTopLevel
|
||||
) {
|
||||
if (checkFn(aStateFlags, aStatus) && aWebProgress.isTopLevel) {
|
||||
let chan = aRequest.QueryInterface(Ci.nsIChannel);
|
||||
dump("Browser loaded " + chan.originalURI.spec + "\n");
|
||||
dump(
|
||||
"Browser got expected state change " +
|
||||
chan.originalURI.spec +
|
||||
"\n"
|
||||
);
|
||||
if (!expectedURI || chan.originalURI.spec == expectedURI) {
|
||||
browser.removeProgressListener(wpl);
|
||||
BrowserTestUtils._webProgressListeners.delete(wpl);
|
||||
@ -576,13 +575,79 @@ var BrowserTestUtils = {
|
||||
browser.addProgressListener(wpl);
|
||||
this._webProgressListeners.add(wpl);
|
||||
dump(
|
||||
"Waiting for browser load" +
|
||||
"Waiting for browser state change" +
|
||||
(expectedURI ? " of " + expectedURI : "") +
|
||||
"\n"
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param {String} expectedURI (optional)
|
||||
* A specific URL to check the channel load against
|
||||
* @param {Boolean} checkAborts (optional, defaults to false)
|
||||
* Whether NS_BINDING_ABORTED stops 'count' as 'real' stops
|
||||
* (e.g. caused by the stop button or equivalent APIs)
|
||||
*
|
||||
* @return {Promise}
|
||||
* @resolves When STATE_STOP reaches the tab's progress listener
|
||||
*/
|
||||
browserStopped(browser, expectedURI, checkAborts = false) {
|
||||
let testFn = function(aStateFlags, aStatus) {
|
||||
return (
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
|
||||
(checkAborts || aStatus != Cr.NS_BINDING_ABORTED)
|
||||
);
|
||||
};
|
||||
dump(
|
||||
"Waiting for browser load" +
|
||||
(expectedURI ? " of " + expectedURI : "") +
|
||||
"\n"
|
||||
);
|
||||
return BrowserTestUtils.waitForBrowserStateChange(
|
||||
browser,
|
||||
expectedURI,
|
||||
testFn
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Waits for the web progress listener associated with this tab to fire a
|
||||
* STATE_START for the toplevel document.
|
||||
*
|
||||
* @param {xul:browser} browser
|
||||
* A xul:browser.
|
||||
* @param {String} expectedURI (optional)
|
||||
* A specific URL to check the channel load against
|
||||
*
|
||||
* @return {Promise}
|
||||
* @resolves When STATE_START reaches the tab's progress listener
|
||||
*/
|
||||
browserStarted(browser, expectedURI) {
|
||||
let testFn = function(aStateFlags, aStatus) {
|
||||
return (
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_START
|
||||
);
|
||||
};
|
||||
dump(
|
||||
"Waiting for browser to start load" +
|
||||
(expectedURI ? " of " + expectedURI : "") +
|
||||
"\n"
|
||||
);
|
||||
return BrowserTestUtils.waitForBrowserStateChange(
|
||||
browser,
|
||||
expectedURI,
|
||||
testFn
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Waits for a tab to open and load a given URL.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user