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 5from telemetry.core import exceptions 6from telemetry import decorators 7from telemetry.internal.actions import loop 8from telemetry.testing import tab_test_case 9 10AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");' 11VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");' 12 13 14class 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', '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)) 30 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)) 44 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', 49 timeout_in_seconds=1) 50 action.WillRunAction(self._tab) 51 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 52 self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab) 53