touch_action_helpers.js (8088B)
1 // Some common helpers 2 3 function promiseTimeout(delay) { 4 return new Promise(resolve => { 5 setTimeout(resolve, delay); 6 }); 7 } 8 9 function promiseTouchStart(element) { 10 return new Promise(resolve => { 11 element.addEventListener("touchstart", resolve, { 12 passive: true, 13 once: true, 14 }); 15 }); 16 } 17 18 async function touchScrollRight(aSelector = "#target0", aX = 20, aY = 20) { 19 const target = document.querySelector(aSelector); 20 const touchStartPromise = promiseTouchStart(document.body); 21 const touchEndPromise = promiseTouchEnd(document.body); 22 dump("Synthesizing horizontal drag\n"); 23 await promiseNativePointerDrag(target, "touch", aX + 40, aY, -40, 0); 24 await touchStartPromise; 25 dump("Got touchstart from the horizontal drag\n"); 26 await touchEndPromise; 27 dump("Got touchend from the horizontal drag\n"); 28 } 29 30 async function touchScrollDown(aSelector = "#target0", aX = 20, aY = 20) { 31 const target = document.querySelector(aSelector); 32 const touchStartPromise = promiseTouchStart(document.body); 33 const touchEndPromise = promiseTouchEnd(document.body); 34 dump("Synthesizing vertical drag\n"); 35 await promiseNativePointerDrag(target, "touch", aX, aY + 40, 0, -40); 36 await touchStartPromise; 37 dump("Got touchstart from the vertical drag\n"); 38 await touchEndPromise; 39 dump("Got touchend from the vertical drag\n"); 40 } 41 42 async function tapCompleteAndWaitTestDone() { 43 let testDone = new Promise(resolve => { 44 add_completion_callback(resolve); 45 }); 46 47 var button = document.getElementById("btnComplete"); 48 button.click(); 49 await testDone; 50 } 51 52 function promiseResetScrollLeft(aSelector = "#target0") { 53 var target = document.querySelector(aSelector); 54 return new Promise(resolve => { 55 target.addEventListener("scroll", function onScroll() { 56 if (target.scrollLeft == 0) { 57 target.removeEventListener("scroll", onScroll); 58 resolve(); 59 } 60 }); 61 }); 62 } 63 64 // The main body functions to simulate the input events required for the named test 65 66 async function pointerevent_touch_action_auto_css_touch_manual() { 67 let testDone = new Promise(resolve => { 68 add_completion_callback(resolve); 69 }); 70 71 await touchScrollRight(); 72 await promiseApzFlushedRepaints(); 73 await touchScrollDown(); 74 await testDone; 75 } 76 77 async function pointerevent_touch_action_button_test_touch_manual() { 78 await touchScrollDown(); 79 await promiseApzFlushedRepaints(); 80 await promiseTimeout(2 * scrollReturnInterval); 81 await touchScrollRight(); 82 let resetScrollLeftPromise = promiseResetScrollLeft(); 83 await promiseApzFlushedRepaints(); 84 await promiseTimeout(2 * scrollReturnInterval); 85 // Wait for resetting target0's scrollLeft to avoid the reset break the 86 // following scroll behaviors. 87 await resetScrollLeftPromise; 88 await touchScrollDown("#target0 > button"); 89 await promiseApzFlushedRepaints(); 90 await touchScrollRight("#target0 > button"); 91 await promiseApzFlushedRepaints(); 92 await tapCompleteAndWaitTestDone(); 93 } 94 95 async function pointerevent_touch_action_inherit_child_auto_child_none_touch_manual() { 96 await touchScrollDown("#target0 > div div"); 97 await promiseApzFlushedRepaints(); 98 await touchScrollRight("#target0 > div div"); 99 await promiseApzFlushedRepaints(); 100 await tapCompleteAndWaitTestDone(); 101 } 102 103 async function pointerevent_touch_action_inherit_child_none_touch_manual() { 104 await touchScrollDown("#target0 > div"); 105 await promiseApzFlushedRepaints(); 106 await touchScrollRight("#target0 > div"); 107 await promiseApzFlushedRepaints(); 108 await tapCompleteAndWaitTestDone(); 109 } 110 111 async function pointerevent_touch_action_inherit_child_pan_x_child_pan_x_touch_manual() { 112 await touchScrollDown("#target0 > div div"); 113 await promiseApzFlushedRepaints(); 114 await touchScrollRight("#target0 > div div"); 115 await promiseApzFlushedRepaints(); 116 await tapCompleteAndWaitTestDone(); 117 } 118 119 async function pointerevent_touch_action_inherit_child_pan_x_child_pan_y_touch_manual() { 120 await touchScrollDown("#target0 > div div"); 121 await promiseApzFlushedRepaints(); 122 await touchScrollRight("#target0 > div div"); 123 await promiseApzFlushedRepaints(); 124 await tapCompleteAndWaitTestDone(); 125 } 126 127 async function pointerevent_touch_action_inherit_highest_parent_none_touch_manual() { 128 let testDone = new Promise(resolve => { 129 add_completion_callback(resolve); 130 }); 131 132 await touchScrollDown("#target0 > div"); 133 await promiseApzFlushedRepaints(); 134 await touchScrollRight("#target0 > div"); 135 await testDone; 136 } 137 138 async function pointerevent_touch_action_inherit_parent_none_touch_manual() { 139 await touchScrollDown(); 140 await promiseApzFlushedRepaints(); 141 await touchScrollRight(); 142 await promiseApzFlushedRepaints(); 143 await tapCompleteAndWaitTestDone(); 144 } 145 146 async function pointerevent_touch_action_none_css_touch_manual() { 147 await touchScrollDown(); 148 await promiseApzFlushedRepaints(); 149 await touchScrollRight(); 150 await promiseApzFlushedRepaints(); 151 await tapCompleteAndWaitTestDone(); 152 } 153 154 async function pointerevent_touch_action_pan_x_css_touch_manual() { 155 await touchScrollDown(); 156 await promiseApzFlushedRepaints(); 157 await touchScrollRight(); 158 await promiseApzFlushedRepaints(); 159 await tapCompleteAndWaitTestDone(); 160 } 161 162 async function pointerevent_touch_action_pan_x_pan_y_pan_y_touch_manual() { 163 await touchScrollDown("#target0 > div div"); 164 await promiseApzFlushedRepaints(); 165 await touchScrollRight("#target0 > div div"); 166 await promiseApzFlushedRepaints(); 167 await tapCompleteAndWaitTestDone(); 168 } 169 170 async function pointerevent_touch_action_pan_x_pan_y_touch_manual() { 171 let testDone = new Promise(resolve => { 172 add_completion_callback(resolve); 173 }); 174 175 await touchScrollDown(); 176 await promiseApzFlushedRepaints(); 177 await touchScrollRight(); 178 await testDone; 179 } 180 181 async function pointerevent_touch_action_pan_y_css_touch_manual() { 182 await touchScrollDown(); 183 await promiseApzFlushedRepaints(); 184 await touchScrollRight(); 185 await promiseApzFlushedRepaints(); 186 await tapCompleteAndWaitTestDone(); 187 } 188 189 async function pointerevent_touch_action_span_test_touch_manual() { 190 await touchScrollDown(); 191 await promiseApzFlushedRepaints(); 192 await promiseTimeout(2 * scrollReturnInterval); 193 await touchScrollRight(); 194 let resetScrollLeftPromise = promiseResetScrollLeft(); 195 await promiseApzFlushedRepaints(); 196 await promiseTimeout(2 * scrollReturnInterval); 197 // Wait for resetting target0's scrollLeft to avoid the reset break the 198 // following scroll behaviors. 199 await resetScrollLeftPromise; 200 await touchScrollDown("#testspan"); 201 await promiseApzFlushedRepaints(); 202 await touchScrollRight("#testspan"); 203 await promiseApzFlushedRepaints(); 204 await tapCompleteAndWaitTestDone(); 205 } 206 207 async function pointerevent_touch_action_svg_test_touch_manual() { 208 await touchScrollDown(); 209 await promiseApzFlushedRepaints(); 210 await promiseTimeout(2 * scrollReturnInterval); 211 await touchScrollRight(); 212 await promiseApzFlushedRepaints(); 213 await promiseTimeout(2 * scrollReturnInterval); 214 await touchScrollDown("#target0", 250, 250); 215 await promiseApzFlushedRepaints(); 216 await touchScrollRight("#target0", 250, 250); 217 await promiseApzFlushedRepaints(); 218 await tapCompleteAndWaitTestDone(); 219 } 220 221 async function pointerevent_touch_action_table_test_touch_manual() { 222 await touchScrollDown("#row1"); 223 await promiseApzFlushedRepaints(); 224 await promiseTimeout(2 * scrollReturnInterval); 225 await touchScrollRight("#row1"); 226 let resetScrollLeftPromise = promiseResetScrollLeft(); 227 await promiseApzFlushedRepaints(); 228 await promiseTimeout(2 * scrollReturnInterval); 229 // Wait for resetting target0's scrollLeft to avoid the reset break the 230 // following scroll behaviors. 231 await resetScrollLeftPromise; 232 await touchScrollDown("#cell3"); 233 await promiseApzFlushedRepaints(); 234 await touchScrollRight("#cell3"); 235 await promiseApzFlushedRepaints(); 236 await tapCompleteAndWaitTestDone(); 237 } 238 239 // This the stuff that runs the appropriate body function above 240 241 // eslint-disable-next-line no-eval 242 var test = eval(_ACTIVE_TEST_NAME.replace(/-/g, "_")); 243 waitUntilApzStable().then(test).then(subtestDone, subtestFailed);