Index: telemetry/telemetry/core/android_action_runner_unittest.py |
diff --git a/telemetry/telemetry/core/android_action_runner_unittest.py b/telemetry/telemetry/core/android_action_runner_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6bd4f45e1c1a9a201a7a5f1af422e1af014092b5 |
--- /dev/null |
+++ b/telemetry/telemetry/core/android_action_runner_unittest.py |
@@ -0,0 +1,79 @@ |
+# Copyright 2017 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. |
+from telemetry import decorators |
rnephew (Reviews Here)
2017/04/26 01:01:26
nit: line between copyright and imports.
ssid
2017/04/26 01:12:46
Done.
|
+from telemetry.internal.actions import action_runner as action_runner_module |
+from telemetry.testing import tab_test_case |
+ |
+ |
+class AndroidActionRunnerInteractionTest(tab_test_case.TabTestCase): |
+ @decorators.Enabled('android') |
+ def testSmoothScrollBy(self): |
+ self.Navigate('page_with_swipeables.html') |
+ action_runner = action_runner_module.ActionRunner(self._tab, |
+ skip_waits=True) |
+ self.assertEquals(action_runner.EvaluateJavaScript('window.scrollY'), 0) |
+ self.assertEquals(action_runner.EvaluateJavaScript('window.scrollX'), 0) |
+ |
+ platform = action_runner.tab.browser.platform |
+ app_ui = action_runner.tab.browser.GetAppUi() |
+ view = app_ui.WaitForUiNode(resource_id='compositor_view_holder') |
+ scroll_start1 = 0.5 * (view.bounds.center + view.bounds.bottom_right) |
+ platform.android_action_runner.SmoothScrollBy( |
+ scroll_start1.x, scroll_start1.y, 'down', 300) |
+ self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') > 0) |
+ |
+ scroll_start2 = 0.5 * (view.bounds.center + view.bounds.top_left) |
+ platform.android_action_runner.SmoothScrollBy( |
+ scroll_start2.x, scroll_start2.y, 'up', 500) |
+ self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') == 0) |
+ |
+ @decorators.Enabled('android') |
+ def testInputSwipe(self): |
+ self.Navigate('page_with_swipeables.html') |
+ action_runner = action_runner_module.ActionRunner(self._tab, |
+ skip_waits=True) |
+ self.assertEquals(action_runner.EvaluateJavaScript('window.scrollY'), 0) |
+ self.assertEquals(action_runner.EvaluateJavaScript('window.scrollX'), 0) |
+ |
+ platform = action_runner.tab.browser.platform |
+ app_ui = action_runner.tab.browser.GetAppUi() |
+ view = app_ui.WaitForUiNode(resource_id='compositor_view_holder') |
+ scroll_start1 = 0.5 * (view.bounds.center + view.bounds.bottom_right) |
+ scroll_end1 = scroll_start1.y - 300 |
+ platform.android_action_runner.InputSwipe( |
+ scroll_start1.x, scroll_start1.y, scroll_start1.x, scroll_end1, 300) |
+ self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') > 0) |
+ |
+ scroll_start2 = 0.5 * (view.bounds.center + view.bounds.top_left) |
+ scroll_end2 = scroll_start2.y + 500 |
+ platform.android_action_runner.InputSwipe( |
+ scroll_start2.x, scroll_start2.y, scroll_start2.x, scroll_end2, 500) |
+ self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') == 0) |
+ |
+ @decorators.Enabled('android') |
+ def testInputText(self): |
+ self.Navigate('blank.html') |
+ self._tab.ExecuteJavaScript( |
+ '(function() {' |
+ ' var elem = document.createElement("textarea");' |
+ ' document.body.appendChild(elem);' |
+ ' elem.focus();' |
+ '})();') |
+ |
+ action_runner = action_runner_module.ActionRunner(self._tab, |
+ skip_waits=True) |
+ platform = action_runner.tab.browser.platform |
+ platform.android_action_runner.InputText('with spaces') |
+ action_runner.PressKey('Home') # |That is boring. |
rnephew (Reviews Here)
2017/04/26 01:01:26
Is this part realistic? Are Home and End keys real
ssid
2017/04/26 01:12:46
Actually not realistic. I was just trying to repli
|
+ platform.android_action_runner.InputText('Input ') |
+ action_runner.PressKey('End') # This is boring|. |
+ platform.android_action_runner.InputText(', even multiple spaces') |
+ |
+ # Check that the contents of the textarea is correct. It might take some |
+ # time until keystrokes are handled on Android. |
+ self._tab.WaitForJavaScriptCondition( |
+ ('document.querySelector("textarea").value === ' |
+ '"Input with spaces, even multiple spaces"'), |
+ timeout=5) |
+ |