From ab5b2c09992fca245a6472d78332f74d8c485703 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Mon, 12 Jul 2021 22:12:48 +0000 Subject: [PATCH] Bug 1659101 - fix intermittent failure in browser_preoloading_tab_moving.js, r=jaws See discussion in the last few comments on the bug. If we don't wait for the correct URL to load in the browser, the SpecialPowers.spawn task can get aborted, which causes the test to fail. Differential Revision: https://phabricator.services.mozilla.com/D119518 --- browser/modules/test/browser/browser.ini | 3 +- .../browser/browser_preloading_tab_moving.js | 53 +++++++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/browser/modules/test/browser/browser.ini b/browser/modules/test/browser/browser.ini index 98343fef3daa..af1aedfdcc49 100644 --- a/browser/modules/test/browser/browser.ini +++ b/browser/modules/test/browser/browser.ini @@ -34,8 +34,7 @@ support-files = [browser_PermissionUI_prompts.js] [browser_preloading_tab_moving.js] skip-if = - os == 'linux' && (!debug || tsan || asan) # Bug 1659101 - os == "win" # Bug 1659101 + os == 'linux' && tsan # Bug 1720203 [browser_ProcessHangNotifications.js] skip-if = !e10s [browser_SitePermissions.js] diff --git a/browser/modules/test/browser/browser_preloading_tab_moving.js b/browser/modules/test/browser/browser_preloading_tab_moving.js index 08a2e0969f5b..53a3dc9ae396 100644 --- a/browser/modules/test/browser/browser_preloading_tab_moving.js +++ b/browser/modules/test/browser/browser_preloading_tab_moving.js @@ -21,6 +21,41 @@ async function openWinWithPreloadBrowser(options = {}) { return newWin; } +async function promiseNewTabLoadedInBrowser(browser) { + let url = browser.ownerGlobal.BROWSER_NEW_TAB_URL; + if (browser.currentURI.spec != url) { + info(`Waiting for ${url} to be the location for the browser.`); + await new Promise(resolve => { + let progressListener = { + onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) { + if (!url || aLocationURI.spec == url) { + browser.removeProgressListener(progressListener); + resolve(); + } + }, + QueryInterface: ChromeUtils.generateQI([ + Ci.nsISupportsWeakReference, + Ci.nsIWebProgressListener2, + Ci.nsIWebProgressListener, + ]), + }; + browser.addProgressListener( + progressListener, + Ci.nsIWebProgress.NOTIFY_ALL + ); + }); + } else { + info(`${url} already the current URI for the browser.`); + } + + info(`Waiting for readyState complete in the browser`); + await SpecialPowers.spawn(browser, [], function() { + return ContentTaskUtils.waitForCondition(() => { + return content.document.readyState == "complete"; + }); + }); +} + /** * Verify that moving a preloaded browser's content from one window to the next * works correctly. @@ -57,22 +92,14 @@ add_task(async function moving_works() { browser, "Preloaded browser is usable when opening a new tab." ); - await SpecialPowers.spawn(browser, [], function() { - return ContentTaskUtils.waitForCondition(() => { - return content.document.readyState == "complete"; - }); - }); + await promiseNewTabLoadedInBrowser(browser); ok(true, "Successfully loaded the tab."); tab = browser = null; await BrowserTestUtils.closeWindow(newWin); tab = BrowserTestUtils.addTab(gBrowser, BROWSER_NEW_TAB_URL); - await SpecialPowers.spawn(tab.linkedBrowser, [], function() { - return ContentTaskUtils.waitForCondition(() => { - return content.document.readyState == "complete"; - }); - }).catch(Cu.reportError); + await promiseNewTabLoadedInBrowser(tab.linkedBrowser); ok(true, "Managed to open a tab in the original window still."); @@ -115,11 +142,7 @@ add_task(async function moving_shouldnt_move_across_private_state() { browser, "Preloaded browser is usable when opening a new tab." ); - await SpecialPowers.spawn(browser, [], function() { - return ContentTaskUtils.waitForCondition(() => { - return content.document.readyState == "complete"; - }); - }); + await promiseNewTabLoadedInBrowser(browser); ok(true, "Successfully loaded the tab."); tab = browser = null;