fune/browser/base/content/test/general/browser_minimize.js
Emilio Cobos Álvarez 1f6f403400 Bug 1779559 - Make tabbrowser manage chrome BC activeness. r=Gijs
Just like it manages content, so that we stop chrome animations and such
in hidden or fully-occluded windows too. This already happened on macOS
for minimized windows via PauseCompositor, but this should be better and
more consistent.

Differential Revision: https://phabricator.services.mozilla.com/D151818
2022-07-19 19:25:47 +00:00

49 lines
1.6 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function() {
registerCleanupFunction(function() {
window.restore();
});
function isActive() {
return gBrowser.selectedTab.linkedBrowser.docShellIsActive;
}
ok(isActive(), "Docshell should be active when starting the test");
ok(!document.hidden, "Top level window should be visible");
info("Calling window.minimize");
let promiseSizeModeChange = BrowserTestUtils.waitForEvent(
window,
"sizemodechange"
);
window.minimize();
await promiseSizeModeChange;
ok(!isActive(), "Docshell should be Inactive");
ok(document.hidden, "Top level window should be hidden");
info("Calling window.restore");
promiseSizeModeChange = BrowserTestUtils.waitForEvent(
window,
"sizemodechange"
);
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,
new Promise((resolve, reject) =>
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(() => {
reject("timed out waiting for sizemodechange event");
}, 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");
});