file_fullscreen-rollback.html (3819B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=700764 5 6 Verifies that cancelFullScreen() rolls back to have the previous full-screen 7 element full-screen. 8 9 Tests: 10 * Request full-screen in doc. 11 * Request full-screen in doc on element not descended from full-screen element. 12 * Cancel full-screen, FSE should rollback to previous FSE. 13 * Request full-screen in subdoc. 14 * Cancel full-screen in subdoc, doc should be full-screen. 15 * Request full-screen in subdoc. 16 * Removing FSE should fully-exit full-screen. 17 18 19 --> 20 <head> 21 <title>Test for Bug 700764</title> 22 <script src="/tests/SimpleTest/SimpleTest.js"></script> 23 <script src="/tests/SimpleTest/EventUtils.js"></script> 24 <script type="application/javascript" src="file_fullscreen-utils.js"></script> 25 </head> 26 <body> 27 28 <div id="fse"> 29 <div id="fse-inner"> 30 <iframe id="subdoc" allowfullscreen srcdoc="<html><body bgcolor='black'></body></html>"></iframe> 31 </div> 32 </div> 33 34 <div id="non-fse"></div> 35 36 <script type="application/javascript"> 37 38 /** Test for Bug 700764 */ 39 40 function ok(condition, msg) { 41 opener.ok(condition, "[rollback] " + msg); 42 if (!condition) { 43 opener.finish(); 44 } 45 } 46 47 function is(a, b, msg) { 48 opener.is(a, b, "[rollback] " + msg); 49 if (a != b) { 50 opener.finish(); 51 } 52 } 53 54 function enterFullscreen(element, callback) { 55 addFullscreenChangeContinuation("enter", callback); 56 element.focus(); 57 element.requestFullscreen(); 58 } 59 60 function revertFullscreen(doc, callback) { 61 ok(doc.fullscreenElement != null, "Should only exit fullscreen on a fullscreen doc"); 62 addFullscreenChangeContinuation("exit", callback, doc); 63 doc.exitFullscreen(); 64 } 65 66 function e(id) { 67 return document.getElementById(id); 68 } 69 70 function requestFullscreen(element) { 71 element.focus(); 72 element.requestFullscreen(); 73 } 74 75 function begin() { 76 enterFullscreen(e("fse"), change1); 77 } 78 79 function change1() { 80 is(document.fullscreenElement, e("fse"), "Body should be FSE"); 81 // Request full-screen from element not descendent from current FSE. 82 enterFullscreen(e("non-fse"), change2); 83 } 84 85 function change2() { 86 is(document.fullscreenElement, e("non-fse"), "FSE should be e('non-fse')"); 87 revertFullscreen(document, change3); 88 } 89 90 function change3() { 91 is(document.fullscreenElement, e("fse"), "FSE should rollback to FSE."); 92 var iframe = e("subdoc"); 93 enterFullscreen(iframe.contentDocument.body, change4); 94 } 95 96 function change4() { 97 var iframe = e("subdoc"); 98 is(document.fullscreenElement, iframe, "Subdoc container should be FSE."); 99 is(iframe.contentDocument.fullscreenElement, iframe.contentDocument.body, "Subdoc body should be FSE in subdoc"); 100 revertFullscreen(document, change5); 101 } 102 103 function change5() { 104 is(document.fullscreenElement, e("fse"), "FSE should rollback to FSE."); 105 revertFullscreen(document, change6); 106 } 107 108 function change6() { 109 is(document.fullscreenElement, null, "Should have left full-screen entirely"); 110 enterFullscreen(e("fse"), change7); 111 } 112 113 function change7() { 114 is(document.fullscreenElement, e("fse"), "FSE should be e('fse')"); 115 enterFullscreen(e("fse-inner"), change8); 116 } 117 118 function change8() { 119 var element = e('fse-inner'); 120 is(document.fullscreenElement, element, "FSE should be e('fse-inner')"); 121 122 // We're breaking out of two levels of fullscreen by removing the 123 // fullscreenElement. To make our helper functions work correctly, 124 // we set the fullscreenChangeEnters value to 1. This is a hack, but 125 // it is a hack that supports the expected behavior. 126 setFullscreenChangeEnters(1); 127 addFullscreenChangeContinuation("exit", change9); 128 info(`Removing FSE should exit fullscreen.`); 129 element.remove(); 130 } 131 132 function change9() { 133 is(document.fullscreenElement, null, "Should have fully exited full-screen mode when removed FSE from doc"); 134 opener.nextTest(); 135 } 136 137 </script> 138 </pre> 139 </body> 140 </html>