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 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 9 10 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");' 11 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");' 12 13 14 class LoopActionTest(tab_test_case.TabTestCase): 15 16 def setUp(self): 17 tab_test_case.TabTestCase.setUp(self) 18 self.Navigate('video_test.html') 19 20 @decorators.Disabled('android') 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 action.WillRunAction(self._tab) 25 action.RunAction(self._tab) 26 # Assert only first video has played. 27 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 28 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 29 30 @decorators.Disabled('android') 31 def testLoopWithAllSelector(self): 32 """Tests that Loop action loops all video elements with selector='all'.""" 33 action = loop.LoopAction(loop_count=2, selector='all') 34 action.WillRunAction(self._tab) 35 # Both videos not playing before running action. 36 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 37 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 38 action.RunAction(self._tab) 39 # Assert all media elements played. 40 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 41 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 42 43 @decorators.Disabled('android', 'linux') 44 def testLoopWaitForLoopTimeout(self): 45 """Tests that wait_for_loop timeout_in_secondss if video does not loop.""" 46 action = loop.LoopAction(loop_count=2, selector='#video_1', 47 timeout_in_seconds=1) 48 action.WillRunAction(self._tab) 49 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 50 self.assertRaises(util.TimeoutException, action.RunAction, self._tab) 51