Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: telemetry/telemetry/internal/actions/seek.py

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 parameters are: 7 Action parameters are:
8 - seconds: The media time to seek to. Test fails if not provided. 8 - seconds: 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 - timeout_in_seconds: Maximum waiting time for the "seeked" event 11 - timeout_in_seconds: Maximum waiting time for the "seeked" event
12 (dispatched when the seeked operation completes) 12 (dispatched when the seeked operation completes)
13 to be fired. 0 means do not wait. 13 to be fired. 0 means do not wait.
14 - log_time: If true the seek time is recorded, otherwise media 14 - log_time: If true the seek time is recorded, otherwise media
15 measurement will not be aware of the seek action. Used to 15 measurement will not be aware of the seek action. Used to
16 perform multiple seeks. Default true. 16 perform multiple seeks. Default true.
17 - label: A suffix string to name the seek perf measurement. 17 - label: A suffix string to name the seek perf measurement.
18 """ 18 """
19 19
20 from telemetry.core import exceptions 20 from telemetry.core import exceptions
21 from telemetry.internal.actions import media_action 21 from telemetry.internal.actions import media_action
22 from telemetry.internal.actions import page_action 22 from telemetry.internal.actions import page_action
23 from telemetry.internal.actions import utils
23 24
24 25
25 class SeekAction(media_action.MediaAction): 26 class SeekAction(media_action.MediaAction):
26 def __init__(self, seconds, selector=None, timeout_in_seconds=0, 27 def __init__(self, seconds, selector=None, timeout_in_seconds=0,
27 log_time=True, label=''): 28 log_time=True, label=''):
28 super(SeekAction, self).__init__() 29 super(SeekAction, self).__init__()
29 self._seconds = seconds 30 self._seconds = seconds
30 self._selector = selector if selector else '' 31 self._selector = selector if selector else ''
31 self._timeout_in_seconds = timeout_in_seconds 32 self._timeout_in_seconds = timeout_in_seconds
32 self._log_time = log_time 33 self._log_time = log_time
33 self._label = label 34 self._label = label
34 35
35 def WillRunAction(self, tab): 36 def WillRunAction(self, tab):
36 """Load the media metrics JS code prior to running the action.""" 37 """Load the media metrics JS code prior to running the action."""
37 super(SeekAction, self).WillRunAction(tab) 38 super(SeekAction, self).WillRunAction(tab)
38 self.LoadJS(tab, 'seek.js') 39 utils.InjectJavaScript(tab, 'seek.js')
39 40
40 def RunAction(self, tab): 41 def RunAction(self, tab):
41 try: 42 try:
42 tab.ExecuteJavaScript( 43 tab.ExecuteJavaScript(
43 'window.__seekMedia("%s", "%s", %i, "%s");' % 44 'window.__seekMedia("%s", "%s", %i, "%s");' %
44 (self._selector, self._seconds, self._log_time, self._label)) 45 (self._selector, self._seconds, self._log_time, self._label))
45 if self._timeout_in_seconds > 0: 46 if self._timeout_in_seconds > 0:
46 self.WaitForEvent(tab, self._selector, 'seeked', 47 self.WaitForEvent(tab, self._selector, 'seeked',
47 self._timeout_in_seconds) 48 self._timeout_in_seconds)
48 except exceptions.EvaluateException: 49 except exceptions.EvaluateException:
49 raise page_action.PageActionFailed('Cannot seek media element(s) with ' 50 raise page_action.PageActionFailed('Cannot seek media element(s) with '
50 'selector = %s.' % self._selector) 51 'selector = %s.' % self._selector)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/scroll_unittest.py ('k') | telemetry/telemetry/internal/actions/swipe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698