file_fullscreen-plugins.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=545812
  5. Test plugins with DOM full-screen API:
  6. * Presence of plugins has no effect on request for full-screen on MacOS.
  7. * Request for full-screen is denied when windowed plugin in current doc is present.
  8. * Request for full-screen is denied when windowed plugin in subdocument is present.
  9. * Request for full-screen is not denied when the only plugin present is windowless.
  10. * Adding an existing (out-of-doc) windowed plugin to a full-screen document causes document to exit full-screen.
  11. * Create windowed plugin and adding it to full-screen document caused exit from full-screen.
  12. -->
  13. <head>
  14. <title>Test for Bug 545812</title>
  15. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  16. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  17. <script type="application/javascript" src="plugin-utils.js"></script>
  18. <script type="application/javascript">
  19. setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
  20. </script>
  21. <script type="application/javascript" src="file_fullscreen-utils.js"></script>
  22. <style>
  23. body:fullscreen, div:fullscreen {
  24. background-color: red;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <!-- Windowed plugin, focusing should revoke full-screen. -->
  30. <embed id="windowed-plugin" type="application/x-test" style="width:200px;height:100px;" wmode="window"></embed>
  31. <!-- Windowless plugin, focusing should not revoke full-screen. -->
  32. <embed id="windowless-plugin" type="application/x-test" style="width:200px;height:100px;"></embed>
  33. <!-- iframe contents:
  34. <html><body><embed id='windowed-plugin' type='application/x-test' style='width:200px;height:100px;' wmode='window'></embed></body></html>
  35. -->
  36. <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>
  37. <script type="application/javascript">
  38. /** Test for Bug 545812 **/
  39. function ok(condition, msg) {
  40. opener.ok(condition, "[plugins] " + msg);
  41. }
  42. function is(a, b, msg) {
  43. opener.is(a, b, "[plugins] " + msg);
  44. }
  45. function e(id) {
  46. return document.getElementById(id);
  47. }
  48. function removeElement(e) {
  49. e.parentNode.removeChild(e);
  50. }
  51. const isMacOs = navigator.appVersion.indexOf("Macintosh") != -1;
  52. var windowedPlugin = null;
  53. function begin() {
  54. // Delay test startup long enough for the windowed plugin in the subframe to
  55. // start up and create its window.
  56. opener.SimpleTest.executeSoon(function() {
  57. opener.SimpleTest.executeSoon(function() {
  58. startTest();
  59. })
  60. });
  61. }
  62. function startTest() {
  63. ok(!document.fullscreenElement, "Should not be in full-screen mode initially");
  64. document.body.requestFullscreen();
  65. // Focus the windowed plugin. On MacOS we should still enter full-screen mode,
  66. // on windows the pending request for full-screen should be denied.
  67. e("windowed-plugin").focus();
  68. if (isMacOs) {
  69. // Running on MacOS, all plugins are effectively windowless, request for full-screen should be granted.
  70. // Continue test in the (mac-specific) "fullscreenchange" handler.
  71. addFullscreenChangeContinuation("enter", macFullScreenChange1);
  72. } else {
  73. // Non-MacOS, request should be denied, carry on the test after receiving error event.
  74. addFullscreenErrorContinuation(nonMacTest);
  75. }
  76. }
  77. function nonMacTest() {
  78. ok(!document.fullscreenElement, "Request for full-screen with focused windowed plugin should be denied.");
  79. // Focus a regular html element, and re-request full-screen, request should be granted.
  80. e("windowless-plugin").focus();
  81. addFullscreenChangeContinuation("enter", nonMacTest2);
  82. document.body.requestFullscreen();
  83. }
  84. function nonMacTest2() {
  85. ok(document.fullscreenElement, "Request for full-screen with non-plugin focused should be granted.");
  86. // Focus a windowed plugin, full-screen should be revoked.
  87. addFullscreenChangeContinuation("exit", nonMacTest3);
  88. e("windowed-plugin").focus();
  89. }
  90. function nonMacTest3() {
  91. ok(!document.fullscreenElement, "Full-screen should have been revoked when windowed-plugin was focused.");
  92. // Remove windowed plugins before closing the window
  93. // to work around bug 1237853.
  94. removeElement(e("windowed-plugin"));
  95. removeElement(e("subdoc-plugin").contentDocument.getElementById("windowed-plugin"));
  96. opener.nextTest();
  97. }
  98. var fullScreenChangeCount = 0;
  99. function createWindowedPlugin() {
  100. var p = document.createElement("embed");
  101. p.setAttribute("type", "application/x-test");
  102. p.setAttribute("wmode", "window");
  103. return p;
  104. }
  105. function macFullScreenChange1(event) {
  106. ok(document.fullscreenElement, "Requests for full-screen with focused windowed plugins should be granted on MacOS");
  107. // Create a new windowed plugin, and add that to the document. Should *not* exit full-screen mode on MacOS.
  108. windowedPlugin = createWindowedPlugin();
  109. document.body.appendChild(windowedPlugin);
  110. // Focus windowed plugin. Should not exit full-screen mode on MacOS.
  111. windowedPlugin.focus();
  112. setTimeout(
  113. function() {
  114. ok(document.fullscreenElement, "Adding & focusing a windowed plugin to document should not cause full-screen to exit on MacOS.");
  115. addFullscreenChangeContinuation("exit", macFullScreenChange2);
  116. document.exitFullscreen();
  117. }, 0);
  118. }
  119. function macFullScreenChange2(event) {
  120. ok(!document.fullscreenElement, "Should have left full-screen mode after calling document.exitFullscreen().");
  121. opener.nextTest();
  122. }
  123. </script>
  124. </pre>
  125. </body>
  126. </html>