summaryrefslogtreecommitdiffstats
path: root/dom/base/test/fullscreen/browser_fullscreen-navigation-history.js
blob: 08624ed3273f1d6d96cf272a979e935437b5f834 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* 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]
  );
});

function preventBFCache(aBrowsingContext, aPrevent) {
  return SpecialPowers.spawn(aBrowsingContext, [aPrevent], prevent => {
    if (prevent) {
      // Using a dummy onunload listener to disable the bfcache.
      content.window.addEventListener("unload", () => {});
    }
    content.window.addEventListener(
      "pagehide",
      e => {
        // XXX checking persisted property causes intermittent failures, so we
        // dump the value instead, bug 1822263.
        // is(e.persisted, !prevent, `Check BFCache state`);
        info(`Check BFCache state: e.persisted is ${e.persisted}`);
      },
      { once: true }
    );
  });
}

[true, false].forEach(crossOrigin => {
  [true, false].forEach(initialPagePreventsBFCache => {
    [true, false].forEach(fullscreenPagePreventsBFCache => {
      add_task(async function navigation_history() {
        info(
          `crossOrigin: ${crossOrigin}, initialPagePreventsBFCache: ${initialPagePreventsBFCache}, fullscreenPagePreventsBFCache: ${fullscreenPagePreventsBFCache}`
        );
        await BrowserTestUtils.withNewTab(
          {
            gBrowser,
            url: "http://mochi.test:8888/browser/dom/base/test/fullscreen/dummy_page.html",
          },
          async function (browser) {
            // Maybe prevent BFCache on initial page.
            await preventBFCache(
              browser.browsingContext,
              initialPagePreventsBFCache
            );

            // Navigate to fullscreen page.
            const url = crossOrigin
              ? "https://example.org/browser/dom/base/test/fullscreen/file_fullscreen-iframe-inner.html"
              : "http://mochi.test:8888/browser/dom/base/test/fullscreen/file_fullscreen-iframe-inner.html";
            const loaded = BrowserTestUtils.browserLoaded(browser, false, url);
            BrowserTestUtils.loadURIString(browser, url);
            await loaded;

            // Maybe prevent BFCache on fullscreen test page.
            await preventBFCache(
              browser.browsingContext,
              fullscreenPagePreventsBFCache
            );

            // Trigger click event to enter fullscreen.
            let promiseFsState = waitForFullscreenState(document, true);
            SpecialPowers.spawn(browser.browsingContext, [], () => {
              content.setTimeout(() => {
                content.document.getElementById("div").click();
              }, 0);
            });
            await promiseFsState;

            // Navigate back to the previous page should exit fullscreen.
            promiseFsState = waitForFullscreenState(document, false);
            await SpecialPowers.spawn(browser.browsingContext, [], () => {
              content.window.history.back();
            });
            await promiseFsState;
          }
        );
      });
    });
  });
});