Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: tools/telemetry/telemetry/page/actions/loop_unittest.py

Issue 346923003: Add ActionRunner wrapper for the remaining less used actions (try 2): (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update unit test to skip test if touch is not supported. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import decorators 5 from telemetry import decorators
6 from telemetry.core import util 6 from telemetry.core import util
7 from telemetry.page.actions import loop 7 from telemetry.page.actions import loop
8 from telemetry.unittest import tab_test_case 8 from telemetry.unittest import tab_test_case
9 9
10 10
11 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");' 11 AUDIO_1_LOOP_CHECK = 'window.__hasEventCompleted("#audio_1", "loop");'
12 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");' 12 VIDEO_1_LOOP_CHECK = 'window.__hasEventCompleted("#video_1", "loop");'
13 13
14 14
15 class LoopActionTest(tab_test_case.TabTestCase): 15 class LoopActionTest(tab_test_case.TabTestCase):
16 16
17 def setUp(self): 17 def setUp(self):
18 tab_test_case.TabTestCase.setUp(self) 18 tab_test_case.TabTestCase.setUp(self)
19 self.Navigate('video_test.html') 19 self.Navigate('video_test.html')
20 20
21 @decorators.Disabled('android') 21 @decorators.Disabled('android')
22 def testLoopWithNoSelector(self): 22 def testLoopWithNoSelector(self):
23 """Tests that with no selector Loop action loops first media element.""" 23 """Tests that with no selector Loop action loops first media element."""
24 data = {'selector': '#video_1', 'loop_count': 2} 24 action = loop.LoopAction(loop_count=2, selector='#video_1')
25 action = loop.LoopAction(data)
26 action.WillRunAction(self._tab) 25 action.WillRunAction(self._tab)
27 action.RunAction(self._tab) 26 action.RunAction(self._tab)
28 # Assert only first video has played. 27 # Assert only first video has played.
29 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 28 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
30 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 29 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
31 30
32 @decorators.Disabled('android') 31 @decorators.Disabled('android')
33 def testLoopWithAllSelector(self): 32 def testLoopWithAllSelector(self):
34 """Tests that Loop action loops all video elements with selector='all'.""" 33 """Tests that Loop action loops all video elements with selector='all'."""
35 data = {'selector': 'all', 'loop_count': 2} 34 action = loop.LoopAction(loop_count=2, selector='all')
36 action = loop.LoopAction(data)
37 action.WillRunAction(self._tab) 35 action.WillRunAction(self._tab)
38 # Both videos not playing before running action. 36 # Both videos not playing before running action.
39 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 37 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
40 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 38 self.assertFalse(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
41 action.RunAction(self._tab) 39 action.RunAction(self._tab)
42 # Assert all media elements played. 40 # Assert all media elements played.
43 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 41 self.assertTrue(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
44 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK)) 42 self.assertTrue(self._tab.EvaluateJavaScript(AUDIO_1_LOOP_CHECK))
45 43
46 @decorators.Disabled('android') 44 @decorators.Disabled('android')
47 def testLoopWaitForLoopTimeout(self): 45 def testLoopWaitForLoopTimeout(self):
48 """Tests that wait_for_loop timeout_in_secondss if video does not loop.""" 46 """Tests that wait_for_loop timeout_in_secondss if video does not loop."""
49 data = {'selector': '#video_1', 47 action = loop.LoopAction(loop_count=2, selector='#video_1',
50 'wait_timeout_in_seconds': 1, 48 timeout_in_seconds=1)
51 'loop_count': 2}
52 action = loop.LoopAction(data)
53 action.WillRunAction(self._tab) 49 action.WillRunAction(self._tab)
54 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) 50 self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
55 self.assertRaises(util.TimeoutException, action.RunAction, self._tab) 51 self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
56
57 @decorators.Disabled('android')
58 def testLoopWithoutLoopCount(self):
59 """Tests that loop action fails with no loop count."""
60 data = {}
61 action = loop.LoopAction(data)
62 action.WillRunAction(self._tab)
63 self.assertRaises(AssertionError, action.RunAction, self._tab)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page/actions/loop.py ('k') | tools/telemetry/telemetry/page/actions/pinch.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698