scrollend-user-scroll-common.js (4788B)
1 async function test_scrollend_on_touch_drag(t, target_div) { 2 // Skip the test on a Mac as they do not support touch screens. 3 const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; 4 if (isMac) 5 return; 6 7 await resetTargetScrollState(t, target_div); 8 await waitForCompositorReady(); 9 10 const targetScrollendPromise = waitForScrollendEventNoTimeout(target_div); 11 verifyNoScrollendOnDocument(t); 12 13 let scrollend_count = 0; 14 const scrollend_listener = () => { 15 scrollend_count += 1; 16 }; 17 target_div.addEventListener("scrollend", scrollend_listener); 18 t.add_cleanup(() => { 19 target_div.removeEventListener('scrollend', scrollend_listener); 20 }); 21 22 // Perform a touch drag on target div and wait for target_div to get 23 // a scrollend event. 24 await new test_driver.Actions() 25 .addPointer('TestPointer', 'touch') 26 .pointerMove(0, 0, { origin: target_div }) // 0, 0 is center of element. 27 .pointerDown() 28 .addTick() 29 .pointerMove(0, -40, { origin: target_div }) // Drag up to move down. 30 .addTick() 31 .pause(200) // Prevent inertial scroll. 32 .pointerMove(0, -60, { origin: target_div }) 33 .addTick() 34 .pause(200) // Prevent inertial scroll. 35 .pointerUp() 36 .send(); 37 38 await targetScrollendPromise; 39 40 assert_true(target_div.scrollTop > 0); 41 await verifyScrollStopped(t, target_div); 42 assert_equals(scrollend_count, 1); 43 } 44 45 async function test_scrollend_on_scrollbar_gutter_click(t, target_div) { 46 // Skip test on platforms that do not have a visible scrollbar (e.g. 47 // overlay scrollbar). 48 const scrollbar_width = target_div.offsetWidth - target_div.clientWidth; 49 if (scrollbar_width == 0) 50 return; 51 52 await resetTargetScrollState(t, target_div); 53 await waitForCompositorReady(); 54 55 const targetScrollendPromise = waitForScrollendEventNoTimeout(target_div); 56 verifyNoScrollendOnDocument(t); 57 58 const bounds = target_div.getBoundingClientRect(); 59 // Some versions of webdriver have been known to frown at non-int arguments 60 // to pointerMove. 61 const x = Math.round(bounds.right - scrollbar_width / 2); 62 const y = Math.round(bounds.bottom - 20); 63 await new test_driver.Actions() 64 .addPointer('TestPointer', 'mouse') 65 .pointerMove(x, y, { origin: 'viewport' }) 66 .pointerDown() 67 .addTick() 68 .pointerUp() 69 .send(); 70 71 await targetScrollendPromise; 72 assert_true(target_div.scrollTop > 0); 73 await verifyScrollStopped(t, target_div); 74 } 75 76 // Same issue as previous test. 77 async function test_scrollend_on_scrollbar_thumb_drag(t, target_div) { 78 // Skip test on platforms that do not have a visible scrollbar (e.g. 79 // overlay scrollbar). 80 const scrollbar_width = target_div.offsetWidth - target_div.clientWidth; 81 if (scrollbar_width == 0) 82 return; 83 84 await resetTargetScrollState(t, target_div); 85 await waitForCompositorReady(); 86 87 const targetScrollendPromise = waitForScrollendEventNoTimeout(target_div); 88 verifyNoScrollendOnDocument(t); 89 90 const bounds = target_div.getBoundingClientRect(); 91 // Some versions of webdriver have been known to frown at non-int arguments 92 // to pointerMove. 93 const x = Math.round(bounds.right - scrollbar_width / 2); 94 const y = Math.round(bounds.top + 30); 95 const dy = 30; 96 await new test_driver.Actions() 97 .addPointer('TestPointer', 'mouse') 98 .pointerMove(x, y, { origin: 'viewport' }) 99 .pointerDown() 100 .pointerMove(x, y + dy, { origin: 'viewport' }) 101 .addTick() 102 .pointerUp() 103 .send(); 104 105 await targetScrollendPromise; 106 assert_true(target_div.scrollTop > 0); 107 await verifyScrollStopped(t, target_div); 108 } 109 110 async function test_scrollend_on_mousewheel_scroll(t, target_div, frame) { 111 await resetTargetScrollState(t, target_div); 112 await waitForCompositorReady(); 113 114 const targetScrollendPromise = waitForScrollendEventNoTimeout(target_div); 115 verifyNoScrollendOnDocument(t); 116 117 let scroll_origin = target_div; 118 if (frame) { 119 // chromedriver doesn't support passing { origin: element } 120 // for an element within a subframe. Use the frame element itself. 121 scroll_origin = frame; 122 } 123 const x = 0; 124 const y = 0; 125 const dx = 0; 126 const dy = 40; 127 await new test_driver.Actions() 128 .scroll(x, y, dx, dy, { origin: scroll_origin }) 129 .send(); 130 131 await targetScrollendPromise; 132 assert_true(target_div.scrollTop > 0); 133 await verifyScrollStopped(t, target_div); 134 } 135 136 async function test_scrollend_on_keyboard_scroll(t, target_div) { 137 await resetTargetScrollState(t, target_div); 138 await waitForCompositorReady(); 139 140 verifyNoScrollendOnDocument(t); 141 const targetScrollendPromise = waitForScrollendEventNoTimeout(target_div); 142 143 target_div.focus(); 144 window.test_driver.send_keys(target_div, '\ue015'); 145 146 await targetScrollendPromise; 147 assert_true(target_div.scrollTop > 0); 148 await verifyScrollStopped(t, target_div); 149 }