browser_test_visibility.js (6055B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 async function runTest(browser, accDoc) { 8 let getAcc = id => findAccessibleChildByID(accDoc, id); 9 10 await untilCacheOk( 11 () => testVisibility(getAcc("div"), false, false), 12 "Div should be on screen" 13 ); 14 15 let input = getAcc("input_scrolledoff"); 16 await untilCacheOk( 17 () => testVisibility(input, true, false), 18 "Input should be offscreen" 19 ); 20 21 // scrolled off item (twice) 22 let lastLi = getAcc("li_last"); 23 await untilCacheOk( 24 () => testVisibility(lastLi, true, false), 25 "Last list item should be offscreen" 26 ); 27 28 // scroll into view the item 29 await invokeContentTask(browser, [], () => { 30 content.document.getElementById("li_last").scrollIntoView(true); 31 }); 32 await untilCacheOk( 33 () => testVisibility(lastLi, false, false), 34 "Last list item should no longer be offscreen" 35 ); 36 37 // first item is scrolled off now (testcase for bug 768786) 38 let firstLi = getAcc("li_first"); 39 await untilCacheOk( 40 () => testVisibility(firstLi, true, false), 41 "First listitem should now be offscreen" 42 ); 43 44 await untilCacheOk( 45 () => testVisibility(getAcc("frame"), false, false), 46 "iframe should initially be onscreen" 47 ); 48 49 let loaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, "iframeDoc"); 50 await invokeContentTask(browser, [], () => { 51 content.document.querySelector("iframe").src = 52 'data:text/html,<body id="iframeDoc"><p id="p">hi</p></body>'; 53 }); 54 55 const iframeDoc = (await loaded).accessible; 56 await untilCacheOk( 57 () => testVisibility(getAcc("frame"), false, false), 58 "iframe outer doc should now be on screen" 59 ); 60 await untilCacheOk( 61 () => testVisibility(iframeDoc, false, false), 62 "iframe inner doc should be on screen" 63 ); 64 const iframeP = findAccessibleChildByID(iframeDoc, "p"); 65 await untilCacheOk( 66 () => testVisibility(iframeP, false, false), 67 "iframe content should also be on screen" 68 ); 69 70 // scroll into view the div 71 await invokeContentTask(browser, [], () => { 72 content.document.getElementById("div").scrollIntoView(true); 73 }); 74 75 await untilCacheOk( 76 () => testVisibility(getAcc("frame"), true, false), 77 "iframe outer doc should now be off screen" 78 ); 79 await untilCacheOk( 80 () => testVisibility(iframeDoc, true, false), 81 "iframe inner doc should now be off screen" 82 ); 83 await untilCacheOk( 84 () => testVisibility(iframeP, true, false), 85 "iframe content should now be off screen" 86 ); 87 88 let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser); 89 // Accessibles in background tab should have offscreen state and no 90 // invisible state. 91 await untilCacheOk( 92 () => testVisibility(getAcc("div"), true, false), 93 "Accs in background tab should be offscreen but not invisible." 94 ); 95 96 await untilCacheOk( 97 () => testVisibility(getAcc("frame"), true, false), 98 "iframe outer doc should still be off screen" 99 ); 100 await untilCacheOk( 101 () => testVisibility(iframeDoc, true, false), 102 "iframe inner doc should still be off screen" 103 ); 104 await untilCacheOk( 105 () => testVisibility(iframeP, true, false), 106 "iframe content should still be off screen" 107 ); 108 109 BrowserTestUtils.removeTab(newTab); 110 } 111 112 addAccessibleTask( 113 ` 114 <div id="div" style="border:2px solid blue; width: 500px; height: 110vh;"></div> 115 <input id="input_scrolledoff"> 116 <ul style="border:2px solid red; width: 100px; height: 50px; overflow: auto;"> 117 <li id="li_first">item1</li><li>item2</li><li>item3</li> 118 <li>item4</li><li>item5</li><li id="li_last">item6</li> 119 </ul> 120 <iframe id="frame"></iframe> 121 `, 122 runTest, 123 { iframe: true, remoteIframe: true } 124 ); 125 126 /** 127 * Test div containers are reported as onscreen, even if some of their contents are 128 * offscreen. 129 */ 130 addAccessibleTask( 131 ` 132 <div id="outer" style="width:200vw; background: green; overflow:scroll;"><div id="inner"><div style="display:inline-block; width:100vw; background:red;" id="on">on screen</div><div style="background:blue; display:inline;" id="off">offscreen</div></div></div> 133 `, 134 async function (browser, accDoc) { 135 const outer = findAccessibleChildByID(accDoc, "outer"); 136 const inner = findAccessibleChildByID(accDoc, "inner"); 137 const on = findAccessibleChildByID(accDoc, "on"); 138 const off = findAccessibleChildByID(accDoc, "off"); 139 140 await untilCacheOk( 141 () => testVisibility(outer, false, false), 142 "outer should be on screen and visible" 143 ); 144 await untilCacheOk( 145 () => testVisibility(inner, false, false), 146 "inner should be on screen and visible" 147 ); 148 await untilCacheOk( 149 () => testVisibility(on, false, false), 150 "on should be on screen and visible" 151 ); 152 await untilCacheOk( 153 () => testVisibility(off, true, false), 154 "off should be off screen and visible" 155 ); 156 }, 157 { chrome: true, iframe: true, remoteIframe: true } 158 ); 159 160 // test dynamic translation 161 addAccessibleTask( 162 `<div id="container" style="position: absolute; left: -300px; top: 100px;">Hello</div> 163 <button id="b">Move</button>`, 164 async function (browser, accDoc) { 165 const container = findAccessibleChildByID(accDoc, "container"); 166 await untilCacheOk( 167 () => testVisibility(container, true, false), 168 "container should be off screen and visible" 169 ); 170 await invokeContentTask(browser, [], () => { 171 let b = content.document.getElementById("b"); 172 b.click(); 173 }); 174 175 await waitForContentPaint(browser); 176 await untilCacheOk( 177 () => testVisibility(container, false, false), 178 "container should be on screen and visible" 179 ); 180 }, 181 { 182 chrome: true, 183 iframe: true, 184 remoteIframe: true, 185 contentSetup: async function contentSetup() { 186 content.document.getElementById("b").onclick = () => { 187 content.document.getElementById("container").style.transform = 188 "translateX(400px)"; 189 }; 190 }, 191 } 192 );