OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import time | 5 import time |
6 | 6 |
7 from telemetry.page.actions import gesture_action | 7 from telemetry.page.actions import gesture_action |
8 from telemetry.unittest import tab_test_case | 8 from telemetry.unittest import tab_test_case |
9 | 9 |
10 class MockGestureAction(gesture_action.GestureAction): | 10 class MockGestureAction(gesture_action.GestureAction): |
11 """Mock gesture action that simply sleeps for a specified amount of time.""" | 11 """Mock gesture action that simply sleeps for a specified amount of time.""" |
12 def __init__(self, attributes=None): | 12 def __init__(self, attributes=None): |
13 super(MockGestureAction, self).__init__(attributes) | 13 super(MockGestureAction, self).__init__(attributes) |
14 self._SetTimelineMarkerBaseName('MockGestureAction::RunAction') | 14 self._SetTimelineMarkerBaseName('MockGestureAction::RunAction') |
15 | 15 |
16 def RunGesture(self, page, tab, previous_action): | 16 def RunGesture(self, page, tab): |
17 duration = getattr(self, 'duration', 2) | 17 duration = getattr(self, 'duration', 2) |
18 | 18 |
19 time.sleep(duration) | 19 time.sleep(duration) |
20 | 20 |
21 | 21 |
22 class GestureActionTest(tab_test_case.TabTestCase): | 22 class GestureActionTest(tab_test_case.TabTestCase): |
23 def testGestureAction(self): | 23 def testGestureAction(self): |
24 """Test that GestureAction.RunAction() calls RunGesture().""" | 24 """Test that GestureAction.RunAction() calls RunGesture().""" |
25 action = MockGestureAction({ 'duration': 1 }) | 25 action = MockGestureAction({ 'duration': 1 }) |
26 | 26 |
27 start_time = time.time() | 27 start_time = time.time() |
28 action.RunAction(None, self._tab, None) | 28 action.RunAction(None, self._tab) |
29 self.assertGreaterEqual(time.time() - start_time, 1.0) | 29 self.assertGreaterEqual(time.time() - start_time, 1.0) |
30 | 30 |
31 def testWaitAfter(self): | 31 def testWaitAfter(self): |
32 action = MockGestureAction({ 'duration': 1, | 32 action = MockGestureAction({ 'duration': 1, |
33 'wait_after': { 'seconds': 1 } }) | 33 'wait_after': { 'seconds': 1 } }) |
34 | 34 |
35 start_time = time.time() | 35 start_time = time.time() |
36 action.RunAction(None, self._tab, None) | 36 action.RunAction(None, self._tab) |
37 self.assertGreaterEqual(time.time() - start_time, 2.0) | 37 self.assertGreaterEqual(time.time() - start_time, 2.0) |
OLD | NEW |