• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 util
6from telemetry.page.actions import seek
7from telemetry.unittest import tab_test_case
8
9AUDIO_1_SEEKED_CHECK = 'window.__hasEventCompleted("#audio_1", "seeked");'
10VIDEO_1_SEEKED_CHECK = 'window.__hasEventCompleted("#video_1", "seeked");'
11
12
13class SeekActionTest(tab_test_case.TabTestCase):
14
15  def setUp(self):
16    tab_test_case.TabTestCase.setUp(self)
17    self.Navigate('video_test.html')
18
19  def testSeekWithNoSelector(self):
20    """Tests that with no selector Seek  action seeks first media element."""
21    action = seek.SeekAction(seconds=1, timeout_in_seconds=10)
22    action.WillRunAction(self._tab)
23    action.RunAction(self._tab)
24    # Assert only first video has played.
25    self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
26    self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK))
27
28  def testSeekWithVideoSelector(self):
29    """Tests that Seek action seeks video element matching selector."""
30    action = seek.SeekAction(seconds=1, selector='#video_1',
31                             timeout_in_seconds=10)
32    action.WillRunAction(self._tab)
33    # Both videos not playing before running action.
34    self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
35    self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK))
36    action.RunAction(self._tab)
37    # Assert only video matching selector has played.
38    self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
39    self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK))
40
41  def testSeekWithAllSelector(self):
42    """Tests that Seek action seeks all video elements with selector='all'."""
43    action = seek.SeekAction(seconds=1, selector='all',
44                             timeout_in_seconds=10)
45    action.WillRunAction(self._tab)
46    # Both videos not playing before running action.
47    self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
48    self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK))
49    action.RunAction(self._tab)
50    # Assert all media elements played.
51    self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
52    self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_SEEKED_CHECK))
53
54  def testSeekWaitForSeekTimeout(self):
55    """Tests that wait_for_seeked timeouts if video does not seek."""
56    action = seek.SeekAction(seconds=1, selector='#video_1',
57                             timeout_in_seconds=0.1)
58    action.WillRunAction(self._tab)
59    self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""')
60    self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
61    self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
62