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
3 # found in the LICENSE file.
5 from telemetry.page.actions import gesture_action
6 from telemetry.page.actions import wait
7 from telemetry.unittest import tab_test_case
8 from telemetry.unittest import simple_mock
10 class MockGestureAction(gesture_action.GestureAction):
11 """Mock gesture action that simply sleeps for a specified amount of time."""
12 def __init__(self, sleep_func, attributes=None):
13 self.sleep_func = sleep_func
14 super(MockGestureAction, self).__init__(attributes)
16 def RunGesture(self, page, tab):
17 duration = getattr(self, 'duration', 2)
19 self.sleep_func(duration)
22 class GestureActionTest(tab_test_case.TabTestCase):
23 def testGestureAction(self):
24 """Test that GestureAction.RunAction() calls RunGesture()."""
25 mock_timer = simple_mock.MockTimer()
26 action = MockGestureAction(mock_timer.Sleep, { 'duration': 1 })
28 action.RunAction(None, self._tab)
29 self.assertEqual(mock_timer.GetTime(), 1)
31 def testWaitAfter(self):
32 mock_timer = simple_mock.MockTimer()
33 real_time_sleep = wait.time.sleep
34 wait.time.sleep = mock_timer.Sleep
37 action = MockGestureAction(mock_timer.Sleep,
39 'wait_after': { 'seconds': 1 } })
41 action.RunAction(None, self._tab)
42 self.assertEqual(mock_timer.GetTime(), 2)
44 wait.time.sleep = real_time_sleep