OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """A Telemetry page_action that performs the "seek" action on media elements. | 5 """A Telemetry page_action that performs the "seek" action on media elements. |
6 | 6 |
7 Action attributes are: | 7 Action attributes are: |
8 - seek_time: The media time to seek to. Test fails if not provided. | 8 - seek_time: The media time to seek to. Test fails if not provided. |
9 - selector: If no selector is defined then the action attempts to seek the first | 9 - selector: If no selector is defined then the action attempts to seek the first |
10 media element on the page. If 'all' then seek all media elements. | 10 media element on the page. If 'all' then seek all media elements. |
11 - log_seek_time: If true the seek time is recorded, otherwise media measurement | 11 - log_seek_time: If true the seek time is recorded, otherwise media measurement |
12 will not be aware of the seek action. Used to perform multiple | 12 will not be aware of the seek action. Used to perform multiple |
13 seeks. Default true. | 13 seeks. Default true. |
14 - wait_for_seeked: If true forces the action to wait for seeked event to fire. | 14 - wait_for_seeked: If true forces the action to wait for seeked event to fire. |
15 Default false. | 15 Default false. |
16 - wait_timeout: Timeout to wait for seeked event. Only valid with | 16 - wait_timeout: Timeout to wait for seeked event. Only valid with |
17 wait_for_seeked=true | 17 wait_for_seeked=true |
| 18 - seek_label: A suffix string to name the seek perf measurement. |
18 """ | 19 """ |
19 | 20 |
20 from telemetry.page.actions.media_action import MediaAction | |
21 from telemetry.core import exceptions | 21 from telemetry.core import exceptions |
22 from telemetry.page.actions import page_action | 22 from telemetry.page.actions import page_action |
| 23 import telemetry.page.actions.media_action as media_action |
23 | 24 |
24 | 25 |
25 class SeekAction(MediaAction): | 26 class SeekAction(media_action.MediaAction): |
26 def __init__(self, attributes=None): | |
27 super(SeekAction, self).__init__(attributes) | |
28 | |
29 def WillRunAction(self, page, tab): | 27 def WillRunAction(self, page, tab): |
30 """Load the media metrics JS code prior to running the action.""" | 28 """Load the media metrics JS code prior to running the action.""" |
31 super(SeekAction, self).WillRunAction(page, tab) | 29 super(SeekAction, self).WillRunAction(page, tab) |
32 self.LoadJS(tab, 'seek.js') | 30 self.LoadJS(tab, 'seek.js') |
33 | 31 |
34 def RunAction(self, page, tab, previous_action): | 32 def RunAction(self, page, tab, previous_action): |
35 try: | 33 try: |
36 assert hasattr(self, 'seek_time') | 34 assert hasattr(self, 'seek_time') |
37 selector = self.selector if hasattr(self, 'selector') else '' | 35 selector = self.selector if hasattr(self, 'selector') else '' |
38 log_seek = self.log_seek == True if hasattr(self, 'log_seek') else True | 36 log_seek = self.log_seek == True if hasattr(self, 'log_seek') else True |
39 tab.ExecuteJavaScript('window.__seekMedia("%s", "%s", %i);' % | 37 seek_label = self.seek_label if hasattr(self, 'seek_label') else '' |
40 (selector, self.seek_time, log_seek)) | 38 tab.ExecuteJavaScript('window.__seekMedia("%s", "%s", %i, "%s");' % |
| 39 (selector, self.seek_time, log_seek, seek_label)) |
41 timeout = self.wait_timeout if hasattr(self, 'wait_timeout') else 60 | 40 timeout = self.wait_timeout if hasattr(self, 'wait_timeout') else 60 |
42 # Check if we need to wait for 'seeked' event to fire. | 41 # Check if we need to wait for 'seeked' event to fire. |
43 if hasattr(self, 'wait_for_seeked') and self.wait_for_seeked: | 42 if hasattr(self, 'wait_for_seeked') and self.wait_for_seeked: |
44 self.WaitForEvent(tab, selector, 'seeked', timeout) | 43 self.WaitForEvent(tab, selector, 'seeked', timeout) |
45 except exceptions.EvaluateException: | 44 except exceptions.EvaluateException: |
46 raise page_action.PageActionFailed('Cannot seek media element(s) with ' | 45 raise page_action.PageActionFailed('Cannot seek media element(s) with ' |
47 'selector = %s.' % selector) | 46 'selector = %s.' % selector) |
OLD | NEW |