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

Side by Side Diff: tools/telemetry/telemetry/page/actions/play.py

Issue 1056133003: Move page/actions to internal/actions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add copyright header. Created 5 years, 8 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
(Empty)
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
3 # found in the LICENSE file.
4
5 """A Telemetry page_action that performs the "play" action on media elements.
6
7 Media elements can be specified by a selector argument. If no selector is
8 defined then then the action attempts to play the first video element or audio
9 element on the page. A selector can also be 'all' to play all media elements.
10
11 Other arguments to use are: playing_event_timeout_in_seconds and
12 ended_event_timeout_in_seconds, which forces the action to wait until
13 playing and ended events get fired respectively.
14 """
15
16 from telemetry.core import exceptions
17 from telemetry.page.actions import media_action
18 from telemetry.page.actions import page_action
19
20
21 class PlayAction(media_action.MediaAction):
22 def __init__(self, selector=None,
23 playing_event_timeout_in_seconds=0,
24 ended_event_timeout_in_seconds=0):
25 super(PlayAction, self).__init__()
26 self._selector = selector if selector else ''
27 self._playing_event_timeout_in_seconds = playing_event_timeout_in_seconds
28 self._ended_event_timeout_in_seconds = ended_event_timeout_in_seconds
29
30 def WillRunAction(self, tab):
31 """Load the media metrics JS code prior to running the action."""
32 super(PlayAction, self).WillRunAction(tab)
33 self.LoadJS(tab, 'play.js')
34
35 def RunAction(self, tab):
36 try:
37 tab.ExecuteJavaScript('window.__playMedia("%s");' % self._selector)
38 # Check if we need to wait for 'playing' event to fire.
39 if self._playing_event_timeout_in_seconds > 0:
40 self.WaitForEvent(tab, self._selector, 'playing',
41 self._playing_event_timeout_in_seconds)
42 # Check if we need to wait for 'ended' event to fire.
43 if self._ended_event_timeout_in_seconds > 0:
44 self.WaitForEvent(tab, self._selector, 'ended',
45 self._ended_event_timeout_in_seconds)
46 except exceptions.EvaluateException:
47 raise page_action.PageActionFailed('Cannot play media element(s) with '
48 'selector = %s.' % self._selector)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page/actions/play.js ('k') | tools/telemetry/telemetry/page/actions/play_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698