From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../base/content/test/general/browser_minimize.js | 43 +++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'browser/base/content/test/general/browser_minimize.js') diff --git a/browser/base/content/test/general/browser_minimize.js b/browser/base/content/test/general/browser_minimize.js index a57fea079c..3919cd7d77 100644 --- a/browser/base/content/test/general/browser_minimize.js +++ b/browser/base/content/test/general/browser_minimize.js @@ -12,26 +12,57 @@ add_task(async function () { ok(isActive(), "Docshell should be active when starting the test"); ok(!document.hidden, "Top level window should be visible"); + // When we show or hide the window (including by minimization), + // there are 2 signifiers that the process is complete: the + // sizemodechange event, and the browsing context becoming active + // or inactive. There is another signifier, the + // occlusionstatechange event, but whether or not that event + // is sent is platform-dependent, so it's not very useful. The + // safest way to check for stable state is to build promises + // around sizemodechange and browsing context active and then + // wait for them all to complete, and that's what we do here. info("Calling window.minimize"); let promiseSizeModeChange = BrowserTestUtils.waitForEvent( window, "sizemodechange" + ).then( + () => ok(true, "Got sizemodechange."), + () => ok(false, "Rejected sizemodechange.") + ); + let promiseBrowserInactive = BrowserTestUtils.waitForCondition( + () => !isActive(), + "Docshell should be inactive." + ).then( + () => ok(true, "Got inactive."), + () => ok(false, "Rejected inactive.") ); window.minimize(); - await promiseSizeModeChange; - ok(!isActive(), "Docshell should be Inactive"); + await Promise.all([promiseSizeModeChange, promiseBrowserInactive]); ok(document.hidden, "Top level window should be hidden"); + // When we restore the window from minimization, we have the + // same concerns as above, so prepare our promises. info("Calling window.restore"); promiseSizeModeChange = BrowserTestUtils.waitForEvent( window, "sizemodechange" + ).then( + () => ok(true, "Got sizemodechange."), + () => ok(false, "Rejected sizemodechange.") + ); + let promiseBrowserActive = BrowserTestUtils.waitForCondition( + () => isActive(), + "Docshell should be active." + ).then( + () => ok(true, "Got active."), + () => ok(false, "Rejected active.") ); window.restore(); + // On Ubuntu `window.restore` doesn't seem to work, use a timer to make the // test fail faster and more cleanly than with a test timeout. await Promise.race([ - promiseSizeModeChange, + Promise.all([promiseSizeModeChange, promiseBrowserActive]), new Promise((resolve, reject) => // eslint-disable-next-line mozilla/no-arbitrary-setTimeout setTimeout(() => { @@ -39,11 +70,5 @@ add_task(async function () { }, 5000) ), ]); - // The sizemodechange event can sometimes be fired before the - // occlusionstatechange event, especially in chaos mode. - if (window.isFullyOccluded) { - await BrowserTestUtils.waitForEvent(window, "occlusionstatechange"); - } - ok(isActive(), "Docshell should be active again"); ok(!document.hidden, "Top level window should be visible"); }); -- cgit v1.2.3