window_bug1369072.html (7510B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1369072 5 --> 6 <head> 7 <title>Test for Bug 1369072</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <script src="/tests/SimpleTest/paint_listener.js"></script> 11 <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1369072">Mozilla Bug 1369072</a> 16 <div id="display"> 17 <iframe id="iframe" srcdoc="<a id='anchor' href='about:home'>anchor text</a><div id='div'></div>" style="width: 300px; height: 300px;"></iframe> 18 <!-- make <body> contents overflow --> 19 <div style="width: 1000px; height: 1000px;"></div> 20 </div> 21 <div id="content" style="display: none"> 22 </div> 23 <pre id="test"> 24 <script type="application/javascript"> 25 26 SimpleTest.waitForExplicitFinish(); 27 SimpleTest.waitForFocus(runTests, window); 28 29 function ok() 30 { 31 window.opener.ok.apply(window.opener, arguments); 32 } 33 34 function is() 35 { 36 window.opener.is.apply(window.opener, arguments); 37 } 38 39 async function runTests() 40 { 41 await SpecialPowers.pushPrefEnv({ 42 set: [ 43 ["general.smoothScroll", false], 44 ["toolkit.scrollbox.verticalScrollDistance", 20], 45 ["toolkit.scrollbox.horizontalScrollDistance", 20], 46 ], 47 }); 48 49 var iframe = document.getElementById("iframe"); 50 var anchor = iframe.contentDocument.getElementById("anchor"); 51 var div = iframe.contentDocument.getElementById("div"); 52 53 async function resetScroll() 54 { 55 var oldFocus = document.activeElement; 56 var oldFrameFocus = iframe.contentDocument.activeElement; 57 58 // Cancel any scroll animation on the target scroll elements to make sure 59 // setting scrollTop or scrolLeft works as expected. 60 // cancelScrollAnimation clears focus, so make sure to restore it. 61 await cancelScrollAnimation(document.documentElement); 62 await cancelScrollAnimation(iframe.contentDocument.documentElement); 63 64 oldFocus.focus(); 65 oldFrameFocus.focus(); 66 67 return new Promise(resolve => { 68 var scrollParent = document.documentElement.scrollTop || document.documentElement.scrollLeft; 69 var scrollChild = iframe.contentDocument.documentElement.scrollTop || iframe.contentDocument.documentElement.scrollLeft; 70 if (scrollParent) { 71 window.addEventListener("scroll", () => { 72 scrollParent = false; 73 if (!scrollChild) { 74 SimpleTest.executeSoon(resolve); 75 } 76 }, { once: true }); 77 } 78 if (scrollChild) { 79 iframe.contentWindow.addEventListener("scroll", () => { 80 scrollChild = false; 81 if (!scrollParent) { 82 SimpleTest.executeSoon(resolve); 83 } 84 }, { once: true }); 85 } 86 document.documentElement.scrollTop = 0; 87 document.documentElement.scrollLeft = 0; 88 iframe.contentDocument.documentElement.scrollTop = 0; 89 iframe.contentDocument.documentElement.scrollLeft = 0; 90 if (!scrollParent && !scrollChild) { 91 SimpleTest.executeSoon(resolve); 92 } 93 }); 94 } 95 96 async function tryToScrollWithKey(aVertical) 97 { 98 await resetScroll(); 99 100 return new Promise(resolve => { 101 // Wait scroll event 102 function onScroll() { 103 SimpleTest.executeSoon(resolve); 104 } 105 window.addEventListener("scroll", onScroll, { once: true }); 106 iframe.contentWindow.addEventListener("scroll", onScroll, { once: true }); 107 108 if (aVertical) { 109 synthesizeKey("KEY_ArrowDown"); 110 } else { 111 synthesizeKey("KEY_ArrowRight"); 112 } 113 }); 114 } 115 116 // When iframe element has focus and the iframe document isn't scrollable, the parent document should be scrolled instead. 117 document.body.focus(); 118 iframe.focus(); 119 await tryToScrollWithKey(true); 120 ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is not scrollable should cause scrolling the parent document"); 121 await tryToScrollWithKey(false); 122 ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is not scrollable should cause scrolling the parent document"); 123 await resetScroll(); 124 125 // When iframe element has focus and the iframe document scrollable, the parent document shouldn't be scrolled. 126 document.body.focus(); 127 div.style.height = "1000px"; 128 div.style.width = "1000px"; 129 iframe.focus(); 130 await tryToScrollWithKey(true); 131 is(document.documentElement.scrollTop, 0, "ArrowDown keydown event at the iframe whose content is scrollable shouldn't cause scrolling the parent document"); 132 ok(iframe.contentDocument.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable should cause scrolling the iframe document"); 133 await tryToScrollWithKey(false); 134 is(document.documentElement.scrollLeft, 0, "ArrowRight keydown event at the iframe whose content is scrollable shouldn't cause scrolling the parent document"); 135 ok(iframe.contentDocument.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable should cause scrolling the iframe document"); 136 await resetScroll(); 137 138 // If iframe document cannot scroll to specific direction, parent document should be scrolled instead. 139 div.style.height = "1px"; 140 div.style.width = "1000px"; 141 iframe.focus(); 142 await tryToScrollWithKey(true); 143 ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable only horizontally should cause scrolling the parent document"); 144 await tryToScrollWithKey(false); 145 is(document.documentElement.scrollLeft, 0, "ArrowRight keydown event at the iframe whose content is scrollable only horizontally shouldn't cause scrolling the parent document"); 146 ok(iframe.contentDocument.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable only horizontally should cause scrolling the iframe document"); 147 await resetScroll(); 148 149 div.style.height = "1000px"; 150 div.style.width = "1px"; 151 iframe.focus(); 152 await tryToScrollWithKey(true); 153 is(document.documentElement.scrollTop, 0, "ArrowDown keydown event at the iframe whose content is scrollable only vertically shouldn't cause scrolling the parent document"); 154 ok(iframe.contentDocument.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable only vertically should cause scrolling the iframe document"); 155 await tryToScrollWithKey(false); 156 ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable only vertically should cause scrolling the parent document"); 157 await resetScroll(); 158 159 // Hidden iframe shouldn't consume keyboard events if it was not scrollable. 160 document.body.focus(); 161 anchor.focus(); 162 iframe.style.display = "none"; 163 await tryToScrollWithKey(true); 164 ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event after hiding the iframe should cause scrolling the parent document"); 165 await tryToScrollWithKey(false); 166 ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event after hiding the iframe should cause scrolling the parent document"); 167 await resetScroll(); 168 169 // Make sure the result visible in the viewport. 170 document.documentElement.scrollTop = 0; 171 document.documentElement.scrollLeft = 0; 172 window.opener.finish(); 173 } 174 175 </script> 176 </pre> 177 </body> 178 </html>