Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 (function() { | |
| 2 var instantTest = async_test('interrupt with instant scroll'); | |
| 3 var smoothTest = async_test('interrupt with smooth scroll'); | |
| 4 var touchTest = async_test('interrupt with touch scroll'); | |
| 5 var wheelTest = async_test('interrupt with mouse wheel'); | |
| 6 var testElement; | |
| 7 var testCase; | |
| 8 var testInnerPoint; | |
| 9 var previousScrollTop; | |
| 10 var previousTimestamp; | |
| 11 | |
| 12 | |
| 13 function verifyScrollOffsetUnchangedAfterInstantScroll() | |
| 14 { | |
| 15 instantTest.step(function() { | |
| 16 assert_equals(testElement.scrollTop, testCase.y3); | |
|
Ian Vollick
2014/02/06 16:02:31
I don't like the assumptions about the contents of
| |
| 17 }); | |
| 18 instantTest.done(); | |
| 19 window.requestAnimationFrame(startSmoothTest); | |
| 20 } | |
| 21 | |
| 22 function verifyProgressTowardsNewDestination() | |
| 23 { | |
| 24 var previousDelta = testCase.y3 - previousScrollTop; | |
| 25 var currentDelta = testCase.y3 - testElement.scrollTop; | |
| 26 if (Math.abs(currentDelta) < Math.abs(previousDelta)) { | |
| 27 smoothTest.done(); | |
| 28 window.requestAnimationFrame(startTouchTest); | |
| 29 return; | |
| 30 } | |
| 31 previousScrollTop = testElement.scrollTop; | |
| 32 window.requestAnimationFrame(verifyProgressTowardsNewDestination); | |
| 33 } | |
| 34 | |
| 35 function verifyScrollOffsetStopsChangingAfterTouchScroll(timestamp) | |
| 36 { | |
| 37 if (previousScrollTop == testElement.scrollTop) { | |
| 38 // Ensure that the animation has really stopped, not that we just ha ve | |
| 39 // two frames that are so close together that the animation only see ms to | |
| 40 // have stopped. | |
| 41 if (timestamp - previousTimestamp > 16) { | |
| 42 touchTest.done(); | |
| 43 window.requestAnimationFrame(startWheelTest); | |
| 44 } else { | |
| 45 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfte rTouchScroll); | |
| 46 } | |
| 47 return; | |
| 48 } | |
| 49 | |
| 50 previousTimestamp = timestamp; | |
| 51 previousScrollTop = testElement.scrollTop; | |
| 52 touchTest.step(function() { | |
| 53 assert_not_equals(previousScrollTop, testCase.y2); | |
| 54 }); | |
| 55 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterTouchSc roll); | |
| 56 } | |
| 57 | |
| 58 function verifyScrollOffsetStopsChangingAfterWheelScroll(timestamp) | |
| 59 { | |
| 60 if (previousScrollTop == testElement.scrollTop) { | |
| 61 // Ensure that the animation has really stopped, not that we just ha ve | |
| 62 // two frames that are so close together that the animation only see ms to | |
| 63 // have stopped. | |
| 64 if (timestamp - previousTimestamp > 16) { | |
| 65 wheelTest.done(); | |
| 66 } else { | |
| 67 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfte rWheelScroll); | |
| 68 } | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 previousTimestamp = timestamp; | |
| 73 previousScrollTop = testElement.scrollTop; | |
| 74 wheelTest.step(function() { | |
| 75 assert_not_equals(previousScrollTop, testCase.y2); | |
| 76 }); | |
| 77 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterWheelSc roll); | |
| 78 } | |
| 79 | |
| 80 function interruptWithInstantScroll() | |
| 81 { | |
| 82 if (testElement.scrollTop == testCase.y1) { | |
| 83 window.requestAnimationFrame(interruptWithInstantScroll); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 instantlyScrollTo(testCase.y3); | |
| 88 instantTest.step(function() { | |
| 89 assert_equals(testElement.scrollTop, testCase.y3); | |
| 90 }); | |
| 91 window.requestAnimationFrame(verifyScrollOffsetUnchangedAfterInstantScro ll); | |
| 92 } | |
| 93 | |
| 94 function interruptWithSmoothScroll() | |
| 95 { | |
| 96 if (testElement.scrollTop == testCase.y1) { | |
| 97 window.requestAnimationFrame(interruptWithSmoothScroll); | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 previousScrollTop = testElement.scrollTop; | |
| 102 smoothlyScrollTo(testCase.y3); | |
| 103 smoothTest.step(function() { | |
| 104 assert_equals(testElement.scrollTop, previousScrollTop); | |
| 105 }); | |
| 106 window.requestAnimationFrame(verifyProgressTowardsNewDestination); | |
| 107 } | |
| 108 | |
| 109 function interruptWithTouchScroll(timestamp) | |
| 110 { | |
| 111 if (testElement.scrollTop == testCase.y1) { | |
| 112 window.requestAnimationFrame(interruptWithTouchScroll); | |
| 113 return; | |
| 114 } | |
| 115 | |
| 116 previousScrollTop = testElement.scrollTop; | |
| 117 previousTimestamp = timestamp; | |
| 118 if (window.eventSender) { | |
| 119 eventSender.gestureScrollBegin(testInnerPoint.x, testInnerPoint.y); | |
| 120 eventSender.gestureScrollUpdate(0, -10); | |
| 121 eventSender.gestureScrollEnd(0, 0); | |
| 122 } else { | |
| 123 document.write("This test does not work in manual mode."); | |
| 124 } | |
| 125 | |
| 126 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterTouchSc roll); | |
| 127 } | |
| 128 | |
| 129 function interruptWithWheelScroll(timestamp) | |
| 130 { | |
| 131 if (testElement.scrollTop == testCase.y1) { | |
| 132 window.requestAnimationFrame(interruptWithWheelScroll); | |
| 133 return; | |
| 134 } | |
| 135 | |
| 136 previousScrollTop = testElement.scrollTop; | |
| 137 previousTimestamp = timestamp; | |
| 138 if (window.eventSender) { | |
| 139 eventSender.mouseMoveTo(testInnerPoint.x, testInnerPoint.y); | |
| 140 eventSender.mouseScrollBy(0, -10); | |
| 141 } else { | |
| 142 document.write("This test does not work in manual mode."); | |
| 143 } | |
| 144 | |
| 145 window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterWheelSc roll); | |
| 146 } | |
| 147 | |
| 148 function smoothlyScrollTo(y) | |
| 149 { | |
| 150 testElement.style.scrollBehavior = "smooth"; | |
| 151 testElement.scrollTop = y; | |
| 152 } | |
| 153 | |
| 154 function instantlyScrollTo(y) | |
| 155 { | |
| 156 testElement.style.scrollBehavior = "instant"; | |
| 157 testElement.scrollTop = y; | |
| 158 } | |
| 159 | |
| 160 function startInstantTest() | |
| 161 { | |
| 162 instantlyScrollTo(testCase.y1); | |
| 163 smoothlyScrollTo(testCase.y2); | |
| 164 window.requestAnimationFrame(interruptWithInstantScroll); | |
| 165 } | |
| 166 | |
| 167 function startSmoothTest() | |
| 168 { | |
| 169 instantlyScrollTo(testCase.y1); | |
| 170 smoothlyScrollTo(testCase.y2); | |
| 171 window.requestAnimationFrame(interruptWithSmoothScroll); | |
| 172 } | |
| 173 | |
| 174 function startTouchTest() | |
| 175 { | |
| 176 instantlyScrollTo(testCase.y1); | |
| 177 smoothlyScrollTo(testCase.y2); | |
| 178 window.requestAnimationFrame(interruptWithTouchScroll); | |
| 179 } | |
| 180 | |
| 181 function startWheelTest() | |
| 182 { | |
| 183 instantlyScrollTo(testCase.y1); | |
| 184 smoothlyScrollTo(testCase.y2); | |
| 185 window.requestAnimationFrame(interruptWithWheelScroll); | |
| 186 } | |
| 187 | |
| 188 runScrollInterruptionTests = function runScrollInterruptionTests(element, | |
|
Ian Vollick
2014/02/06 16:02:31
Does this function need to be named?
| |
| 189 scrolls, | |
| 190 innerPoint) { | |
| 191 testElement = element; | |
| 192 testCase = scrolls; | |
| 193 testInnerPoint = innerPoint; | |
|
Ian Vollick
2014/02/06 16:02:31
It's a bit funky that startInstantTest does more t
| |
| 194 startInstantTest(); | |
| 195 } | |
| 196 })(); | |
| OLD | NEW |