| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from telemetry.core import util | 5 from telemetry.core import util |
| 6 from telemetry.page.actions import loop | 6 from telemetry.page.actions import loop |
| 7 from telemetry.unittest import tab_test_case | 7 from telemetry.unittest import tab_test_case |
| 8 from telemetry.unittest import test | |
| 9 | 8 |
| 10 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");' | 9 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");' |
| 11 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");' | 10 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");' |
| 12 | 11 |
| 13 | 12 |
| 14 class LoopActionTest(tab_test_case.TabTestCase): | 13 class LoopActionTest(tab_test_case.TabTestCase): |
| 15 | 14 |
| 16 def setUp(self): | 15 def setUp(self): |
| 17 tab_test_case.TabTestCase.setUp(self) | 16 tab_test_case.TabTestCase.setUp(self) |
| 18 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) | 17 self.Navigate('video_test.html') |
| 19 self._tab.Navigate(self._browser.http_server.UrlOf('video_test.html')) | |
| 20 self._tab.WaitForDocumentReadyStateToBeComplete() | |
| 21 | 18 |
| 22 @test.Disabled('chromeos') | |
| 23 def testLoopWithNoSelector(self): | 19 def testLoopWithNoSelector(self): |
| 24 """Tests that with no selector Loop action loops first media element.""" | 20 """Tests that with no selector Loop action loops first media element.""" |
| 25 data = {'selector': '#video_1', 'loop_count': 2} | 21 data = {'selector': '#video_1', 'loop_count': 2} |
| 26 action = loop.LoopAction(data) | 22 action = loop.LoopAction(data) |
| 27 action.WillRunAction(None, self._tab) | 23 action.WillRunAction(None, self._tab) |
| 28 action.RunAction(None, self._tab, None) | 24 action.RunAction(None, self._tab, None) |
| 29 # Assert only first video has played. | 25 # Assert only first video has played. |
| 30 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) | 26 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) |
| 31 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) | 27 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) |
| 32 | 28 |
| 33 @test.Disabled('chromeos') | |
| 34 def testLoopWithAllSelector(self): | 29 def testLoopWithAllSelector(self): |
| 35 """Tests that Loop action loops all video elements with selector='all'.""" | 30 """Tests that Loop action loops all video elements with selector='all'.""" |
| 36 data = {'selector': 'all', 'loop_count': 2} | 31 data = {'selector': 'all', 'loop_count': 2} |
| 37 action = loop.LoopAction(data) | 32 action = loop.LoopAction(data) |
| 38 action.WillRunAction(None, self._tab) | 33 action.WillRunAction(None, self._tab) |
| 39 # Both videos not playing before running action. | 34 # Both videos not playing before running action. |
| 40 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) | 35 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) |
| 41 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) | 36 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) |
| 42 action.RunAction(None, self._tab, None) | 37 action.RunAction(None, self._tab, None) |
| 43 # Assert all media elements played. | 38 # Assert all media elements played. |
| 44 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) | 39 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) |
| 45 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) | 40 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) |
| 46 | 41 |
| 47 @test.Disabled('chromeos') | |
| 48 def testLoopWaitForLoopTimeout(self): | 42 def testLoopWaitForLoopTimeout(self): |
| 49 """Tests that wait_for_loop timeouts if video does not loop.""" | 43 """Tests that wait_for_loop timeouts if video does not loop.""" |
| 50 data = {'selector': '#video_1', | 44 data = {'selector': '#video_1', |
| 51 'wait_timeout': 1, | 45 'wait_timeout': 1, |
| 52 'loop_count': 2} | 46 'loop_count': 2} |
| 53 action = loop.LoopAction(data) | 47 action = loop.LoopAction(data) |
| 54 action.WillRunAction(None, self._tab) | 48 action.WillRunAction(None, self._tab) |
| 55 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) | 49 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) |
| 56 self.assertRaises(util.TimeoutException, action.RunAction, None, self._tab, | 50 self.assertRaises(util.TimeoutException, action.RunAction, None, self._tab, |
| 57 None) | 51 None) |
| 58 | 52 |
| 59 def testLoopWithoutLoopCount(self): | 53 def testLoopWithoutLoopCount(self): |
| 60 """Tests that loop action fails with no loop count.""" | 54 """Tests that loop action fails with no loop count.""" |
| 61 data = {} | 55 data = {} |
| 62 action = loop.LoopAction(data) | 56 action = loop.LoopAction(data) |
| 63 action.WillRunAction(None, self._tab) | 57 action.WillRunAction(None, self._tab) |
| 64 self.assertRaises(AssertionError, action.RunAction, None, self._tab, None) | 58 self.assertRaises(AssertionError, action.RunAction, None, self._tab, None) |
| OLD | NEW |