summaryrefslogtreecommitdiffstats
path: root/dom/base/test/fullscreen/file_fullscreen-event-order.html
blob: 72fb2c9b4747c762ae0828373c49fb7c4560edcb (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
<!DOCTYPE html>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="file_fullscreen-utils.js"></script>
<iframe src="empty.html" allowfullscreen></iframe>
<script>
function ok(condition, msg) {
  opener.ok(condition, "[event-order] " + msg);
}
function is(a, b, msg) {
  opener.is(a, b, "[event-order] " + msg);
}

let fullscreenEvents = [];
let iframe, iframeDoc;

function begin() {
  iframe = document.querySelector("iframe");
  iframeDoc = iframe.contentDocument;
  document.addEventListener("fullscreenchange", evt => {
    fullscreenEvents.push(evt);
  });
  iframeDoc.addEventListener("fullscreenchange", evt => {
    fullscreenEvents.push(evt);
  });
  addFullscreenChangeContinuation("enter", enterFullscreen);
  iframeDoc.body.requestFullscreen();
}

function assertFullscreenEvents(action) {
  is(fullscreenEvents.length, 2,
    "Two documents should have event dispatched for " + action);
  is(fullscreenEvents[0].target, iframe,
     "Root document should have the event dispatched first after " + action);
  is(fullscreenEvents[1].target, iframeDoc.body,
     "Inner document should have the event dispatched second after " + action);
}

function enterFullscreen() {
  assertFullscreenEvents("requestFullscreen");
  fullscreenEvents = [];
  addFullscreenChangeContinuation("exit", exitFullscreen);
  document.exitFullscreen();
}

function exitFullscreen() {
  assertFullscreenEvents("exitFullscreen");
  opener.nextTest();
}
</script>