browser_minimize.js (2693B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function () { 5 registerCleanupFunction(function () { 6 window.restore(); 7 }); 8 function isActive() { 9 return gBrowser.selectedTab.linkedBrowser.docShellIsActive; 10 } 11 12 ok(isActive(), "Docshell should be active when starting the test"); 13 ok(!document.hidden, "Top level window should be visible"); 14 15 // When we show or hide the window (including by minimization), 16 // there are 2 signifiers that the process is complete: the 17 // sizemodechange event, and the browsing context becoming active 18 // or inactive. There is another signifier, the 19 // occlusionstatechange event, but whether or not that event 20 // is sent is platform-dependent, so it's not very useful. The 21 // safest way to check for stable state is to build promises 22 // around sizemodechange and browsing context active and then 23 // wait for them all to complete, and that's what we do here. 24 info("Calling window.minimize"); 25 let promiseSizeModeChange = BrowserTestUtils.waitForEvent( 26 window, 27 "sizemodechange" 28 ).then( 29 () => ok(true, "Got sizemodechange."), 30 () => ok(false, "Rejected sizemodechange.") 31 ); 32 let promiseBrowserInactive = BrowserTestUtils.waitForCondition( 33 () => !isActive(), 34 "Docshell should be inactive." 35 ).then( 36 () => ok(true, "Got inactive."), 37 () => ok(false, "Rejected inactive.") 38 ); 39 window.minimize(); 40 await Promise.all([promiseSizeModeChange, promiseBrowserInactive]); 41 ok(document.hidden, "Top level window should be hidden"); 42 43 // When we restore the window from minimization, we have the 44 // same concerns as above, so prepare our promises. 45 info("Calling window.restore"); 46 promiseSizeModeChange = BrowserTestUtils.waitForEvent( 47 window, 48 "sizemodechange" 49 ).then( 50 () => ok(true, "Got sizemodechange."), 51 () => ok(false, "Rejected sizemodechange.") 52 ); 53 let promiseBrowserActive = BrowserTestUtils.waitForCondition( 54 () => isActive(), 55 "Docshell should be active." 56 ).then( 57 () => ok(true, "Got active."), 58 () => ok(false, "Rejected active.") 59 ); 60 window.restore(); 61 62 // On Ubuntu `window.restore` doesn't seem to work, use a timer to make the 63 // test fail faster and more cleanly than with a test timeout. 64 await Promise.race([ 65 Promise.all([promiseSizeModeChange, promiseBrowserActive]), 66 new Promise((resolve, reject) => 67 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 68 setTimeout(() => { 69 reject("timed out waiting for sizemodechange event"); 70 }, 5000) 71 ), 72 ]); 73 ok(!document.hidden, "Top level window should be visible"); 74 });