| Index: tools/telemetry/telemetry/page/actions/gesture_action_unittest.py
|
| diff --git a/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py b/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py
|
| index 9c6f909d7385cd7ed6e5dd3a4389a6ddcafef7ea..637fad7f6cba2a525a701fda02a73fd6e476671a 100644
|
| --- a/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py
|
| +++ b/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py
|
| @@ -2,35 +2,43 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| -import time
|
| -
|
| from telemetry.page.actions import gesture_action
|
| +from telemetry.page.actions import wait
|
| from telemetry.unittest import tab_test_case
|
| +from telemetry.unittest import simple_mock
|
|
|
| class MockGestureAction(gesture_action.GestureAction):
|
| """Mock gesture action that simply sleeps for a specified amount of time."""
|
| - def __init__(self, attributes=None):
|
| + def __init__(self, sleep_func, attributes=None):
|
| + self.sleep_func = sleep_func
|
| super(MockGestureAction, self).__init__(attributes)
|
|
|
| def RunGesture(self, page, tab):
|
| duration = getattr(self, 'duration', 2)
|
|
|
| - time.sleep(duration)
|
| + self.sleep_func(duration)
|
|
|
|
|
| class GestureActionTest(tab_test_case.TabTestCase):
|
| def testGestureAction(self):
|
| """Test that GestureAction.RunAction() calls RunGesture()."""
|
| - action = MockGestureAction({ 'duration': 1 })
|
| + mock_timer = simple_mock.MockTimer()
|
| + action = MockGestureAction(mock_timer.Sleep, { 'duration': 1 })
|
|
|
| - start_time = time.time()
|
| action.RunAction(None, self._tab)
|
| - self.assertGreaterEqual(time.time() - start_time, 1.0)
|
| + self.assertEqual(mock_timer.GetTime(), 1)
|
|
|
| def testWaitAfter(self):
|
| - action = MockGestureAction({ 'duration': 1,
|
| - 'wait_after': { 'seconds': 1 } })
|
| -
|
| - start_time = time.time()
|
| - action.RunAction(None, self._tab)
|
| - self.assertGreaterEqual(time.time() - start_time, 2.0)
|
| + mock_timer = simple_mock.MockTimer()
|
| + real_time_sleep = wait.time.sleep
|
| + wait.time.sleep = mock_timer.Sleep
|
| +
|
| + try:
|
| + action = MockGestureAction(mock_timer.Sleep,
|
| + { 'duration': 1,
|
| + 'wait_after': { 'seconds': 1 } })
|
| +
|
| + action.RunAction(None, self._tab)
|
| + self.assertEqual(mock_timer.GetTime(), 2)
|
| + finally:
|
| + wait.time.sleep = real_time_sleep
|
|
|