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 seek 8from telemetry.testing import tab_test_case 9 10AUDIO_1_SEEKED_CHECK = 'window.__hasEventCompleted("#audio_1", "seeked");' 11VIDEO_1_SEEKED_CHECK = 'window.__hasEventCompleted("#video_1", "seeked");' 12 13 14class SeekActionTest(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('linux') # crbug.com/418577 21 def testSeekWithNoSelector(self): 22 """Tests that with no selector Seek action seeks first media element.""" 23 action = seek.SeekAction(seconds=1, timeout_in_seconds=5) 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_SEEKED_CHECK)) 28 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK)) 29 30 @decorators.Disabled('linux') # crbug.com/418577 31 def testSeekWithVideoSelector(self): 32 """Tests that Seek action seeks video element matching selector.""" 33 action = seek.SeekAction(seconds=1, selector='#video_1', 34 timeout_in_seconds=5) 35 action.WillRunAction(self._tab) 36 # Both videos not playing before running action. 37 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) 38 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK)) 39 action.RunAction(self._tab) 40 # Assert only video matching selector has played. 41 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) 42 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK)) 43 44 @decorators.Disabled('linux') # crbug.com/418577 45 def testSeekWithAllSelector(self): 46 """Tests that Seek action seeks all video elements with selector='all'.""" 47 action = seek.SeekAction(seconds=1, selector='all', 48 timeout_in_seconds=5) 49 action.WillRunAction(self._tab) 50 # Both videos not playing before running action. 51 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) 52 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK)) 53 action.RunAction(self._tab) 54 # Assert all media elements played. 55 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) 56 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK)) 57 58 @decorators.Disabled('linux') # crbug.com/418577 59 def testSeekWaitForSeekTimeout(self): 60 """Tests that wait_for_seeked timeouts if video does not seek.""" 61 action = seek.SeekAction(seconds=1, selector='#video_1', 62 timeout_in_seconds=0.1) 63 action.WillRunAction(self._tab) 64 self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""') 65 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) 66 self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab) 67