summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/fullscreen/browser_fullscreen_warning.js
blob: 210f65ee1ca07e781762c999221cccb5e7aca004 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_fullscreen_display_none() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["full-screen-api.enabled", true],
      ["full-screen-api.allow-trusted-requests-only", false],
    ],
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: `data:text/html,
      <html>
        <head>
          <meta charset="utf-8"/>
          <title>Fullscreen Test</title>
        </head>
        <body id="body">
        <iframe
         src="https://example.org/browser/browser/base/content/test/fullscreen/fullscreen.html"
         hidden
         allowfullscreen></iframe>
        </body>
      </html>`,
    },
    async function(browser) {
      let warning = document.getElementById("fullscreen-warning");
      let warningShownPromise = BrowserTestUtils.waitForAttribute(
        "onscreen",
        warning,
        "true"
      );
      // Enter fullscreen
      await SpecialPowers.spawn(browser, [], async () => {
        let frame = content.document.querySelector("iframe");
        frame.focus();
        await SpecialPowers.spawn(frame, [], () => {
          content.document.getElementById("request").click();
        });
      });
      await warningShownPromise;
      ok(true, "Fullscreen warning shown");
      // Exit fullscreen
      let exitFullscreenPromise = BrowserTestUtils.waitForEvent(
        document,
        "fullscreenchange",
        false,
        () => !document.fullscreenElement
      );
      document.getElementById("fullscreen-exit-button").click();
      await exitFullscreenPromise;
    }
  );
});

add_task(async function test_fullscreen_pointerlock_conflict() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["full-screen-api.enabled", true],
      ["full-screen-api.allow-trusted-requests-only", false],
    ],
  });

  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
    let fsWarning = document.getElementById("fullscreen-warning");
    let plWarning = document.getElementById("pointerlock-warning");

    is(
      fsWarning.getAttribute("onscreen"),
      null,
      "Should not show full screen warning initially."
    );
    is(
      plWarning.getAttribute("onscreen"),
      null,
      "Should not show pointer lock warning initially."
    );

    let fsWarningShownPromise = BrowserTestUtils.waitForAttribute(
      "onscreen",
      fsWarning,
      "true"
    );

    info("Entering full screen and pointer lock.");
    await SpecialPowers.spawn(browser, [], async () => {
      await content.document.body.requestFullscreen();
      await content.document.body.requestPointerLock();
    });

    await fsWarningShownPromise;
    is(
      fsWarning.getAttribute("onscreen"),
      "true",
      "Should show full screen warning."
    );
    is(
      plWarning.getAttribute("onscreen"),
      null,
      "Should not show pointer lock warning."
    );

    info("Exiting pointerlock");
    await SpecialPowers.spawn(browser, [], async () => {
      await content.document.exitPointerLock();
    });

    is(
      fsWarning.getAttribute("onscreen"),
      "true",
      "Should still show full screen warning."
    );
    is(
      plWarning.getAttribute("onscreen"),
      null,
      "Should not show pointer lock warning."
    );

    // Cleanup
    await document.exitFullscreen();
  });
});