summaryrefslogtreecommitdiffstats
path: root/dom/html/test/file_fullscreen-plugins.html
blob: f28fbede9343fab3aa0e3d4aaeac0b4fccc35d43 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=545812

Test plugins with DOM full-screen API:
* Presence of plugins has no effect on request for full-screen on MacOS.
* Request for full-screen is denied when windowed plugin in current doc is present.
* Request for full-screen is denied when windowed plugin in subdocument is present.
* Request for full-screen is not denied when the only plugin present is windowless.
* Adding an existing (out-of-doc) windowed plugin to a full-screen document causes document to exit full-screen.
* Create windowed plugin and adding it to full-screen document caused exit from full-screen.

-->
<head>
  <title>Test for Bug 545812</title>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="plugin-utils.js"></script>
  <script type="application/javascript">
    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
  </script>
  <script type="application/javascript" src="file_fullscreen-utils.js"></script>
  <style>
  body:fullscreen, div:fullscreen {
    background-color: red;
  }
  </style>
</head>
<body>


<!-- Windowed plugin, focusing should revoke full-screen. -->
<embed id="windowed-plugin" type="application/x-test" style="width:200px;height:100px;" wmode="window"></embed>

<!-- Windowless plugin, focusing should not revoke full-screen. -->
<embed id="windowless-plugin" type="application/x-test" style="width:200px;height:100px;"></embed>


<!-- iframe contents:

<html><body><embed id='windowed-plugin' type='application/x-test' style='width:200px;height:100px;' wmode='window'></embed></body></html>

-->

<iframe id="subdoc-plugin" src="data:text/html;charset=utf-8,<html><body><embed id%3D'windowed-plugin' type%3D'application%2Fx-test' style%3D'width%3A200px%3Bheight%3A100px%3B' wmode%3D'window'><%2Fembed><%2Fbody><%2Fhtml>%0D%0A"></iframe>

<script type="application/javascript">

/** Test for Bug 545812 **/

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

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

function e(id) {
  return document.getElementById(id);
}

function removeElement(e) {
  e.parentNode.removeChild(e);
}

const isMacOs = navigator.appVersion.indexOf("Macintosh") != -1;

var windowedPlugin = null;

function begin() {
  // Delay test startup long enough for the windowed plugin in the subframe to
  // start up and create its window.
  opener.SimpleTest.executeSoon(function() {
    opener.SimpleTest.executeSoon(function() {
      startTest();
    })
  });
}

function startTest() {
  ok(!document.fullscreenElement, "Should not be in full-screen mode initially");
  document.body.requestFullscreen();

  // Focus the windowed plugin. On MacOS we should still enter full-screen mode,
  // on windows the pending request for full-screen should be denied.
  e("windowed-plugin").focus();
  
  if (isMacOs) {
    // Running on MacOS, all plugins are effectively windowless, request for full-screen should be granted.
    // Continue test in the (mac-specific) "fullscreenchange" handler.
    addFullscreenChangeContinuation("enter", macFullScreenChange1);
  } else {
    // Non-MacOS, request should be denied, carry on the test after receiving error event.
    addFullscreenErrorContinuation(nonMacTest);
  }
}

function nonMacTest() {
  ok(!document.fullscreenElement, "Request for full-screen with focused windowed plugin should be denied.");

  // Focus a regular html element, and re-request full-screen, request should be granted.
  e("windowless-plugin").focus();
  addFullscreenChangeContinuation("enter", nonMacTest2);
  document.body.requestFullscreen();
}

function nonMacTest2() {
  ok(document.fullscreenElement, "Request for full-screen with non-plugin focused should be granted.");
  // Focus a windowed plugin, full-screen should be revoked.
  addFullscreenChangeContinuation("exit", nonMacTest3);
  e("windowed-plugin").focus();
}

function nonMacTest3() {
  ok(!document.fullscreenElement, "Full-screen should have been revoked when windowed-plugin was focused.");
  // Remove windowed plugins before closing the window
  // to work around bug 1237853.
  removeElement(e("windowed-plugin"));
  removeElement(e("subdoc-plugin").contentDocument.getElementById("windowed-plugin"));
  opener.nextTest();
}

var fullScreenChangeCount = 0;

function createWindowedPlugin() {
  var p = document.createElement("embed");
  p.setAttribute("type", "application/x-test");
  p.setAttribute("wmode", "window");
  return p;
}

function macFullScreenChange1(event) {
  ok(document.fullscreenElement, "Requests for full-screen with focused windowed plugins should be granted on MacOS");
  
  // Create a new windowed plugin, and add that to the document. Should *not* exit full-screen mode on MacOS.
  windowedPlugin = createWindowedPlugin();
  document.body.appendChild(windowedPlugin);
  
  // Focus windowed plugin. Should not exit full-screen mode on MacOS.
  windowedPlugin.focus();
  
  setTimeout(
    function() {
      ok(document.fullscreenElement, "Adding & focusing a windowed plugin to document should not cause full-screen to exit on MacOS.");
      addFullscreenChangeContinuation("exit", macFullScreenChange2);
      document.exitFullscreen();
    }, 0);
}

function macFullScreenChange2(event) {
  ok(!document.fullscreenElement, "Should have left full-screen mode after calling document.exitFullscreen().");
  opener.nextTest();
}

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