| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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.internal.actions import key_event | 7 from telemetry.internal.actions import key_event |
| 8 from telemetry.internal.actions import utils |
| 8 from telemetry.testing import tab_test_case | 9 from telemetry.testing import tab_test_case |
| 9 | 10 |
| 10 | 11 |
| 11 class KeyPressActionTest(tab_test_case.TabTestCase): | 12 class KeyPressActionTest(tab_test_case.TabTestCase): |
| 12 | 13 |
| 13 @property | 14 @property |
| 14 def _scroll_position(self): | 15 def _scroll_position(self): |
| 15 return self._tab.EvaluateJavaScript( | 16 return self._tab.EvaluateJavaScript( |
| 16 'document.documentElement.scrollTop || document.body.scrollTop') | 17 'document.documentElement.scrollTop || document.body.scrollTop') |
| 17 | 18 |
| 18 @property | 19 @property |
| 19 def _window_height(self): | 20 def _window_height(self): |
| 20 return self._tab.EvaluateJavaScript('window.innerHeight') | 21 return self._tab.EvaluateJavaScript('__GestureCommon_GetWindowHeight()') |
| 21 | 22 |
| 22 def _PressKey(self, key): | 23 def _PressKey(self, key): |
| 23 action = key_event.KeyPressAction(key) | 24 action = key_event.KeyPressAction(key) |
| 24 action.WillRunAction(self._tab) | 25 action.WillRunAction(self._tab) |
| 25 action.RunAction(self._tab) | 26 action.RunAction(self._tab) |
| 26 | 27 |
| 27 def setUp(self): | 28 def setUp(self): |
| 28 tab_test_case.TabTestCase.setUp(self) | 29 tab_test_case.TabTestCase.setUp(self) |
| 29 self.Navigate('blank.html') | 30 self.Navigate('blank.html') |
| 31 utils.InjectJavaScript(self._tab, 'gesture_common.js') |
| 30 | 32 |
| 31 def testPressEndAndHome(self): | 33 def testPressEndAndHome(self): |
| 32 # Make page taller than the window so it's scrollable. | 34 # Make page taller than the window so it's scrollable. |
| 33 self._tab.ExecuteJavaScript( | 35 self._tab.ExecuteJavaScript('document.body.style.height =' |
| 34 'document.body.style.height = (3 * window.innerHeight + 1) + "px";') | 36 '(3 * __GestureCommon_GetWindowHeight() + 1) + "px";') |
| 35 | 37 |
| 36 # Check that the browser is currently showing the top of the page and that | 38 # Check that the browser is currently showing the top of the page and that |
| 37 # the page has non-trivial height. | 39 # the page has non-trivial height. |
| 38 self.assertEquals(0, self._scroll_position) | 40 self.assertEquals(0, self._scroll_position) |
| 39 self.assertLess(50, self._window_height) | 41 self.assertLess(50, self._window_height) |
| 40 | 42 |
| 41 self._PressKey('End') | 43 self._PressKey('End') |
| 42 | 44 |
| 43 # Scroll happens *after* key press returns, so we need to wait a little. | 45 # Scroll happens *after* key press returns, so we need to wait a little. |
| 44 time.sleep(1) | 46 time.sleep(1) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 self._PressKey('Return') | 76 self._PressKey('Return') |
| 75 | 77 |
| 76 # Check that the contents of the textarea is correct. | 78 # Check that the contents of the textarea is correct. |
| 77 self.assertEquals('Hello,\nWorld!', | 79 self.assertEquals('Hello,\nWorld!', |
| 78 self._tab.EvaluateJavaScript( | 80 self._tab.EvaluateJavaScript( |
| 79 'document.querySelector("textarea").value')) | 81 'document.querySelector("textarea").value')) |
| 80 | 82 |
| 81 def testPressUnknownKey(self): | 83 def testPressUnknownKey(self): |
| 82 with self.assertRaises(ValueError): | 84 with self.assertRaises(ValueError): |
| 83 self._PressKey('UnknownKeyName') | 85 self._PressKey('UnknownKeyName') |
| OLD | NEW |