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

Unified Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java

Issue 662493006: Replace flaky KeyUtils methods with more robust variant. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java
index 0abbe97bb2970f3b7a2e2cc41116a17cdce2e0f9..f421503f63ab880d38bc74cd01a5673f05237aac 100644
--- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/KeyUtils.java
@@ -5,61 +5,56 @@
package org.chromium.content.browser.test.util;
import android.app.Instrumentation;
+import android.os.SystemClock;
import android.view.KeyEvent;
+import android.view.View;
+
+import org.chromium.base.ThreadUtils;
/**
* Collection of keyboard utilities.
*/
public class KeyUtils {
/**
- * Press "Enter".
+ * Sends (synchronously) a single key down/up pair of events to the specified view.
+ * <p>
+ * Does not use the event injecting framework, but instead relies on
+ * {@link View#dispatchKeyEventPreIme(KeyEvent)} and {@link View#dispatchKeyEvent(KeyEvent)} of
+ * the view itself
+ * <p>
+ * The event injecting framework requires INJECT_EVENTS permission and that has been flaky on
+ * our perf bots. So until a root cause of the issue can be found, we should use this instead
+ * of the functionality provided by {@link #sendKeys(int...)}.
+ *
+ * @param i The application being instrumented.
+ * @param v The view to receive the key event.
+ * @param keyCode The keycode for the event to be issued.
*/
- public static void pressEnter(Instrumentation instrumentation) {
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_ENTER));
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
- KeyEvent.KEYCODE_ENTER));
- instrumentation.waitForIdleSync();
- }
+ public static void singleKeyEventView(Instrumentation i, final View v, int keyCode) {
+ long downTime = SystemClock.uptimeMillis();
+ long eventTime = SystemClock.uptimeMillis();
- /**
- * Press "Tab".
- */
- public static void pressTab(Instrumentation instrumentation) {
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_TAB));
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
- KeyEvent.KEYCODE_TAB));
- instrumentation.waitForIdleSync();
- }
+ final KeyEvent downEvent =
+ new KeyEvent(downTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0);
+ dispatchKeyEvent(i, v, downEvent);
- /**
- * Press "Backspace".
- */
- public static void pressBackspace(Instrumentation instrumentation) {
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_DEL));
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
- KeyEvent.KEYCODE_DEL));
- instrumentation.waitForIdleSync();
+ downTime = SystemClock.uptimeMillis();
+ eventTime = SystemClock.uptimeMillis();
+ final KeyEvent upEvent =
+ new KeyEvent(downTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0);
+ dispatchKeyEvent(i, v, upEvent);
}
- /**
- * Press "Back".
- */
- public static void pressBack(Instrumentation instrumentation) {
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_BACK));
- instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
- KeyEvent.KEYCODE_BACK));
- instrumentation.waitForIdleSync();
- }
-
- /**
- * Input a String.
- */
- public static void inputString(Instrumentation instrumentation, String text) {
- instrumentation.sendStringSync(text);
- instrumentation.waitForIdleSync();
+ private static void dispatchKeyEvent(final Instrumentation i, final View v,
+ final KeyEvent event) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ if (!v.dispatchKeyEventPreIme(event)) {
+ v.dispatchKeyEvent(event);
+ }
+ }
+ });
+ i.waitForIdleSync();
}
-}
+}
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698