summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_minimize.js
blob: a57fea079c4da720304ac09e99a7101b3ac9c5d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 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");
});