OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import time | 5 import time |
6 | 6 |
7 from telemetry.page.actions.javascript_click import ClickElementAction | 7 from telemetry.page.actions.javascript_click import ClickElementAction |
8 from telemetry.page.actions.loop import LoopAction | 8 from telemetry.page.actions.loop import LoopAction |
9 from telemetry.page.actions.navigate import NavigateAction | 9 from telemetry.page.actions.navigate import NavigateAction |
10 from telemetry.page.actions.pinch import PinchAction | 10 from telemetry.page.actions.pinch import PinchAction |
11 from telemetry.page.actions.play import PlayAction | 11 from telemetry.page.actions.play import PlayAction |
12 from telemetry.page.actions.repaint_continuously import ( | 12 from telemetry.page.actions.repaint_continuously import ( |
13 RepaintContinuouslyAction) | 13 RepaintContinuouslyAction) |
14 from telemetry.page.actions.scroll import ScrollAction | 14 from telemetry.page.actions.scroll import ScrollAction |
15 from telemetry.page.actions.scroll_bounce import ScrollBounceAction | 15 from telemetry.page.actions.scroll_bounce import ScrollBounceAction |
16 from telemetry.page.actions.seek import SeekAction | 16 from telemetry.page.actions.seek import SeekAction |
17 from telemetry.page.actions.swipe import SwipeAction | 17 from telemetry.page.actions.swipe import SwipeAction |
18 from telemetry.page.actions.tap import TapAction | 18 from telemetry.page.actions.tap import TapAction |
19 from telemetry.page.actions.wait import WaitForElementAction | 19 from telemetry.page.actions.wait import WaitForElementAction |
20 from telemetry.web_perf import timeline_interaction_record as tir_module | 20 from telemetry.web_perf import timeline_interaction_record as tir_module |
21 | 21 |
22 | 22 |
23 class ActionRunner(object): | 23 class ActionRunner(object): |
24 | 24 |
25 def __init__(self, tab): | 25 def __init__(self, tab): |
26 self._tab = tab | 26 self._tab = tab |
27 | 27 |
28 # TODO(nednguyen): remove this (or make private) when | 28 def _RunAction(self, action): |
29 # crbug.com/361809 is marked fixed | |
30 def RunAction(self, action): | |
31 action.WillRunAction(self._tab) | 29 action.WillRunAction(self._tab) |
32 action.RunAction(self._tab) | 30 action.RunAction(self._tab) |
33 | 31 |
34 def BeginInteraction(self, label, is_smooth=False, is_responsive=False): | 32 def BeginInteraction(self, label, is_smooth=False, is_responsive=False): |
35 """Marks the beginning of an interaction record. | 33 """Marks the beginning of an interaction record. |
36 | 34 |
37 An interaction record is a labeled time period containing | 35 An interaction record is a labeled time period containing |
38 interaction that developers care about. Each set of metrics | 36 interaction that developers care about. Each set of metrics |
39 specified in flags will be calculated for this time period.. The | 37 specified in flags will be calculated for this time period.. The |
40 End() method in the returned object must be called once to mark | 38 End() method in the returned object must be called once to mark |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 """Navigate to the given page. | 80 """Navigate to the given page. |
83 | 81 |
84 Args: | 82 Args: |
85 page: page is an instance of page.Page | 83 page: page is an instance of page.Page |
86 timeout_in_seconds: The timeout in seconds (default to 60). | 84 timeout_in_seconds: The timeout in seconds (default to 60). |
87 """ | 85 """ |
88 if page.is_file: | 86 if page.is_file: |
89 target_side_url = self._tab.browser.http_server.UrlOf(page.file_path_url) | 87 target_side_url = self._tab.browser.http_server.UrlOf(page.file_path_url) |
90 else: | 88 else: |
91 target_side_url = page.url | 89 target_side_url = page.url |
92 self.RunAction(NavigateAction( | 90 self._RunAction(NavigateAction( |
93 url=target_side_url, | 91 url=target_side_url, |
94 script_to_evaluate_on_commit=page.script_to_evaluate_on_commit, | 92 script_to_evaluate_on_commit=page.script_to_evaluate_on_commit, |
95 timeout_in_seconds=timeout_in_seconds)) | 93 timeout_in_seconds=timeout_in_seconds)) |
96 | 94 |
97 def WaitForNavigate(self, timeout_in_seconds_seconds=60): | 95 def WaitForNavigate(self, timeout_in_seconds_seconds=60): |
98 self._tab.WaitForNavigate(timeout_in_seconds_seconds) | 96 self._tab.WaitForNavigate(timeout_in_seconds_seconds) |
99 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | 97 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
100 | 98 |
101 def ReloadPage(self): | 99 def ReloadPage(self): |
102 """Reloads the page.""" | 100 """Reloads the page.""" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 Only one of these arguments must be specified. | 158 Only one of these arguments must be specified. |
161 | 159 |
162 Args: | 160 Args: |
163 selector: A CSS selector describing the element. | 161 selector: A CSS selector describing the element. |
164 text: The element must contains this exact text. | 162 text: The element must contains this exact text. |
165 element_function: A JavaScript function (as string) that is used | 163 element_function: A JavaScript function (as string) that is used |
166 to retrieve the element. For example: | 164 to retrieve the element. For example: |
167 '(function() { return foo.element; })()'. | 165 '(function() { return foo.element; })()'. |
168 timeout_in_seconds: The timeout in seconds (default to 60). | 166 timeout_in_seconds: The timeout in seconds (default to 60). |
169 """ | 167 """ |
170 self.RunAction(WaitForElementAction( | 168 self._RunAction(WaitForElementAction( |
171 selector=selector, text=text, element_function=element_function, | 169 selector=selector, text=text, element_function=element_function, |
172 timeout_in_seconds=timeout_in_seconds)) | 170 timeout_in_seconds=timeout_in_seconds)) |
173 | 171 |
174 def TapElement(self, selector=None, text=None, element_function=None): | 172 def TapElement(self, selector=None, text=None, element_function=None): |
175 """Tap an element. | 173 """Tap an element. |
176 | 174 |
177 The element may be selected via selector, text, or element_function. | 175 The element may be selected via selector, text, or element_function. |
178 Only one of these arguments must be specified. | 176 Only one of these arguments must be specified. |
179 | 177 |
180 Args: | 178 Args: |
181 selector: A CSS selector describing the element. | 179 selector: A CSS selector describing the element. |
182 text: The element must contains this exact text. | 180 text: The element must contains this exact text. |
183 element_function: A JavaScript function (as string) that is used | 181 element_function: A JavaScript function (as string) that is used |
184 to retrieve the element. For example: | 182 to retrieve the element. For example: |
185 '(function() { return foo.element; })()'. | 183 '(function() { return foo.element; })()'. |
186 """ | 184 """ |
187 self.RunAction(TapAction( | 185 self._RunAction(TapAction( |
188 selector=selector, text=text, element_function=element_function)) | 186 selector=selector, text=text, element_function=element_function)) |
189 | 187 |
190 def ClickElement(self, selector=None, text=None, element_function=None): | 188 def ClickElement(self, selector=None, text=None, element_function=None): |
191 """Click an element. | 189 """Click an element. |
192 | 190 |
193 The element may be selected via selector, text, or element_function. | 191 The element may be selected via selector, text, or element_function. |
194 Only one of these arguments must be specified. | 192 Only one of these arguments must be specified. |
195 | 193 |
196 Args: | 194 Args: |
197 selector: A CSS selector describing the element. | 195 selector: A CSS selector describing the element. |
198 text: The element must contains this exact text. | 196 text: The element must contains this exact text. |
199 element_function: A JavaScript function (as string) that is used | 197 element_function: A JavaScript function (as string) that is used |
200 to retrieve the element. For example: | 198 to retrieve the element. For example: |
201 '(function() { return foo.element; })()'. | 199 '(function() { return foo.element; })()'. |
202 """ | 200 """ |
203 self.RunAction(ClickElementAction( | 201 self._RunAction(ClickElementAction( |
204 selector=selector, text=text, element_function=element_function)) | 202 selector=selector, text=text, element_function=element_function)) |
205 | 203 |
206 def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5, | 204 def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5, |
207 scale_factor=None, speed_in_pixels_per_second=800): | 205 scale_factor=None, speed_in_pixels_per_second=800): |
208 """Perform the pinch gesture on the page. | 206 """Perform the pinch gesture on the page. |
209 | 207 |
210 It computes the pinch gesture automatically based on the anchor | 208 It computes the pinch gesture automatically based on the anchor |
211 coordinate and the scale factor. The scale factor is the ratio of | 209 coordinate and the scale factor. The scale factor is the ratio of |
212 of the final span and the initial span of the gesture. | 210 of the final span and the initial span of the gesture. |
213 | 211 |
214 Args: | 212 Args: |
215 left_anchor_ratio: The horizontal pinch anchor coordinate of the | 213 left_anchor_ratio: The horizontal pinch anchor coordinate of the |
216 gesture, as a ratio of the visible bounding rectangle for | 214 gesture, as a ratio of the visible bounding rectangle for |
217 document.body. | 215 document.body. |
218 top_anchor_ratio: The vertical pinch anchor coordinate of the | 216 top_anchor_ratio: The vertical pinch anchor coordinate of the |
219 gesture, as a ratio of the visible bounding rectangle for | 217 gesture, as a ratio of the visible bounding rectangle for |
220 document.body. | 218 document.body. |
221 scale_factor: The ratio of the final span to the initial span. | 219 scale_factor: The ratio of the final span to the initial span. |
222 The default scale factor is | 220 The default scale factor is |
223 3.0 / (window.outerWidth/window.innerWidth). | 221 3.0 / (window.outerWidth/window.innerWidth). |
224 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 222 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
225 """ | 223 """ |
226 self.RunAction(PinchAction( | 224 self._RunAction(PinchAction( |
227 left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio, | 225 left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio, |
228 scale_factor=scale_factor, | 226 scale_factor=scale_factor, |
229 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 227 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
230 | 228 |
231 def PinchElement(self, selector=None, text=None, element_function=None, | 229 def PinchElement(self, selector=None, text=None, element_function=None, |
232 left_anchor_ratio=0.5, top_anchor_ratio=0.5, | 230 left_anchor_ratio=0.5, top_anchor_ratio=0.5, |
233 scale_factor=None, speed_in_pixels_per_second=800): | 231 scale_factor=None, speed_in_pixels_per_second=800): |
234 """Perform the pinch gesture on an element. | 232 """Perform the pinch gesture on an element. |
235 | 233 |
236 It computes the pinch gesture automatically based on the anchor | 234 It computes the pinch gesture automatically based on the anchor |
(...skipping 10 matching lines...) Expand all Loading... |
247 gesture, as a ratio of the visible bounding rectangle for | 245 gesture, as a ratio of the visible bounding rectangle for |
248 the element. | 246 the element. |
249 top_anchor_ratio: The vertical pinch anchor coordinate of the | 247 top_anchor_ratio: The vertical pinch anchor coordinate of the |
250 gesture, as a ratio of the visible bounding rectangle for | 248 gesture, as a ratio of the visible bounding rectangle for |
251 the element. | 249 the element. |
252 scale_factor: The ratio of the final span to the initial span. | 250 scale_factor: The ratio of the final span to the initial span. |
253 The default scale factor is | 251 The default scale factor is |
254 3.0 / (window.outerWidth/window.innerWidth). | 252 3.0 / (window.outerWidth/window.innerWidth). |
255 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 253 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
256 """ | 254 """ |
257 self.RunAction(PinchAction( | 255 self._RunAction(PinchAction( |
258 selector=selector, text=text, element_function=element_function, | 256 selector=selector, text=text, element_function=element_function, |
259 left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio, | 257 left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio, |
260 scale_factor=scale_factor, | 258 scale_factor=scale_factor, |
261 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 259 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
262 | 260 |
263 def ScrollPage(self, left_start_ratio=0.5, top_start_ratio=0.5, | 261 def ScrollPage(self, left_start_ratio=0.5, top_start_ratio=0.5, |
264 direction='down', distance=None, distance_expr=None, | 262 direction='down', distance=None, distance_expr=None, |
265 speed_in_pixels_per_second=800, use_touch=False): | 263 speed_in_pixels_per_second=800, use_touch=False): |
266 """Perform scroll gesture on the page. | 264 """Perform scroll gesture on the page. |
267 | 265 |
(...skipping 10 matching lines...) Expand all Loading... |
278 document.body. | 276 document.body. |
279 direction: The direction of scroll, either 'left', 'right', | 277 direction: The direction of scroll, either 'left', 'right', |
280 'up', or 'down' | 278 'up', or 'down' |
281 distance: The distance to scroll (in pixel). | 279 distance: The distance to scroll (in pixel). |
282 distance_expr: A JavaScript expression (as string) that can be | 280 distance_expr: A JavaScript expression (as string) that can be |
283 evaluated to compute scroll distance. Example: | 281 evaluated to compute scroll distance. Example: |
284 'window.scrollTop' or '(function() { return crazyMath(); })()'. | 282 'window.scrollTop' or '(function() { return crazyMath(); })()'. |
285 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 283 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
286 use_touch: Whether scrolling should be done with touch input. | 284 use_touch: Whether scrolling should be done with touch input. |
287 """ | 285 """ |
288 self.RunAction(ScrollAction( | 286 self._RunAction(ScrollAction( |
289 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 287 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
290 direction=direction, distance=distance, distance_expr=distance_expr, | 288 direction=direction, distance=distance, distance_expr=distance_expr, |
291 speed_in_pixels_per_second=speed_in_pixels_per_second, | 289 speed_in_pixels_per_second=speed_in_pixels_per_second, |
292 use_touch=use_touch)) | 290 use_touch=use_touch)) |
293 | 291 |
294 def ScrollElement(self, selector=None, text=None, element_function=None, | 292 def ScrollElement(self, selector=None, text=None, element_function=None, |
295 left_start_ratio=0.5, top_start_ratio=0.5, | 293 left_start_ratio=0.5, top_start_ratio=0.5, |
296 direction='down', distance=None, distance_expr=None, | 294 direction='down', distance=None, distance_expr=None, |
297 speed_in_pixels_per_second=800, use_touch=False): | 295 speed_in_pixels_per_second=800, use_touch=False): |
298 """Perform scroll gesture on the element. | 296 """Perform scroll gesture on the element. |
(...skipping 19 matching lines...) Expand all Loading... |
318 the element. | 316 the element. |
319 direction: The direction of scroll, either 'left', 'right', | 317 direction: The direction of scroll, either 'left', 'right', |
320 'up', or 'down' | 318 'up', or 'down' |
321 distance: The distance to scroll (in pixel). | 319 distance: The distance to scroll (in pixel). |
322 distance_expr: A JavaScript expression (as string) that can be | 320 distance_expr: A JavaScript expression (as string) that can be |
323 evaluated to compute scroll distance. Example: | 321 evaluated to compute scroll distance. Example: |
324 'window.scrollTop' or '(function() { return crazyMath(); })()'. | 322 'window.scrollTop' or '(function() { return crazyMath(); })()'. |
325 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 323 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
326 use_touch: Whether scrolling should be done with touch input. | 324 use_touch: Whether scrolling should be done with touch input. |
327 """ | 325 """ |
328 self.RunAction(ScrollAction( | 326 self._RunAction(ScrollAction( |
329 selector=selector, text=text, element_function=element_function, | 327 selector=selector, text=text, element_function=element_function, |
330 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 328 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
331 direction=direction, distance=distance, distance_expr=distance_expr, | 329 direction=direction, distance=distance, distance_expr=distance_expr, |
332 speed_in_pixels_per_second=speed_in_pixels_per_second, | 330 speed_in_pixels_per_second=speed_in_pixels_per_second, |
333 use_touch=use_touch)) | 331 use_touch=use_touch)) |
334 | 332 |
335 def ScrollBouncePage(self, left_start_ratio=0.5, top_start_ratio=0.5, | 333 def ScrollBouncePage(self, left_start_ratio=0.5, top_start_ratio=0.5, |
336 direction='down', distance=100, | 334 direction='down', distance=100, |
337 overscroll=10, repeat_count=10, | 335 overscroll=10, repeat_count=10, |
338 speed_in_pixels_per_second=400): | 336 speed_in_pixels_per_second=400): |
(...skipping 12 matching lines...) Expand all Loading... |
351 gesture, as a ratio of the visible bounding rectangle for | 349 gesture, as a ratio of the visible bounding rectangle for |
352 document.body. | 350 document.body. |
353 direction: The direction of scroll, either 'left', 'right', | 351 direction: The direction of scroll, either 'left', 'right', |
354 'up', or 'down' | 352 'up', or 'down' |
355 distance: The distance to scroll (in pixel). | 353 distance: The distance to scroll (in pixel). |
356 overscroll: The number of additional pixels to scroll back, in | 354 overscroll: The number of additional pixels to scroll back, in |
357 addition to the givendistance. | 355 addition to the givendistance. |
358 repeat_count: How often we want to repeat the full gesture. | 356 repeat_count: How often we want to repeat the full gesture. |
359 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 357 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
360 """ | 358 """ |
361 self.RunAction(ScrollBounceAction( | 359 self._RunAction(ScrollBounceAction( |
362 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 360 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
363 direction=direction, distance=distance, | 361 direction=direction, distance=distance, |
364 overscroll=overscroll, repeat_count=repeat_count, | 362 overscroll=overscroll, repeat_count=repeat_count, |
365 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 363 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
366 | 364 |
367 def ScrollBounceElement(self, selector=None, text=None, element_function=None, | 365 def ScrollBounceElement(self, selector=None, text=None, element_function=None, |
368 left_start_ratio=0.5, top_start_ratio=0.5, | 366 left_start_ratio=0.5, top_start_ratio=0.5, |
369 direction='down', distance=100, | 367 direction='down', distance=100, |
370 overscroll=10, repeat_count=10, | 368 overscroll=10, repeat_count=10, |
371 speed_in_pixels_per_second=400): | 369 speed_in_pixels_per_second=400): |
(...skipping 17 matching lines...) Expand all Loading... |
389 gesture, as a ratio of the visible bounding rectangle for | 387 gesture, as a ratio of the visible bounding rectangle for |
390 document.body. | 388 document.body. |
391 direction: The direction of scroll, either 'left', 'right', | 389 direction: The direction of scroll, either 'left', 'right', |
392 'up', or 'down' | 390 'up', or 'down' |
393 distance: The distance to scroll (in pixel). | 391 distance: The distance to scroll (in pixel). |
394 overscroll: The number of additional pixels to scroll back, in | 392 overscroll: The number of additional pixels to scroll back, in |
395 addition to the givendistance. | 393 addition to the givendistance. |
396 repeat_count: How often we want to repeat the full gesture. | 394 repeat_count: How often we want to repeat the full gesture. |
397 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 395 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
398 """ | 396 """ |
399 self.RunAction(ScrollBounceAction( | 397 self._RunAction(ScrollBounceAction( |
400 selector=selector, text=text, element_function=element_function, | 398 selector=selector, text=text, element_function=element_function, |
401 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 399 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
402 direction=direction, distance=distance, | 400 direction=direction, distance=distance, |
403 overscroll=overscroll, repeat_count=repeat_count, | 401 overscroll=overscroll, repeat_count=repeat_count, |
404 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 402 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
405 | 403 |
406 def SwipePage(self, left_start_ratio=0.5, top_start_ratio=0.5, | 404 def SwipePage(self, left_start_ratio=0.5, top_start_ratio=0.5, |
407 direction='left', distance=100, speed_in_pixels_per_second=800): | 405 direction='left', distance=100, speed_in_pixels_per_second=800): |
408 """Perform swipe gesture on the page. | 406 """Perform swipe gesture on the page. |
409 | 407 |
410 Args: | 408 Args: |
411 left_start_ratio: The horizontal starting coordinate of the | 409 left_start_ratio: The horizontal starting coordinate of the |
412 gesture, as a ratio of the visible bounding rectangle for | 410 gesture, as a ratio of the visible bounding rectangle for |
413 document.body. | 411 document.body. |
414 top_start_ratio: The vertical starting coordinate of the | 412 top_start_ratio: The vertical starting coordinate of the |
415 gesture, as a ratio of the visible bounding rectangle for | 413 gesture, as a ratio of the visible bounding rectangle for |
416 document.body. | 414 document.body. |
417 direction: The direction of swipe, either 'left', 'right', | 415 direction: The direction of swipe, either 'left', 'right', |
418 'up', or 'down' | 416 'up', or 'down' |
419 distance: The distance to swipe (in pixel). | 417 distance: The distance to swipe (in pixel). |
420 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 418 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
421 """ | 419 """ |
422 self.RunAction(SwipeAction( | 420 self._RunAction(SwipeAction( |
423 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 421 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
424 direction=direction, distance=distance, | 422 direction=direction, distance=distance, |
425 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 423 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
426 | 424 |
427 def SwipeElement(self, selector=None, text=None, element_function=None, | 425 def SwipeElement(self, selector=None, text=None, element_function=None, |
428 left_start_ratio=0.5, top_start_ratio=0.5, | 426 left_start_ratio=0.5, top_start_ratio=0.5, |
429 direction='left', distance=100, | 427 direction='left', distance=100, |
430 speed_in_pixels_per_second=800): | 428 speed_in_pixels_per_second=800): |
431 """Perform swipe gesture on the element. | 429 """Perform swipe gesture on the element. |
432 | 430 |
(...skipping 10 matching lines...) Expand all Loading... |
443 gesture, as a ratio of the visible bounding rectangle for | 441 gesture, as a ratio of the visible bounding rectangle for |
444 the element. | 442 the element. |
445 top_start_ratio: The vertical starting coordinate of the | 443 top_start_ratio: The vertical starting coordinate of the |
446 gesture, as a ratio of the visible bounding rectangle for | 444 gesture, as a ratio of the visible bounding rectangle for |
447 the element. | 445 the element. |
448 direction: The direction of swipe, either 'left', 'right', | 446 direction: The direction of swipe, either 'left', 'right', |
449 'up', or 'down' | 447 'up', or 'down' |
450 distance: The distance to swipe (in pixel). | 448 distance: The distance to swipe (in pixel). |
451 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). | 449 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
452 """ | 450 """ |
453 self.RunAction(SwipeAction( | 451 self._RunAction(SwipeAction( |
454 selector=selector, text=text, element_function=element_function, | 452 selector=selector, text=text, element_function=element_function, |
455 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, | 453 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
456 direction=direction, distance=distance, | 454 direction=direction, distance=distance, |
457 speed_in_pixels_per_second=speed_in_pixels_per_second)) | 455 speed_in_pixels_per_second=speed_in_pixels_per_second)) |
458 | 456 |
459 def PlayMedia(self, selector=None, | 457 def PlayMedia(self, selector=None, |
460 playing_event_timeout_in_seconds=0, | 458 playing_event_timeout_in_seconds=0, |
461 ended_event_timeout_in_seconds=0): | 459 ended_event_timeout_in_seconds=0): |
462 """Invokes the "play" action on media elements (such as video). | 460 """Invokes the "play" action on media elements (such as video). |
463 | 461 |
464 Args: | 462 Args: |
465 selector: A CSS selector describing the element. If none is | 463 selector: A CSS selector describing the element. If none is |
466 specified, play the first media element on the page. If the | 464 specified, play the first media element on the page. If the |
467 selector matches more than 1 media element, all of them will | 465 selector matches more than 1 media element, all of them will |
468 be played. | 466 be played. |
469 playing_event_timeout_in_seconds: Maximum waiting time for the "playing" | 467 playing_event_timeout_in_seconds: Maximum waiting time for the "playing" |
470 event (dispatched when the media begins to play) to be fired. | 468 event (dispatched when the media begins to play) to be fired. |
471 0 means do not wait. | 469 0 means do not wait. |
472 ended_event_timeout_in_seconds: Maximum waiting time for the "ended" | 470 ended_event_timeout_in_seconds: Maximum waiting time for the "ended" |
473 event (dispatched when playback completes) to be fired. | 471 event (dispatched when playback completes) to be fired. |
474 0 means do not wait. | 472 0 means do not wait. |
475 | 473 |
476 Raises: | 474 Raises: |
477 TimeoutException: If the maximum waiting time is exceeded. | 475 TimeoutException: If the maximum waiting time is exceeded. |
478 """ | 476 """ |
479 self.RunAction(PlayAction( | 477 self._RunAction(PlayAction( |
480 selector=selector, | 478 selector=selector, |
481 playing_event_timeout_in_seconds=playing_event_timeout_in_seconds, | 479 playing_event_timeout_in_seconds=playing_event_timeout_in_seconds, |
482 ended_event_timeout_in_seconds=ended_event_timeout_in_seconds)) | 480 ended_event_timeout_in_seconds=ended_event_timeout_in_seconds)) |
483 | 481 |
484 def SeekMedia(self, seconds, selector=None, timeout_in_seconds=0, | 482 def SeekMedia(self, seconds, selector=None, timeout_in_seconds=0, |
485 log_time=True, label=''): | 483 log_time=True, label=''): |
486 """Performs a seek action on media elements (such as video). | 484 """Performs a seek action on media elements (such as video). |
487 | 485 |
488 Args: | 486 Args: |
489 seconds: The media time to seek to. | 487 seconds: The media time to seek to. |
490 selector: A CSS selector describing the element. If none is | 488 selector: A CSS selector describing the element. If none is |
491 specified, seek the first media element on the page. If the | 489 specified, seek the first media element on the page. If the |
492 selector matches more than 1 media element, all of them will | 490 selector matches more than 1 media element, all of them will |
493 be seeked. | 491 be seeked. |
494 timeout_in_seconds: Maximum waiting time for the "seeked" event | 492 timeout_in_seconds: Maximum waiting time for the "seeked" event |
495 (dispatched when the seeked operation completes) to be | 493 (dispatched when the seeked operation completes) to be |
496 fired. 0 means do not wait. | 494 fired. 0 means do not wait. |
497 log_time: Whether to log the seek time for the perf | 495 log_time: Whether to log the seek time for the perf |
498 measurement. Useful when performing multiple seek. | 496 measurement. Useful when performing multiple seek. |
499 label: A suffix string to name the seek perf measurement. | 497 label: A suffix string to name the seek perf measurement. |
500 | 498 |
501 Raises: | 499 Raises: |
502 TimeoutException: If the maximum waiting time is exceeded. | 500 TimeoutException: If the maximum waiting time is exceeded. |
503 """ | 501 """ |
504 self.RunAction(SeekAction( | 502 self._RunAction(SeekAction( |
505 seconds=seconds, selector=selector, | 503 seconds=seconds, selector=selector, |
506 timeout_in_seconds=timeout_in_seconds, | 504 timeout_in_seconds=timeout_in_seconds, |
507 log_time=log_time, label=label)) | 505 log_time=log_time, label=label)) |
508 | 506 |
509 def LoopMedia(self, loop_count, selector=None, timeout_in_seconds=None): | 507 def LoopMedia(self, loop_count, selector=None, timeout_in_seconds=None): |
510 """Loops a media playback. | 508 """Loops a media playback. |
511 | 509 |
512 Args: | 510 Args: |
513 loop_count: The number of times to loop the playback. | 511 loop_count: The number of times to loop the playback. |
514 selector: A CSS selector describing the element. If none is | 512 selector: A CSS selector describing the element. If none is |
515 specified, loop the first media element on the page. If the | 513 specified, loop the first media element on the page. If the |
516 selector matches more than 1 media element, all of them will | 514 selector matches more than 1 media element, all of them will |
517 be looped. | 515 be looped. |
518 timeout_in_seconds: Maximum waiting time for the looped playback to | 516 timeout_in_seconds: Maximum waiting time for the looped playback to |
519 complete. 0 means do not wait. None (the default) means to | 517 complete. 0 means do not wait. None (the default) means to |
520 wait loop_count * 60 seconds. | 518 wait loop_count * 60 seconds. |
521 | 519 |
522 Raises: | 520 Raises: |
523 TimeoutException: If the maximum waiting time is exceeded. | 521 TimeoutException: If the maximum waiting time is exceeded. |
524 """ | 522 """ |
525 self.RunAction(LoopAction( | 523 self._RunAction(LoopAction( |
526 loop_count=loop_count, selector=selector, | 524 loop_count=loop_count, selector=selector, |
527 timeout_in_seconds=timeout_in_seconds)) | 525 timeout_in_seconds=timeout_in_seconds)) |
528 | 526 |
529 def ForceGarbageCollection(self): | 527 def ForceGarbageCollection(self): |
530 """Forces JavaScript garbage collection on the page.""" | 528 """Forces JavaScript garbage collection on the page.""" |
531 self._tab.CollectGarbage() | 529 self._tab.CollectGarbage() |
532 | 530 |
533 def PauseInteractive(self): | 531 def PauseInteractive(self): |
534 """Pause the page execution and wait for terminal interaction. | 532 """Pause the page execution and wait for terminal interaction. |
535 | 533 |
536 This is typically used for debugging. You can use this to pause | 534 This is typically used for debugging. You can use this to pause |
537 the page execution and inspect the browser state before | 535 the page execution and inspect the browser state before |
538 continuing. | 536 continuing. |
539 """ | 537 """ |
540 raw_input("Interacting... Press Enter to continue.") | 538 raw_input("Interacting... Press Enter to continue.") |
541 | 539 |
542 def RepaintContinuously(self, seconds): | 540 def RepaintContinuously(self, seconds): |
543 """Continuously repaints the visible content. | 541 """Continuously repaints the visible content. |
544 | 542 |
545 It does this by requesting animation frames until the given number | 543 It does this by requesting animation frames until the given number |
546 of seconds have elapsed AND at least three RAFs have been | 544 of seconds have elapsed AND at least three RAFs have been |
547 fired. Times out after max(60, self.seconds), if less than three | 545 fired. Times out after max(60, self.seconds), if less than three |
548 RAFs were fired.""" | 546 RAFs were fired.""" |
549 self.RunAction(RepaintContinuouslyAction(seconds=seconds)) | 547 self._RunAction(RepaintContinuouslyAction(seconds=seconds)) |
550 | 548 |
551 class Interaction(object): | 549 class Interaction(object): |
552 | 550 |
553 def __init__(self, action_runner, label, flags): | 551 def __init__(self, action_runner, label, flags): |
554 assert action_runner | 552 assert action_runner |
555 assert label | 553 assert label |
556 assert isinstance(flags, list) | 554 assert isinstance(flags, list) |
557 | 555 |
558 self._action_runner = action_runner | 556 self._action_runner = action_runner |
559 self._label = label | 557 self._label = label |
560 self._flags = flags | 558 self._flags = flags |
561 self._started = False | 559 self._started = False |
562 | 560 |
563 def Begin(self): | 561 def Begin(self): |
564 assert not self._started | 562 assert not self._started |
565 self._started = True | 563 self._started = True |
566 self._action_runner.ExecuteJavaScript('console.time("%s");' % | 564 self._action_runner.ExecuteJavaScript('console.time("%s");' % |
567 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( | 565 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( |
568 self._label, self._flags)) | 566 self._label, self._flags)) |
569 | 567 |
570 def End(self): | 568 def End(self): |
571 assert self._started | 569 assert self._started |
572 self._started = False | 570 self._started = False |
573 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % | 571 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % |
574 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( | 572 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( |
575 self._label, self._flags)) | 573 self._label, self._flags)) |
OLD | NEW |