OLD | NEW |
1 // This file contains the commonly used functions in pointerevent tests. | 1 // This file contains the commonly used functions in pointerevent tests. |
2 | 2 |
3 const scrollOffset = 30; | 3 const scrollOffset = 30; |
4 const boundaryOffset = 5; | 4 const boundaryOffset = 5; |
5 const touchSourceType = 1; | 5 const touchSourceType = 1; |
6 | 6 |
| 7 var xPosition = 0; |
| 8 var yPosition = 0; |
| 9 |
7 function delayPromise(delay) { | 10 function delayPromise(delay) { |
8 return new Promise(function(resolve, reject) { | 11 return new Promise(function(resolve, reject) { |
9 window.setTimeout(resolve, delay); | 12 window.setTimeout(resolve, delay); |
10 }); | 13 }); |
11 } | 14 } |
12 | 15 |
13 function scrollPageIfNeeded(targetSelector, targetDocument) { | 16 function scrollPageIfNeeded(targetSelector, targetDocument) { |
14 var target = targetDocument.querySelector(targetSelector); | 17 var target = targetDocument.querySelector(targetSelector); |
15 var targetRect = target.getBoundingClientRect(); | 18 var targetRect = target.getBoundingClientRect(); |
16 if (targetRect.top < 0 || targetRect.left < 0 || targetRect.bottom > window.in
nerHeight || targetRect.right > window.innerWidth) | 19 if (targetRect.top < 0 || targetRect.left < 0 || targetRect.bottom > window.in
nerHeight || targetRect.right > window.innerWidth) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 targetDocument = targetFrame.contentDocument; | 136 targetDocument = targetFrame.contentDocument; |
134 var frameRect = targetFrame.getBoundingClientRect(); | 137 var frameRect = targetFrame.getBoundingClientRect(); |
135 frameLeft = frameRect.left; | 138 frameLeft = frameRect.left; |
136 frameTop = frameRect.top; | 139 frameTop = frameRect.top; |
137 } | 140 } |
138 return new Promise(function(resolve, reject) { | 141 return new Promise(function(resolve, reject) { |
139 if (window.chrome && chrome.gpuBenchmarking) { | 142 if (window.chrome && chrome.gpuBenchmarking) { |
140 scrollPageIfNeeded(targetSelector, targetDocument); | 143 scrollPageIfNeeded(targetSelector, targetDocument); |
141 var target = targetDocument.querySelector(targetSelector); | 144 var target = targetDocument.querySelector(targetSelector); |
142 var targetRect = target.getBoundingClientRect(); | 145 var targetRect = target.getBoundingClientRect(); |
143 chrome.gpuBenchmarking.tap(frameLeft + targetRect.left + boundaryOffset, f
rameTop + targetRect.top + boundaryOffset, resolve); | 146 xPosition = frameLeft + targetRect.left + boundaryOffset; |
| 147 yPosition = frameTop + targetRect.top + boundaryOffset; |
| 148 chrome.gpuBenchmarking.pointerActionSequence( { |
| 149 "source": "touch", |
| 150 "pointer": [ |
| 151 { |
| 152 "id": 1, |
| 153 "actions": [ |
| 154 { "name": "pointerDown", "x": xPosition, "y": yPosition }, |
| 155 { "name": "pointerUp" } |
| 156 ] |
| 157 }]}, resolve); |
144 } else { | 158 } else { |
145 reject(); | 159 reject(); |
146 } | 160 } |
147 }); | 161 }); |
148 } | 162 } |
149 | 163 |
150 function touchScrollInTarget(targetSelector, direction) { | 164 function touchScrollInTarget(targetSelector, direction) { |
151 return new Promise(function(resolve, reject) { | 165 return new Promise(function(resolve, reject) { |
152 if (window.chrome && chrome.gpuBenchmarking) { | 166 if (window.chrome && chrome.gpuBenchmarking) { |
153 scrollPageIfNeeded(targetSelector, document); | 167 scrollPageIfNeeded(targetSelector, document); |
154 var target = document.querySelector(targetSelector); | 168 var target = document.querySelector(targetSelector); |
155 var targetRect = target.getBoundingClientRect(); | 169 var targetRect = target.getBoundingClientRect(); |
156 chrome.gpuBenchmarking.smoothScrollBy(scrollOffset, resolve, | 170 xPosition = targetRect.left + boundaryOffset; |
157 targetRect.left + boundaryOffset, targetRect.top + boundaryOffset, tou
chSourceType, direction); | 171 yPosition = targetRect.top + boundaryOffset; |
| 172 var newXPosition = xPosition; |
| 173 var newYPosition = yPosition; |
| 174 if (direction == "down") { |
| 175 newYPosition -= scrollOffset; |
| 176 } else if (direction == "up") { |
| 177 newYPosition += scrollOffset; |
| 178 } else if (direction == "right") { |
| 179 newXPosition -= scrollOffset; |
| 180 } else if (direction == "left") { |
| 181 newXPosition += scrollOffset; |
| 182 } else { |
| 183 return false; |
| 184 } |
| 185 chrome.gpuBenchmarking.pointerActionSequence( { |
| 186 "source": "touch", |
| 187 "pointer": [ |
| 188 { |
| 189 "id": 1, |
| 190 "actions": [ |
| 191 { "name": "pointerDown", "x": xPosition, "y": yPosition }, |
| 192 { "name": "pointerMove", "x": newXPosition, "y": newYPosition }, |
| 193 { "name": "pause" }, |
| 194 { "name": "pause" }, |
| 195 { "name": "pause" }, |
| 196 { "name": "pause" }, |
| 197 { "name": "pause" }, |
| 198 { "name": "pause" }, |
| 199 { "name": "pointerUp" } |
| 200 ] |
| 201 }]}, resolve); |
158 } else { | 202 } else { |
159 reject(); | 203 reject(); |
160 } | 204 } |
161 }); | 205 }); |
162 } | 206 } |
163 | 207 |
164 function pinchZoomInTarget(targetSelector, scale) { | 208 function pinchZoomInTarget(targetSelector, scale) { |
165 return new Promise(function(resolve, reject) { | 209 return new Promise(function(resolve, reject) { |
166 if (window.chrome && chrome.gpuBenchmarking) { | 210 if (window.chrome && chrome.gpuBenchmarking) { |
167 scrollPageIfNeeded(targetSelector, document); | 211 scrollPageIfNeeded(targetSelector, document); |
168 var target = document.querySelector(targetSelector); | 212 var target = document.querySelector(targetSelector); |
169 var targetRect = target.getBoundingClientRect(); | 213 var targetRect = target.getBoundingClientRect(); |
170 chrome.gpuBenchmarking.pinchBy(scale, targetRect.left + (targetRect.width/
2), targetRect.top + (targetRect.height/2), function() { | 214 xPosition = targetRect.left + (targetRect.width/2); |
171 resolve(); | 215 yPosition = targetRect.top + (targetRect.height/2); |
172 }); | 216 chrome.gpuBenchmarking.pointerActionSequence( { |
| 217 "source": "touch", |
| 218 "pointer": [ |
| 219 { |
| 220 "id": 1, |
| 221 "actions": [ |
| 222 { "name": "pointerDown", "x": xPosition, "y": yPosition - 10}, |
| 223 { "name": "pointerMove", "x": xPosition, "y": yPosition - 20}, |
| 224 { "name": "pointerMove", "x": xPosition, "y": yPosition - 30}, |
| 225 { "name": "pointerMove", "x": xPosition, "y": yPosition - 40}, |
| 226 { "name": "pointerMove", "x": xPosition, "y": yPosition - 50}, |
| 227 { "name": "pointerMove", "x": xPosition, "y": yPosition - 60}, |
| 228 { "name": "pointerMove", "x": xPosition, "y": yPosition - 70}, |
| 229 { "name": "pointerMove", "x": xPosition, "y": yPosition - 80}, |
| 230 { "name": "pointerUp" } |
| 231 ] |
| 232 }, { |
| 233 "id": 2, |
| 234 "actions": [ |
| 235 { "name": "pointerDown", "x": xPosition, "y": yPosition + 10}, |
| 236 { "name": "pointerMove", "x": xPosition, "y": yPosition + 20}, |
| 237 { "name": "pointerMove", "x": xPosition, "y": yPosition + 30}, |
| 238 { "name": "pointerMove", "x": xPosition, "y": yPosition + 40}, |
| 239 { "name": "pointerMove", "x": xPosition, "y": yPosition + 50}, |
| 240 { "name": "pointerMove", "x": xPosition, "y": yPosition + 60}, |
| 241 { "name": "pointerMove", "x": xPosition, "y": yPosition + 70}, |
| 242 { "name": "pointerMove", "x": xPosition, "y": yPosition + 80}, |
| 243 { "name": "pointerUp" } |
| 244 ] |
| 245 }]}, resolve); |
173 } else { | 246 } else { |
174 reject(); | 247 reject(); |
175 } | 248 } |
176 }); | 249 }); |
177 } | 250 } |
178 | 251 |
179 // Pen inputs. | 252 // Pen inputs. |
180 function penMoveToDocument() { | 253 function penMoveToDocument() { |
181 return new Promise(function(resolve, reject) { | 254 return new Promise(function(resolve, reject) { |
182 if (window.eventSender) { | 255 if (window.eventSender) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 315 } |
243 | 316 |
244 { | 317 { |
245 var pointerevent_automation = async_test("PointerEvent Automation"); | 318 var pointerevent_automation = async_test("PointerEvent Automation"); |
246 // Defined in every test and should return a promise that gets resolved when i
nput is finished. | 319 // Defined in every test and should return a promise that gets resolved when i
nput is finished. |
247 inject_input().then(function() { | 320 inject_input().then(function() { |
248 pointerevent_automation.done(); | 321 pointerevent_automation.done(); |
249 }); | 322 }); |
250 } | 323 } |
251 | 324 |
OLD | NEW |