KeyUtils.java revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright 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. 4 5package org.chromium.content.browser.test.util; 6 7import android.app.Instrumentation; 8import android.view.KeyEvent; 9 10/** 11 * Collection of keyboard utilities. 12 */ 13public class KeyUtils { 14 /** 15 * Press "Enter". 16 */ 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(); 23 } 24 25 /** 26 * Press "Tab". 27 */ 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(); 34 } 35 36 /** 37 * Press "Backspace". 38 */ 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(); 45 } 46 47 /** 48 * Press "Back". 49 */ 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(); 56 } 57 58 /** 59 * Input a String. 60 */ 61 public static void inputString(Instrumentation instrumentation, String text) { 62 instrumentation.sendStringSync(text); 63 instrumentation.waitForIdleSync(); 64 } 65} 66