helper_key_scroll.html (4111B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1383365 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Async key scrolling test, helper page</title> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <script src="/tests/SimpleTest/paint_listener.js"></script> 11 <script type="application/javascript" src="apz_test_utils.js"></script> 12 <script type="application/javascript"> 13 // -------------------------------------------------------------------- 14 // Async key scrolling test 15 // 16 // This test checks that a key scroll occurs asynchronously. 17 // 18 // The page contains a <div> that is large enough to make the page 19 // scrollable. We first synthesize a page down to scroll to the bottom 20 // of the page. Once we have reached the bottom of the page, we synthesize 21 // a page up to get us back to the top of the page. 22 // 23 // Once at the top, we request test data from APZ, rebuild the APZC tree 24 // structure, and use it to check that async key scrolling happened. 25 // -------------------------------------------------------------------- 26 27 async function test() { 28 // Sanity check 29 is(checkHasAsyncKeyScrolled(), false, "expected no async key scrolling before test"); 30 31 // Send a key to initiate a page scroll to take us to the bottom of the 32 // page. This scroll is done synchronously because APZ doesn't have 33 // current focus state at page load. 34 let scrollBottomPromise = new Promise(resolve => { 35 let checkBottom = function() { 36 if (window.scrollY < window.scrollMaxY) { 37 return; 38 } 39 info("Reached final scroll position of sync KEY_End scroll"); 40 window.removeEventListener("scroll", checkBottom); 41 resolve(); 42 }; 43 window.addEventListener("scroll", checkBottom); 44 }); 45 46 window.synthesizeKey("KEY_End"); 47 await scrollBottomPromise; 48 49 // Spin the refresh driver a few times, so that the AsyncScroll instance 50 // that was running the main-thread scroll animation finishes up and 51 // triggers any repaints that it needs to. 52 var utils = SpecialPowers.DOMWindowUtils; 53 for (var i = 0; i < 10; i++) { 54 utils.advanceTimeAndRefresh(50); 55 } 56 utils.restoreNormalRefresh(); 57 58 // Wait for the APZ to reach a stable state as well, before dispatching 59 // the next key input or the default action won't occur. 60 await promiseApzFlushedRepaints(); 61 62 is(checkHasAsyncKeyScrolled(), false, "expected no async key scrolling before KEY_Home dispatch"); 63 64 // This scroll should be asynchronous now that the focus state is up to date. 65 let scrollTopPromise = new Promise(resolve => { 66 let checkTop = function() { 67 if (window.scrollY > 0) { 68 return; 69 } 70 info("Reached final scroll position of async KEY_Home scroll"); 71 window.removeEventListener("scroll", checkTop); 72 resolve(); 73 }; 74 window.addEventListener("scroll", checkTop); 75 }); 76 77 window.synthesizeKey("KEY_Home"); 78 await scrollTopPromise; 79 80 // Wait for APZ to settle and then check that async scrolling happened. 81 await promiseApzFlushedRepaints(); 82 is(checkHasAsyncKeyScrolled(), true, "expected async key scrolling after test"); 83 } 84 85 function checkHasAsyncKeyScrolled() { 86 // Reconstruct the APZC tree structure in the last paint. 87 var apzcTree = getLastApzcTree(); 88 var rcd = findRcdNode(apzcTree); 89 90 if (rcd) { 91 return rcd.hasAsyncKeyScrolled === "1"; 92 } 93 94 info("Last paint rcd is null"); 95 return false; 96 } 97 98 waitUntilApzStable() 99 .then(forceLayerTreeToCompositor) 100 .then(test) 101 .then(subtestDone, subtestFailed); 102 </script> 103 </head> 104 <body style="height: 500px; overflow: scroll"> 105 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1383365">Async key scrolling test</a> 106 <!-- Put enough content into the page to make it have a nonzero scroll range --> 107 <div style="height: 5000px"></div> 108 </body> 109 </html>