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

Unified Diff: tools/telemetry/telemetry/page/actions/gesture_action_unittest.py

Issue 240893004: Mock timer for Telemetry unit tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hide time.sleep and time.time Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/telemetry/telemetry/page/actions/wait_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | tools/telemetry/telemetry/page/actions/wait_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698