file_fullscreen-nested.html (4610B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for Bug 1187801</title> 5 <script src="/tests/SimpleTest/EventUtils.js"></script> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="application/javascript" src="file_fullscreen-utils.js"></script> 8 </head> 9 <body> 10 <iframe src="empty.html" allowfullscreen></iframe> 11 <script type="text/javascript"> 12 13 /** Test for Bug 1187801 */ 14 15 function info(msg) { 16 opener.info("[nested] " + msg); 17 } 18 19 function ok(condition, msg) { 20 opener.ok(condition, "[nested] " + msg); 21 } 22 23 function is(a, b, msg) { 24 opener.is(a, b, "[nested] " + msg); 25 } 26 27 var gInnerDoc; 28 var gTestSteps; 29 var gTestIndex = 0; 30 31 function begin() { 32 var root = document.documentElement; 33 var iframe = document.querySelector("iframe"); 34 var innerDoc = gInnerDoc = iframe.contentDocument; 35 var innerRoot = innerDoc.documentElement; 36 37 // The format of each test step is: 38 // [[action, target], [fsOuter, fsInner]] where: 39 // * "action" is "enter" or "exit" means whether we want to enter or 40 // fullscreen in this step. An action of "reset" means to force 41 // our count of enters to a certain value, to match how many exits 42 // we need to do to leave fullscreen. This is used when one exit 43 // can unwind more than one enter. 44 // * "target" is where we apply this action. For "enter" action, it 45 // is the element we want to call requestFullscreen() on, and for 46 // "exit", it is the document we want to call exitFullscreen() on. 47 // * "fsOuter" and "fsInner" are the expected fullscreen elements of 48 // the outer and inner document respectively after executing the 49 // action in this step. These are only checked after "enter" or 50 // "exit" actions. 51 gTestSteps = [ 52 // innerRoot 53 [["enter", innerRoot], [iframe, innerRoot]], 54 [[ "exit", innerDoc], [ null, null]], 55 [["enter", innerRoot], [iframe, innerRoot]], 56 [[ "exit", document], [ null, null]], 57 // root, innerRoot 58 [["enter", root], [ root, null]], 59 [["enter", innerRoot], [iframe, innerRoot]], 60 [[ "exit", innerDoc], [ root, null]], 61 [[ "exit", document], [ null, null]], 62 [["enter", root], [ root, null]], 63 [["enter", innerRoot], [iframe, innerRoot]], 64 [[ "exit", document], [ root, null]], 65 [[ "exit", document], [ null, null]], 66 // iframe, innerRoot 67 [["enter", iframe], [iframe, null]], 68 [["enter", innerRoot], [iframe, innerRoot]], 69 [[ "exit", innerDoc], [iframe, null]], 70 [[ "exit", document], [ null, null]], 71 [["enter", iframe], [iframe, null]], 72 [["enter", innerRoot], [iframe, innerRoot]], 73 [["reset", 1], [ null, null]], 74 [[ "exit", document], [ null, null]], 75 // root, iframe, innerRoot 76 [["enter", root], [ root, null]], 77 [["enter", iframe], [iframe, null]], 78 [["enter", innerRoot], [iframe, innerRoot]], 79 [[ "exit", innerDoc], [iframe, null]], 80 [[ "exit", document], [ root, null]], 81 [[ "exit", document], [ null, null]], 82 [["enter", root], [ root, null]], 83 [["enter", iframe], [iframe, null]], 84 [["enter", innerRoot], [iframe, innerRoot]], 85 [[ "exit", document], [ root, null]], 86 [["reset", 1], [ null, null]], 87 [[ "exit", document], [ null, null]], 88 ]; 89 90 nextStep(); 91 } 92 93 function nextStep() { 94 if (gTestIndex == gTestSteps.length) { 95 opener.nextTest(); 96 return; 97 } 98 99 var index = gTestIndex; 100 var [[action, target], [fsOuter, fsInner]] = gTestSteps[gTestIndex++]; 101 102 function checkAndNext() { 103 is(document.fullscreenElement, fsOuter, 104 `Fullscreen element of outer doc should match after step ${index}`); 105 is(gInnerDoc.fullscreenElement, fsInner, 106 `Fullscreen element of inner doc should match after step ${index}`); 107 nextStep(); 108 } 109 110 info(`Executing step ${index}: ${action} on ${target}...`); 111 if (action == "enter") { 112 // For "enter" action, the target is the element 113 var doc = target.ownerDocument; 114 addFullscreenChangeContinuation("enter", checkAndNext, doc); 115 target.requestFullscreen(); 116 } else if (action == "exit") { 117 // For "exit" action, the target is the document 118 addFullscreenChangeContinuation("exit", checkAndNext, target); 119 target.exitFullscreen(); 120 } else if (action == "reset") { 121 // For "reset" action, the target is the number to setFullscreenChangeEnters. 122 setFullscreenChangeEnters(target); 123 nextStep(); 124 } else { 125 ok(false, `Unknown action ${action}`); 126 } 127 } 128 </script> 129 </body> 130 </html>