1 // Copyright (c) 2012 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.
5 package org.chromium.content.browser.test.util;
7 import android.app.Instrumentation;
8 import android.view.KeyEvent;
11 * Collection of keyboard utilities.
13 public class KeyUtils {
17 public static void pressEnter(Instrumentation instrumentation) {
18 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
19 KeyEvent.KEYCODE_ENTER));
20 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
21 KeyEvent.KEYCODE_ENTER));
22 instrumentation.waitForIdleSync();
28 public static void pressTab(Instrumentation instrumentation) {
29 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
30 KeyEvent.KEYCODE_TAB));
31 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
32 KeyEvent.KEYCODE_TAB));
33 instrumentation.waitForIdleSync();
39 public static void pressBackspace(Instrumentation instrumentation) {
40 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
41 KeyEvent.KEYCODE_DEL));
42 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
43 KeyEvent.KEYCODE_DEL));
44 instrumentation.waitForIdleSync();
50 public static void pressBack(Instrumentation instrumentation) {
51 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
52 KeyEvent.KEYCODE_BACK));
53 instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
54 KeyEvent.KEYCODE_BACK));
55 instrumentation.waitForIdleSync();
61 public static void inputString(Instrumentation instrumentation, String text) {
62 instrumentation.sendStringSync(text);
63 instrumentation.waitForIdleSync();