browser_visibleFindSelection.js (2141B)
1 add_task(async function () { 2 const childContent = 3 "<div style='position: absolute; left: 2200px; background: green; width: 200px; height: 200px;'>" + 4 "div</div><div style='position: absolute; left: 0px; background: red; width: 200px; height: 200px;'>" + 5 "<span id='s'>div</span></div>"; 6 7 let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser)); 8 9 await BrowserTestUtils.loadURIString({ 10 browser: tab.linkedBrowser, 11 uriString: "data:text/html;charset=utf-8," + escape(childContent), 12 }); 13 await SimpleTest.promiseFocus(gBrowser.selectedBrowser); 14 15 let remote = gBrowser.selectedBrowser.isRemoteBrowser; 16 17 let findBarOpenPromise = BrowserTestUtils.waitForEvent( 18 gBrowser, 19 "findbaropen" 20 ); 21 EventUtils.synthesizeKey("f", { accelKey: true }); 22 await findBarOpenPromise; 23 24 ok(gFindBarInitialized, "find bar is now initialized"); 25 26 // Finds the div in the green box. 27 let scrollPromise = remote 28 ? BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "scroll") 29 : BrowserTestUtils.waitForEvent(gBrowser, "scroll"); 30 EventUtils.sendString("div"); 31 await scrollPromise; 32 33 // Wait for one paint to ensure we've processed the previous key events and scrolling. 34 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 35 return new Promise(resolve => { 36 content.requestAnimationFrame(() => { 37 content.setTimeout(resolve, 0); 38 }); 39 }); 40 }); 41 42 // Finds the div in the red box. 43 scrollPromise = remote 44 ? BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "scroll") 45 : BrowserTestUtils.waitForEvent(gBrowser, "scroll"); 46 EventUtils.synthesizeKey("g", { accelKey: true }); 47 await scrollPromise; 48 49 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 50 Assert.greaterOrEqual( 51 content.document.getElementById("s").getBoundingClientRect().left, 52 0, 53 "scroll should include find result" 54 ); 55 }); 56 57 // clear the find bar 58 EventUtils.synthesizeKey("a", { accelKey: true }); 59 EventUtils.synthesizeKey("KEY_Delete"); 60 61 gFindBar.close(); 62 gBrowser.removeCurrentTab(); 63 });