summaryrefslogtreecommitdiffstats
path: root/dom/base/test/fullscreen/browser_fullscreen-window-open-race.js
blob: 4cf8a3d8c704160aa417e293ac41ec57dc4d4e59 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

requestLongerTimeout(2);

// Import helpers
Services.scriptloader.loadSubScript(
  "chrome://mochitests/content/browser/dom/base/test/fullscreen/fullscreen_helpers.js",
  this
);

// This test tends to trigger a race in the fullscreen time telemetry,
// where the fullscreen enter and fullscreen exit events (which use the
// same histogram ID) overlap. That causes TelemetryStopwatch to log an
// error, bug 1742890.
SimpleTest.ignoreAllUncaughtExceptions(true);

add_setup(async function () {
  await pushPrefs(
    ["full-screen-api.transition-duration.enter", "0 0"],
    ["full-screen-api.transition-duration.leave", "0 0"],
    ["full-screen-api.allow-trusted-requests-only", false]
  );
});

add_task(async () => {
  const url =
    "http://mochi.test:8888/browser/dom/base/test/fullscreen/dummy_page.html";
  const name = "foo";

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function (browser) {
      info("open new window");
      SpecialPowers.spawn(browser, [url, name], function (u, n) {
        content.document.notifyUserGestureActivation();
        content.window.open(u, n, "width=100,height=100");
      });
      let newWin = await BrowserTestUtils.waitForNewWindow({ url });
      await SimpleTest.promiseFocus(newWin);

      info("re-focusing main window");
      await SimpleTest.promiseFocus(window);

      info("open an existing window and request fullscreen");
      await SpecialPowers.spawn(browser, [url, name], function (u, n) {
        content.document.notifyUserGestureActivation();
        content.window.open(u, n);
        content.document.body.requestFullscreen();
      });

      // We call window.open() first than requestFullscreen() in a row on
      // content page, but given that focus sync-up takes several IPC exchanges,
      // so parent process ends up processing the requests in a reverse order,
      // which should reject the fullscreen request and leave fullscreen.
      await waitWidgetFullscreenEvent(window, false, true);

      // Ensure the browser exits fullscreen state.
      ok(!window.fullScreen, "The chrome window should not be in fullscreen");
      ok(
        !document.documentElement.hasAttribute("inDOMFullscreen"),
        "The chrome document should not be in fullscreen"
      );

      await BrowserTestUtils.closeWindow(newWin);
    }
  );
});