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.
5 from telemetry import decorators
6 from telemetry.core import util
7 from telemetry.page.actions import loop
8 from telemetry.unittest import tab_test_case
10 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");'
11 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");'
14 class LoopActionTest(tab_test_case.TabTestCase):
17 tab_test_case.TabTestCase.setUp(self)
18 self.Navigate('video_test.html')
20 @decorators.Disabled('android', 'linux') # crbug.com/418577
21 def testLoopWithNoSelector(self):
22 """Tests that with no selector Loop action loops first media element."""
23 action = loop.LoopAction(loop_count=2, selector='#video_1',
24 timeout_in_seconds=10)
25 action.WillRunAction(self._tab)
26 action.RunAction(self._tab)
27 # Assert only first video has played.
28 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
29 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
31 @decorators.Disabled('android', 'linux') # crbug.com/418577
32 def testLoopWithAllSelector(self):
33 """Tests that Loop action loops all video elements with selector='all'."""
34 action = loop.LoopAction(loop_count=2, selector='all',
35 timeout_in_seconds=10)
36 action.WillRunAction(self._tab)
37 # Both videos not playing before running action.
38 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
39 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
40 action.RunAction(self._tab)
41 # Assert all media elements played.
42 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
43 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
45 @decorators.Disabled('android', 'linux') # crbug.com/418577
46 def testLoopWaitForLoopTimeout(self):
47 """Tests that wait_for_loop timeout_in_secondss if video does not loop."""
48 action = loop.LoopAction(loop_count=2, selector='#video_1',
50 action.WillRunAction(self._tab)
51 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
52 self.assertRaises(util.TimeoutException, action.RunAction, self._tab)