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:
Marco Bonardo 2023-10-13 09:18:20 +00:00
Родитель ec862c541a
Коммит 07741fd9ee
6 изменённых файлов: 59 добавлений и 71 удалений

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

@ -1070,7 +1070,6 @@ module.exports = {
"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_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/quicksuggest/QuickSuggestTestUtils.jsm ",
"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
skip-if = ["os == 'linux' && asan"] # Bug 1789051
["browser_waitForLoadOrTimeout.js"]
["browser_waitForLoadStartOrTimeout.js"]
https_first_disabled = true
skip-if = [
"tsan", # Bug 1683730
"os == 'linux' && bits == 64 && !debug", # Bug 1666092
]
["browser_whereToOpen.js"]

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

@ -45,10 +45,9 @@ add_task(async function noResults() {
);
// Press enter. Nothing should happen.
let loadPromise = waitForLoadOrTimeout();
let promise = waitForLoadStartOrTimeout();
EventUtils.synthesizeKey("KEY_Enter");
let loadEvent = await loadPromise;
Assert.ok(!loadEvent, "Nothing should have loaded");
await Assert.rejects(promise, /timed out/, "Nothing should have loaded");
await UrlbarTestUtils.promisePopupClose(window);
});
@ -90,10 +89,9 @@ add_task(async function localNoHeuristic() {
Assert.ok(!result.heuristic, "Result should not be heuristic");
// Press enter. Nothing should happen.
let loadPromise = waitForLoadOrTimeout();
let promise = waitForLoadStartOrTimeout();
EventUtils.synthesizeKey("KEY_Enter");
let loadEvent = await loadPromise;
Assert.ok(!loadEvent, "Nothing should have loaded");
await Assert.rejects(promise, /timed out/, "Nothing should have loaded");
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
* The top-level browser window to listen in.
* @param {number} timeoutMs
* The timeout in ms.
* @returns {event|null}
* If a load event was detected before the timeout fired, then the event is
* returned. event.target will be the browser in which the load occurred. If
* the timeout fired before a load was detected, null is returned.
* @returns {Promise} resolved to the loading uri in case of load, rejected in
* case of timeout.
*/
async function waitForLoadOrTimeout(win = window, timeoutMs = 1000) {
let event;
function waitForLoadStartOrTimeout(win = window, timeoutMs = 1000) {
let listener;
let timeout;
let eventName = "BrowserTestUtils:ContentEvent:load";
try {
event = await Promise.race([
new Promise(resolve => {
listener = resolve;
win.addEventListener(eventName, listener, true);
}),
new Promise(resolve => {
timeout = win.setTimeout(resolve, timeoutMs);
}),
]);
} finally {
win.removeEventListener(eventName, listener, true);
return Promise.race([
new Promise(resolve => {
listener = {
onStateChange(browser, webprogress, request, flags, status) {
if (flags & Ci.nsIWebProgressListener.STATE_START) {
resolve(request.QueryInterface(Ci.nsIChannel).URI);
}
},
};
win.gBrowser.addTabsProgressListener(listener);
}),
new Promise((resolve, reject) => {
timeout = win.setTimeout(() => reject("timed out"), timeoutMs);
}),
]).finally(() => {
win.gBrowser.removeTabsProgressListener(listener);
win.clearTimeout(timeout);
}
return event || null;
});
}
/**