summaryrefslogtreecommitdiff
path: root/dom/html/test/file_fullscreen-unprefix-disabled-inner.html
blob: 632a6c0ce7c352bff0dd94f6dc089b8ccfb498cd (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Test for Bug 1268749</title>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
  <div id="fullscreen"></div>
<script>

function ok(condition, msg) {
  opener.opener.ok(condition, "[unprefix-disabled] " + msg);
}

function is(a, b, msg) {
  opener.opener.is(a, b, "[unprefix-disabled] " + msg);
}

function info(msg) {
  opener.opener.info("[unprefix-disabled] " + msg);
}

SimpleTest.requestFlakyTimeout(
  "need to wait for a while to confirm no unexpected event is dispatched");

let div = document.getElementById("fullscreen");
let unattachedDiv = document.createElement('div');

function begin() {
  ok(!("requestFullscreen" in div), "No element.requestFullscreen");
  ok(!("exitFullscreen" in document), "No document.exitFullscreen");
  ok(!("fullscreen" in document), "No document.fullscreen");
  ok(!("fullscreenElement" in document), "No document.fullscreenElement");
  ok(!("fullscreenEnabled" in document), "No document.fullscreenEnabled");
  ok(!("onfullscreenchange" in document), "No document.onfullscreenchange");
  ok(!("onfullscreenerror" in document), "No document.onfullscreenerror");

  for (var event of ["fullscreenchange", "fullscreenerror"]) {
    let customEvent = new Event(event, {bubbles: true});
    let gotCustomEventFromWindow = false;
    let gotCustomEventFromDocument = false;
    let listenerForWindow = evt => {
      ok(!gotCustomEventFromWindow,
         "Should get custom event from window only once");
      ok(evt == customEvent, "Should get the desired custom event");
      gotCustomEventFromWindow = true;
    };
    let listenerForDocument = evt => {
      ok(!gotCustomEventFromDocument,
         "Should get custom event from document only once");
      ok(evt == customEvent, "Should get the desired custom event");
      gotCustomEventFromDocument = true;
    };
    window.addEventListener(event, listenerForWindow);
    document.addEventListener(event, listenerForDocument);
    document.dispatchEvent(customEvent);
    ok(gotCustomEventFromWindow, "Should get the custom event from window");
    ok(gotCustomEventFromDocument, "Should get the custom event from document");
    window.removeEventListener(event, listenerForWindow);
    document.removeEventListener(event, listenerForDocument);

    for (var target of [window, document]) {
      target.addEventListener(event, () => {
        ok(false, `No ${event} should be triggered on ${target}`);
      });
    }
  }

  document.addEventListener("mozfullscreenchange", enteredFullscreen);
  SimpleTest.executeSoon(() => div.mozRequestFullScreen());
}

function enteredFullscreen() {
  document.removeEventListener("mozfullscreenchange", enteredFullscreen);
  document.addEventListener("mozfullscreenchange", exitedFullscreen);
  SimpleTest.executeSoon(() => document.mozCancelFullScreen());
}

function exitedFullscreen() {
  document.removeEventListener("mozfullscreenchange", exitedFullscreen);
  document.addEventListener("mozfullscreenerror", errorFullscreen);
  SimpleTest.executeSoon(() => unattachedDiv.mozRequestFullScreen());
}

function errorFullscreen() {
  document.removeEventListener("mozfullscreenerror", errorFullscreen);
  // Wait a short time before exiting this test to confirm that there is
  // really no unwanted event gets dispatched.
  setTimeout(() => opener.finish(), 200);
}

</script>
</body>
</html>