summaryrefslogtreecommitdiffstats
path: root/dom/base/test/fullscreen/file_fullscreen-nested.html
blob: 1629d8386cc970b5dd7ff5dc1e8d42226a9caa1f (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
128
129
130
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Bug 1187801</title>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="file_fullscreen-utils.js"></script>
</head>
<body>
<iframe src="empty.html" allowfullscreen></iframe>
<script type="text/javascript">

/** Test for Bug 1187801 **/

function info(msg) {
  opener.info("[nested] " + msg);
}

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

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

var gInnerDoc;
var gTestSteps;
var gTestIndex = 0;

function begin() {
  var root = document.documentElement;
  var iframe = document.querySelector("iframe");
  var innerDoc = gInnerDoc = iframe.contentDocument;
  var innerRoot = innerDoc.documentElement;

  // The format of each test step is:
  // [[action, target], [fsOuter, fsInner]] where:
  // * "action" is "enter" or "exit" means whether we want to enter or
  //   fullscreen in this step. An action of "reset" means to force
  //   our count of enters to a certain value, to match how many exits
  //   we need to do to leave fullscreen. This is used when one exit
  //   can unwind more than one enter.
  // * "target" is where we apply this action. For "enter" action, it
  //   is the element we want to call requestFullscreen() on, and for
  //   "exit", it is the document we want to call exitFullscreen() on.
  // * "fsOuter" and "fsInner" are the expected fullscreen elements of
  //   the outer and inner document respectively after executing the
  //   action in this step. These are only checked after "enter" or
  //   "exit" actions.
  gTestSteps = [
    // innerRoot
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  innerDoc], [  null,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  document], [  null,      null]],
    // root, innerRoot
    [["enter",      root], [  root,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  innerDoc], [  root,      null]],
    [[ "exit",  document], [  null,      null]],
    [["enter",      root], [  root,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  document], [  root,      null]],
    [[ "exit",  document], [  null,      null]],
    // iframe, innerRoot
    [["enter",    iframe], [iframe,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  innerDoc], [iframe,      null]],
    [[ "exit",  document], [  null,      null]],
    [["enter",    iframe], [iframe,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [["reset",         1], [  null,      null]],
    [[ "exit",  document], [  null,      null]],
    // root, iframe, innerRoot
    [["enter",      root], [  root,      null]],
    [["enter",    iframe], [iframe,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  innerDoc], [iframe,      null]],
    [[ "exit",  document], [  root,      null]],
    [[ "exit",  document], [  null,      null]],
    [["enter",      root], [  root,      null]],
    [["enter",    iframe], [iframe,      null]],
    [["enter", innerRoot], [iframe, innerRoot]],
    [[ "exit",  document], [  root,      null]],
    [["reset",         1], [  null,      null]],
    [[ "exit",  document], [  null,      null]],
  ];

  nextStep();
}

function nextStep() {
  if (gTestIndex == gTestSteps.length) {
    opener.nextTest();
    return;
  }

  var index = gTestIndex;
  var [[action, target], [fsOuter, fsInner]] = gTestSteps[gTestIndex++];

  function checkAndNext() {
    is(document.fullscreenElement, fsOuter,
       `Fullscreen element of outer doc should match after step ${index}`);
    is(gInnerDoc.fullscreenElement, fsInner,
       `Fullscreen element of inner doc should match after step ${index}`);
    nextStep();
  }

  info(`Executing step ${index}: ${action} on ${target}...`);
  if (action == "enter") {
    // For "enter" action, the target is the element
    var doc = target.ownerDocument;
    addFullscreenChangeContinuation("enter", checkAndNext, doc);
    target.requestFullscreen();
  } else if (action == "exit") {
    // For "exit" action, the target is the document
    addFullscreenChangeContinuation("exit", checkAndNext, target);
    target.exitFullscreen();
  } else if (action == "reset") {
    // For "reset" action, the target is the number to setFullscreenChangeEnters.
    setFullscreenChangeEnters(target);
    nextStep();
  } else {
    ok(false, `Unknown action ${action}`);
  }
}
</script>
</body>
</html>