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

Unified Diff: telemetry/telemetry/internal/actions/key_event_unittest.py

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 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
Index: telemetry/telemetry/internal/actions/key_event_unittest.py
diff --git a/telemetry/telemetry/internal/actions/key_event_unittest.py b/telemetry/telemetry/internal/actions/key_event_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..8721847ceccd51015c913e4ea1e2a101c53e7df5
--- /dev/null
+++ b/telemetry/telemetry/internal/actions/key_event_unittest.py
@@ -0,0 +1,85 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import time
+
+from telemetry.internal.actions import key_event
+from telemetry.internal.actions import utils
+from telemetry.testing import tab_test_case
+
+
+class KeyPressActionTest(tab_test_case.TabTestCase):
+
+ @property
+ def _scroll_position(self):
+ return self._tab.EvaluateJavaScript(
+ 'document.documentElement.scrollTop || document.body.scrollTop')
+
+ @property
+ def _window_height(self):
+ return self._tab.EvaluateJavaScript('__GestureCommon_GetWindowHeight()')
+
+ def _PressKey(self, key):
+ action = key_event.KeyPressAction(key)
+ action.WillRunAction(self._tab)
+ action.RunAction(self._tab)
+
+ def setUp(self):
+ tab_test_case.TabTestCase.setUp(self)
+ self.Navigate('blank.html')
+ utils.InjectJavaScript(self._tab, 'gesture_common.js')
+
+ def testPressEndAndHome(self):
+ # Make page taller than the window so it's scrollable.
+ self._tab.ExecuteJavaScript('document.body.style.height ='
+ '(3 * __GestureCommon_GetWindowHeight() + 1) + "px";')
+
+ # Check that the browser is currently showing the top of the page and that
+ # the page has non-trivial height.
+ self.assertEquals(0, self._scroll_position)
+ self.assertLess(50, self._window_height)
+
+ self._PressKey('End')
+
+ # Scroll happens *after* key press returns, so we need to wait a little.
+ time.sleep(1)
+
+ # We can only expect the bottom scroll position to be approximatly equal.
+ self.assertAlmostEqual(2 * self._window_height, self._scroll_position,
+ delta=20)
+
+ self._PressKey('Home')
+
+ # Scroll happens *after* key press returns, so we need to wait a little.
+ time.sleep(1)
+
+ self.assertEquals(self._scroll_position, 0)
+
+ def testTextEntry(self):
+ # Add an input box to the page.
+ self._tab.ExecuteJavaScript(
+ '(function() {'
+ ' var elem = document.createElement("textarea");'
+ ' document.body.appendChild(elem);'
+ ' elem.focus();'
+ '})();')
+
+ # Simulate typing a sentence.
+ for char in 'Hello, World!':
+ self._PressKey(char)
+
+ # Make changes to the sentence using special keys.
+ for _ in xrange(6):
+ self._PressKey('ArrowLeft')
+ self._PressKey('Backspace')
+ self._PressKey('Return')
+
+ # Check that the contents of the textarea is correct.
+ self.assertEquals('Hello,\nWorld!',
+ self._tab.EvaluateJavaScript(
+ 'document.querySelector("textarea").value'))
+
+ def testPressUnknownKey(self):
+ with self.assertRaises(ValueError):
+ self._PressKey('UnknownKeyName')
« no previous file with comments | « telemetry/telemetry/internal/actions/key_event.py ('k') | telemetry/telemetry/internal/actions/load_media.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698