helper_bug1756529.html (13803B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1756529 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Page scrolling bug test, helper page</title> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <script type="application/javascript" src="apz_test_native_event_utils.js"></script> 11 <script type="application/javascript" src="apz_test_utils.js"></script> 12 <script src="/tests/SimpleTest/paint_listener.js"></script> 13 <script type="application/javascript"> 14 // -------------------------------------------------------------------- 15 // Page scrolling not smooth test 16 // 17 // This test checks that a page scroll respects general_smoothScroll_pages preference. 18 // 19 // The page contains a <div> that is large enough to make the page 20 // scrollable. 21 // 22 // We trigger the page scroll and then we wait to reach destination 23 // Expecting an instant scroll, we check that the scroll event is called once 24 // -------------------------------------------------------------------- 25 const testData = [ 26 {scrollOrigin: "page", smooth: false, 27 prefs: [["general.smoothScroll", true], ["general.smoothScroll.pages", false], 28 ["general.smoothScroll.msdPhysics.enabled", true]]}, 29 {scrollOrigin: "page", smooth: false, 30 prefs: [["general.smoothScroll", false], ["general.smoothScroll.pages", true], 31 ["general.smoothScroll.msdPhysics.enabled", true]]}, 32 {scrollOrigin: "page", smooth: true, 33 prefs: [["general.smoothScroll", true], ["general.smoothScroll.pages", true], 34 ["general.smoothScroll.msdPhysics.enabled", true]]}, 35 {scrollOrigin: "page", smooth: false, 36 prefs: [["general.smoothScroll", true], ["general.smoothScroll.pages", false], 37 ["general.smoothScroll.msdPhysics.enabled", false]]}, 38 {scrollOrigin: "page", smooth: false, 39 prefs: [["general.smoothScroll", false], ["general.smoothScroll.pages", true], 40 ["general.smoothScroll.msdPhysics.enabled", false]]}, 41 {scrollOrigin: "page", smooth: true, 42 prefs: [["general.smoothScroll", true], ["general.smoothScroll.pages", true], 43 ["general.smoothScroll.msdPhysics.enabled", false]]}, 44 // Origin:Line Scrolling tests 45 {scrollOrigin: "line", smooth: false, 46 prefs: [["general.smoothScroll", true], ["general.smoothScroll.lines", false], 47 ["general.smoothScroll.msdPhysics.enabled", true]]}, 48 {scrollOrigin: "line", smooth: false, 49 prefs: [["general.smoothScroll", false], ["general.smoothScroll.lines", true], 50 ["general.smoothScroll.msdPhysics.enabled", true]]}, 51 {scrollOrigin: "line", smooth: true, 52 prefs: [["general.smoothScroll", true], ["general.smoothScroll.lines", true], 53 ["general.smoothScroll.msdPhysics.enabled", true]]}, 54 {scrollOrigin: "line", smooth: false, 55 prefs: [["general.smoothScroll", true], ["general.smoothScroll.lines", false], 56 ["general.smoothScroll.msdPhysics.enabled", false]]}, 57 {scrollOrigin: "line", smooth: false, 58 prefs: [["general.smoothScroll", false], ["general.smoothScroll.lines", true], 59 ["general.smoothScroll.msdPhysics.enabled", false]]}, 60 {scrollOrigin: "line", smooth: true, 61 prefs: [["general.smoothScroll", true], ["general.smoothScroll.lines", true], 62 ["general.smoothScroll.msdPhysics.enabled", false]]}, 63 // Origin:Other Scrolling test 64 {scrollOrigin: "other", smooth: false, 65 prefs: [["general.smoothScroll", true], ["general.smoothScroll.other", false], 66 ["general.smoothScroll.msdPhysics.enabled", true]]}, 67 {scrollOrigin: "other", smooth: false, 68 prefs: [["general.smoothScroll", false], ["general.smoothScroll.other", true], 69 ["general.smoothScroll.msdPhysics.enabled", true]]}, 70 {scrollOrigin: "other", smooth: true, 71 prefs: [["general.smoothScroll", true], ["general.smoothScroll.other", true], 72 ["general.smoothScroll.msdPhysics.enabled", true]]}, 73 {scrollOrigin: "other", smooth: false, 74 prefs: [["general.smoothScroll", true], ["general.smoothScroll.other", false], 75 ["general.smoothScroll.msdPhysics.enabled", false]]}, 76 {scrollOrigin: "other", smooth: false, 77 prefs: [["general.smoothScroll", false], ["general.smoothScroll.other", true], 78 ["general.smoothScroll.msdPhysics.enabled", false]]}, 79 {scrollOrigin: "other", smooth: true, 80 prefs: [["general.smoothScroll", true], ["general.smoothScroll.other", true], 81 ["general.smoothScroll.msdPhysics.enabled", false]]}]; 82 83 async function test(data) { 84 /* 85 Test Data: 86 { 87 scrollOrigin: "page"|"other"|"line", 88 smooth: bool, 89 prefs: prefences 90 } 91 */ 92 const scrollOrigin = data.scrollOrigin; 93 const smooth = data.smooth; 94 const msdPhysics = data.prefs[2][1]; 95 let destination = 0; 96 let key = ""; 97 switch (scrollOrigin){ 98 case "page": 99 destination = document.scrollingElement.clientHeight * 0.8; 100 key = "KEY_PageDown"; 101 break; 102 case "other": 103 destination = 40000; // Div is 50k 104 key = "KEY_End"; 105 break; 106 case "line": 107 default: 108 destination = 50; // pref set to scroll by 5 lines 109 // line scroll amounts vary by platform but are 110 // in the 16-19px range 111 key = "KEY_ArrowDown"; 112 } 113 await SpecialPowers.pushPrefEnv({ set: data.prefs }); 114 info(`Testing Scrolling preferences. [origin: ${scrollOrigin}; smooth: ${smooth}; msdPhysics: ${msdPhysics}; ${destination}]`); 115 116 // Send the synthesized key event, and wait until it arrives in the 117 // content process. 118 let keyPromise = promiseOneEvent(window, "keydown", null); 119 window.synthesizeKey(key); 120 await keyPromise; 121 122 // Take control of the refresh driver. It's important to do this 123 // as soon as the key event has arrived, to ensure that any compositor 124 // animation hasn't started yet. Otherwise, the compositor animation 125 // could start and get in multiple samples (potentially the entire 126 // animation) before the content process gets a chance to observe it, 127 // preventing us from distinguishing smooth scrolls from instant scrolls. 128 let utils = SpecialPowers.DOMWindowUtils; 129 utils.advanceTimeAndRefresh(0); 130 131 // Flush any pending paints. This gives a chance for any handoff of 132 // the scroll to APZ to occur. 133 await promiseAllPaintsDone(); 134 135 // Tick the refresh driver manually until we detect that scrolling has 136 // started (scrollY > 0) and then stopped (scroll offset the same in 137 // two subsequent ticks). 138 let startedScroll = false; 139 let stoppedScroll = false; 140 let scrollCount = 0; 141 let prevScrollPos = window.scrollY; 142 while (!stoppedScroll) { 143 // Tick the refresh driver. This triggers a composite, so any 144 // compositor animation will be sampled. (Main thread animations 145 // will also be sampled.) 146 utils.advanceTimeAndRefresh(16); 147 148 // Flush APZ repaints to ensure that scroll offset changes from 149 // a compositor sample reach the content process. 150 await promiseApzFlushedRepaints(); 151 152 // Track the number of ticks in which the scroll offset changed. 153 let scrollPos = window.scrollY; 154 if (startedScroll && scrollPos == prevScrollPos) { 155 stoppedScroll = true; 156 break; 157 } 158 if (!startedScroll && scrollPos > 0) { 159 startedScroll = true; 160 } 161 if (startedScroll) { 162 scrollCount++; 163 } 164 prevScrollPos = scrollPos; 165 } 166 167 info(`Scrolled to ${window.scrollY}`); 168 169 // Relinquish control of the refresh driver. 170 utils.restoreNormalRefresh(); 171 172 ok(window.scrollY >= destination, `The page did not scroll [origin: ${scrollOrigin}, smooth: ${smooth}]`); 173 if (smooth) 174 ok(scrollCount > 1, 175 `Scrolled only once, but expecting a smooth transtion [origin: ${scrollOrigin}; msdPhysics: ${msdPhysics}]`); 176 else 177 is(scrollCount, 1, 178 `Scrolled more than once, but expecting an instant scroll [origin: ${scrollOrigin}; msdPhysics: ${msdPhysics}]`); 179 180 // Synthesize a touch tap to cancel the animation if it's still in-progress. 181 // (scrollTo() does not do this as of bug 1692708, it adjusts the destination 182 // of the animation by a relative delta). 183 let touchStartPromise = promiseOneEvent(window, "touchstart", null); 184 await synthesizeNativeTap(window, 50, 50); 185 // Wait until the tap is actually processed by APZ. 186 await touchStartPromise; 187 await promiseApzFlushedRepaints(); 188 189 // Reset scroll position for next case. 190 window.scrollTo(0, 0); 191 await promiseApzFlushedRepaints(); 192 is(0, window.scrollY, `Expected to be scrolled to origin, actually scrolled to ${window.scrollY}`) 193 } 194 195 async function runTests() { 196 for (i = 0; i < testData.length; i++){ 197 await test(testData[i]); 198 } 199 } 200 201 if (getPlatform() == "linux" || getPlatform() == "mac") { 202 // FIXME(bug 1760731): On Linux, this test frequently hangs at 203 // "await touchStartPromise", so we skip it. 204 // For Mac, the test is disabled due to a high intermittent failure 205 // rate reported in bug 1771836. 206 ok(true, "Test is disabled on Linux and Mac, skipping"); 207 subtestDone(); 208 } else { 209 waitUntilApzStable() 210 .then(runTests) 211 .then(subtestDone, subtestFailed); 212 } 213 </script> 214 </head> 215 <body style="height: 10000px; overflow: scroll;"> 216 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1756529">SmoothScrollPage not honored with MSD physics bug.</a> 217 <!-- Put enough content into the page to make it have a nonzero scroll range --> 218 <div style="height: 50000px;"> 219 <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tellus in metus vulputate eu. Vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet. Congue quisque egestas diam in. Pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu. Eleifend mi in nulla posuere. Proin libero nunc consequat interdum varius. Risus pretium quam vulputate dignissim suspendisse in est. Lacus vel facilisis volutpat est. Donec pretium vulputate sapien nec. Feugiat sed lectus vestibulum mattis. Platea dictumst quisque sagittis purus. Vulputate eu scelerisque felis imperdiet proin fermentum leo vel. Enim facilisis gravida neque convallis a cras semper auctor. Placerat orci nulla pellentesque dignissim enim sit.</p> 220 <p>Augue neque gravida in fermentum et sollicitudin ac. Mattis enim ut tellus elementum sagittis vitae et. Malesuada nunc vel risus commodo viverra maecenas accumsan. Viverra nibh cras pulvinar mattis nunc sed. Lectus nulla at volutpat diam ut venenatis tellus in. Non tellus orci ac auctor. Magna etiam tempor orci eu lobortis. Malesuada nunc vel risus commodo viverra maecenas accumsan lacus vel. Sagittis orci a scelerisque purus. Tellus pellentesque eu tincidunt tortor. Vulputate dignissim suspendisse in est ante in. Tristique et egestas quis ipsum suspendisse. Quisque egestas diam in arcu cursus. Massa massa ultricies mi quis hendrerit dolor magna eget. Mattis nunc sed blandit libero volutpat sed. Consectetur purus ut faucibus pulvinar elementum integer enim.</p> 221 <p>Vestibulum lorem sed risus ultricies tristique nulla. Imperdiet nulla malesuada pellentesque elit eget gravida. Feugiat nisl pretium fusce id velit ut tortor pretium. Commodo ullamcorper a lacus vestibulum sed arcu non odio. Id nibh tortor id aliquet lectus proin nibh nisl condimentum. Amet volutpat consequat mauris nunc congue nisi vitae suscipit tellus. Neque ornare aenean euismod elementum. Semper quis lectus nulla at. Massa sed elementum tempus egestas. Praesent elementum facilisis leo vel fringilla est ullamcorper eget nulla. Pellentesque elit eget gravida cum sociis natoque penatibus et. Massa enim nec dui nunc mattis enim. Laoreet suspendisse interdum consectetur libero id faucibus nisl. Fusce ut placerat orci nulla.</p> 222 <p>Vitae tempus quam pellentesque nec nam aliquam. Vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare. Nam libero justo laoreet sit amet. Arcu non sodales neque sodales. Nec ultrices dui sapien eget mi proin sed. Parturient montes nascetur ridiculus mus mauris vitae ultricies. Lacus sed viverra tellus in hac habitasse. Orci phasellus egestas tellus rutrum. Leo a diam sollicitudin tempor id eu nisl. Diam phasellus vestibulum lorem sed risus ultricies tristique nulla. Lectus nulla at volutpat diam ut venenatis tellus in. Cursus metus aliquam eleifend mi in nulla. Et ultrices neque ornare aenean euismod. Sit amet aliquam id diam maecenas ultricies mi. Volutpat diam ut venenatis tellus in metus vulputate eu.</p> 223 <p>Pellentesque elit ullamcorper dignissim cras tincidunt. Morbi tincidunt augue interdum velit euismod. Diam vel quam elementum pulvinar etiam non quam. Eget duis at tellus at urna. Posuere ac ut consequat semper viverra nam libero justo laoreet. Ac turpis egestas maecenas pharetra convallis posuere. Ultrices tincidunt arcu non sodales neque sodales ut etiam sit. In eu mi bibendum neque egestas. Pellentesque sit amet porttitor eget dolor morbi. Ac tortor dignissim convallis aenean et tortor at. Elementum tempus egestas sed sed risus pretium quam. Nisi scelerisque eu ultrices vitae auctor eu augue. Urna duis convallis convallis tellus id interdum velit laoreet id. Auctor eu augue ut lectus arcu bibendum at varius vel.</p> 224 </div> 225 </body> 226 </html>