Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / gesture_action_unittest.py
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.
4
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
9
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)
15
16   def RunGesture(self, page, tab):
17     duration = getattr(self, 'duration', 2)
18
19     self.sleep_func(duration)
20
21
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 })
27
28     action.RunAction(None, self._tab)
29     self.assertEqual(mock_timer.GetTime(), 1)
30
31   def testWaitAfter(self):
32     mock_timer = simple_mock.MockTimer()
33     real_time_sleep = wait.time.sleep
34     wait.time.sleep = mock_timer.Sleep
35
36     try:
37       action = MockGestureAction(mock_timer.Sleep,
38                                  { 'duration': 1,
39                                    'wait_after': { 'seconds': 1 } })
40
41       action.RunAction(None, self._tab)
42       self.assertEqual(mock_timer.GetTime(), 2)
43     finally:
44       wait.time.sleep = real_time_sleep