browser_test_scrollTo.js (1765B)
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 function getCenterY(acc) { 8 const y = {}; 9 const h = {}; 10 acc.getBounds({}, y, {}, h); 11 return y.value + h.value / 2; 12 } 13 14 /** 15 * Test nsIAccessible::scrollTo. 16 */ 17 addAccessibleTask( 18 ` 19 <div id="scroller" style="height: 100vh; overflow: scroll;"> 20 <hr style="height: 100vh;"> 21 <p id="p1" style="height: 10vh;">a</p> 22 <hr style="height: 100vh;"> 23 <p id="p2" style="height: 10vh;">b</p> 24 <hr style="height: 100vh;"> 25 </div> 26 `, 27 async function (browser, docAcc) { 28 const scroller = findAccessibleChildByID(docAcc, "scroller"); 29 const scrollerY = getCenterY(scroller); 30 // scroller can only show one of p1 or p2, not both. 31 const p1 = findAccessibleChildByID(docAcc, "p1"); 32 info("scrollTo p1"); 33 let scrolled = waitForEvent( 34 nsIAccessibleEvent.EVENT_SCROLLING_END, 35 scroller 36 ); 37 p1.scrollTo(SCROLL_TYPE_ANYWHERE); 38 await scrolled; 39 isWithin(getCenterY(p1), scrollerY, 10, "p1 scrolled to center"); 40 const p2 = findAccessibleChildByID(docAcc, "p2"); 41 info("scrollTo p2"); 42 scrolled = waitForEvent(nsIAccessibleEvent.EVENT_SCROLLING_END, scroller); 43 p2.scrollTo(SCROLL_TYPE_ANYWHERE); 44 await scrolled; 45 isWithin(getCenterY(p2), scrollerY, 10, "p2 scrolled to center"); 46 info("scrollTo p1"); 47 scrolled = waitForEvent(nsIAccessibleEvent.EVENT_SCROLLING_END, scroller); 48 p1.scrollTo(SCROLL_TYPE_ANYWHERE); 49 await scrolled; 50 isWithin(getCenterY(p1), scrollerY, 10, "p1 scrolled to center"); 51 }, 52 { topLevel: true, iframe: true, remoteIframe: true, chrome: true } 53 );