summaryrefslogtreecommitdiffstats
path: root/dom/base/test/fullscreen/test_fullscreen_modal.html
blob: 94b115f93e7a0cb380fa9727e4afd181a747ddce (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
<!doctype html>
<title>Test for bug 1771150</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<style>
  #fullscreen {
    background-color: rgba(0, 255, 0, .5);
  }
  #fullscreen::backdrop {
    background-color: transparent;
  }
  #fullscreen, #fullscreen::backdrop {
    pointer-events: none;
  }
</style>
<div id="fullscreen"></div>
<button>Go fullscreen</button>
<script>
const button = document.querySelector("button");
let clickCount = 0;
let lastFullscreenPromise = null;
let shouldEnterFullscreen = false;
button.addEventListener("click", function(e) {
  clickCount++;
  if (shouldEnterFullscreen) {
    lastFullscreenPromise = document.getElementById("fullscreen").requestFullscreen();
  }
});

function clickButton(expectEvent) {
  let lastClickCount = clickCount;
  synthesizeMouseAtCenter(button, {});
  (expectEvent ? isnot : is)(lastClickCount, clickCount, `Should've ${expectEvent ? "" : "not "}been able to click`);
}

function enterFullscreen() {
  lastFullscreenPromise = null;
  shouldEnterFullscreen = true;
  clickButton(true);
  shouldEnterFullscreen = false;
  isnot(lastFullscreenPromise, null, "Should be transitioning to fullscreen");
  return lastFullscreenPromise;
}

async function testFullscreenIsModal(modal) {
  info("testing modal: " + modal);
  is(document.fullscreenElement, null, "Shouldn't be in fullscreen");
  await SpecialPowers.pushPrefEnv({ set: [["dom.fullscreen.modal", modal]] });
  await enterFullscreen();

  clickButton(/* expectEvent = */ !modal);

  ok(document.fullscreenElement.matches(":fullscreen"), "Fullscreen element matches :fullscreen");
  is(document.fullscreenElement.matches(":modal"), modal, "Fullscreen element matches :modal");

  await document.exitFullscreen();
  clickButton(/* expectEvent = */ true);
}

add_task(async function() {
  await testFullscreenIsModal(true);
});

add_task(async function() {
  await testFullscreenIsModal(false);
});
</script>