forked from mirrors/gecko-dev
Bug 1666092 - Change waitForLoadOrTimeout test helper to only check for load start. r=adw
Waiting for the full load sometimes will take more than the timeout, and we don't really need to do it for the purpose of this helper. Differential Revision: https://phabricator.services.mozilla.com/D190756
This commit is contained in:
parent
ec862c541a
commit
07741fd9ee
6 changed files with 59 additions and 71 deletions
|
|
@ -1070,7 +1070,6 @@ module.exports = {
|
||||||
"browser/components/urlbar/tests/browser/browser_urlbar_telemetry_sponsored_topsites.js",
|
"browser/components/urlbar/tests/browser/browser_urlbar_telemetry_sponsored_topsites.js",
|
||||||
"browser/components/urlbar/tests/browser/browser_view_resultDisplay.js",
|
"browser/components/urlbar/tests/browser/browser_view_resultDisplay.js",
|
||||||
"browser/components/urlbar/tests/browser/browser_view_resultTypes_display.js",
|
"browser/components/urlbar/tests/browser/browser_view_resultTypes_display.js",
|
||||||
"browser/components/urlbar/tests/browser/browser_waitForLoadOrTimeout.js",
|
|
||||||
"browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_clearInput.js",
|
"browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_clearInput.js",
|
||||||
"browser/components/urlbar/tests/quicksuggest/QuickSuggestTestUtils.jsm ",
|
"browser/components/urlbar/tests/quicksuggest/QuickSuggestTestUtils.jsm ",
|
||||||
"browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest.js",
|
"browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest.js",
|
||||||
|
|
|
||||||
|
|
@ -689,11 +689,7 @@ support-files = [
|
||||||
fail-if = ["a11y_checks"] # Bug 1854660 clicked element may not be focusable and/or labeled
|
fail-if = ["a11y_checks"] # Bug 1854660 clicked element may not be focusable and/or labeled
|
||||||
skip-if = ["os == 'linux' && asan"] # Bug 1789051
|
skip-if = ["os == 'linux' && asan"] # Bug 1789051
|
||||||
|
|
||||||
["browser_waitForLoadOrTimeout.js"]
|
["browser_waitForLoadStartOrTimeout.js"]
|
||||||
https_first_disabled = true
|
https_first_disabled = true
|
||||||
skip-if = [
|
|
||||||
"tsan", # Bug 1683730
|
|
||||||
"os == 'linux' && bits == 64 && !debug", # Bug 1666092
|
|
||||||
]
|
|
||||||
|
|
||||||
["browser_whereToOpen.js"]
|
["browser_whereToOpen.js"]
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,9 @@ add_task(async function noResults() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Press enter. Nothing should happen.
|
// Press enter. Nothing should happen.
|
||||||
let loadPromise = waitForLoadOrTimeout();
|
let promise = waitForLoadStartOrTimeout();
|
||||||
EventUtils.synthesizeKey("KEY_Enter");
|
EventUtils.synthesizeKey("KEY_Enter");
|
||||||
let loadEvent = await loadPromise;
|
await Assert.rejects(promise, /timed out/, "Nothing should have loaded");
|
||||||
Assert.ok(!loadEvent, "Nothing should have loaded");
|
|
||||||
|
|
||||||
await UrlbarTestUtils.promisePopupClose(window);
|
await UrlbarTestUtils.promisePopupClose(window);
|
||||||
});
|
});
|
||||||
|
|
@ -90,10 +89,9 @@ add_task(async function localNoHeuristic() {
|
||||||
Assert.ok(!result.heuristic, "Result should not be heuristic");
|
Assert.ok(!result.heuristic, "Result should not be heuristic");
|
||||||
|
|
||||||
// Press enter. Nothing should happen.
|
// Press enter. Nothing should happen.
|
||||||
let loadPromise = waitForLoadOrTimeout();
|
let promise = waitForLoadStartOrTimeout();
|
||||||
EventUtils.synthesizeKey("KEY_Enter");
|
EventUtils.synthesizeKey("KEY_Enter");
|
||||||
let loadEvent = await loadPromise;
|
await Assert.rejects(promise, /timed out/, "Nothing should have loaded");
|
||||||
Assert.ok(!loadEvent, "Nothing should have loaded");
|
|
||||||
|
|
||||||
await UrlbarTestUtils.promisePopupClose(window);
|
await UrlbarTestUtils.promisePopupClose(window);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the waitForLoadOrTimeout test helper function in head.js.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
add_task(async function load() {
|
|
||||||
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
|
||||||
let url = "http://example.com/";
|
|
||||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
|
||||||
window,
|
|
||||||
value: url,
|
|
||||||
});
|
|
||||||
|
|
||||||
let loadPromise = waitForLoadOrTimeout();
|
|
||||||
EventUtils.synthesizeKey("KEY_Enter");
|
|
||||||
let loadEvent = await loadPromise;
|
|
||||||
|
|
||||||
Assert.ok(loadEvent, "Page should have loaded before timeout");
|
|
||||||
Assert.equal(
|
|
||||||
loadEvent.target.currentURI.spec,
|
|
||||||
url,
|
|
||||||
"example.com should have loaded"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_task(async function timeout() {
|
|
||||||
let loadEvent = await waitForLoadOrTimeout();
|
|
||||||
Assert.ok(
|
|
||||||
!loadEvent,
|
|
||||||
"No page should have loaded, and timeout should have fired"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the waitForLoadStartOrTimeout test helper function in head.js.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
add_task(async function load() {
|
||||||
|
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
||||||
|
let url = "https://example.com/";
|
||||||
|
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||||
|
window,
|
||||||
|
value: url,
|
||||||
|
});
|
||||||
|
|
||||||
|
let loadPromise = waitForLoadStartOrTimeout();
|
||||||
|
EventUtils.synthesizeKey("KEY_Enter");
|
||||||
|
let uri = await loadPromise;
|
||||||
|
info("Page should have loaded before timeout");
|
||||||
|
|
||||||
|
Assert.equal(uri.spec, url, "example.com should have loaded");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function timeout() {
|
||||||
|
await Assert.rejects(
|
||||||
|
waitForLoadStartOrTimeout(),
|
||||||
|
/timed out/,
|
||||||
|
"Should have timed out"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
@ -52,37 +52,36 @@ async function selectAndPaste(str, win = window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for a load in any browser or a timeout, whichever comes first.
|
* Waits for a load starting in any browser or a timeout, whichever comes first.
|
||||||
*
|
*
|
||||||
* @param {window} win
|
* @param {window} win
|
||||||
* The top-level browser window to listen in.
|
* The top-level browser window to listen in.
|
||||||
* @param {number} timeoutMs
|
* @param {number} timeoutMs
|
||||||
* The timeout in ms.
|
* The timeout in ms.
|
||||||
* @returns {event|null}
|
* @returns {Promise} resolved to the loading uri in case of load, rejected in
|
||||||
* If a load event was detected before the timeout fired, then the event is
|
* case of timeout.
|
||||||
* returned. event.target will be the browser in which the load occurred. If
|
|
||||||
* the timeout fired before a load was detected, null is returned.
|
|
||||||
*/
|
*/
|
||||||
async function waitForLoadOrTimeout(win = window, timeoutMs = 1000) {
|
function waitForLoadStartOrTimeout(win = window, timeoutMs = 1000) {
|
||||||
let event;
|
|
||||||
let listener;
|
let listener;
|
||||||
let timeout;
|
let timeout;
|
||||||
let eventName = "BrowserTestUtils:ContentEvent:load";
|
return Promise.race([
|
||||||
try {
|
new Promise(resolve => {
|
||||||
event = await Promise.race([
|
listener = {
|
||||||
new Promise(resolve => {
|
onStateChange(browser, webprogress, request, flags, status) {
|
||||||
listener = resolve;
|
if (flags & Ci.nsIWebProgressListener.STATE_START) {
|
||||||
win.addEventListener(eventName, listener, true);
|
resolve(request.QueryInterface(Ci.nsIChannel).URI);
|
||||||
}),
|
}
|
||||||
new Promise(resolve => {
|
},
|
||||||
timeout = win.setTimeout(resolve, timeoutMs);
|
};
|
||||||
}),
|
win.gBrowser.addTabsProgressListener(listener);
|
||||||
]);
|
}),
|
||||||
} finally {
|
new Promise((resolve, reject) => {
|
||||||
win.removeEventListener(eventName, listener, true);
|
timeout = win.setTimeout(() => reject("timed out"), timeoutMs);
|
||||||
|
}),
|
||||||
|
]).finally(() => {
|
||||||
|
win.gBrowser.removeTabsProgressListener(listener);
|
||||||
win.clearTimeout(timeout);
|
win.clearTimeout(timeout);
|
||||||
}
|
});
|
||||||
return event || null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue