summaryrefslogtreecommitdiff
path: root/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'com/android/uiautomator/testrunner/UiAutomatorTestCase.java')
-rw-r--r--com/android/uiautomator/testrunner/UiAutomatorTestCase.java106
1 files changed, 76 insertions, 30 deletions
diff --git a/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
index 7c9aeded..3d5476d0 100644
--- a/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
+++ b/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,24 +16,55 @@
package com.android.uiautomator.testrunner;
-import android.app.Instrumentation;
+import android.content.Context;
import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.SystemClock;
-import android.test.InstrumentationTestCase;
+import android.view.inputmethod.InputMethodInfo;
-import com.android.uiautomator.core.InstrumentationUiAutomatorBridge;
+import com.android.internal.view.IInputMethodManager;
import com.android.uiautomator.core.UiDevice;
+import junit.framework.TestCase;
+
+import java.util.List;
+
/**
- * UI Automator test case that is executed on the device.
+ * UI automation test should extend this class. This class provides access
+ * to the following:
+ * {@link UiDevice} instance
+ * {@link Bundle} for command line parameters.
+ * @since API Level 16
* @deprecated New tests should be written using UI Automator 2.0 which is available as part of the
* Android Testing Support Library.
*/
@Deprecated
-public class UiAutomatorTestCase extends InstrumentationTestCase {
+public class UiAutomatorTestCase extends TestCase {
+ private static final String DISABLE_IME = "disable_ime";
+ private static final String DUMMY_IME_PACKAGE = "com.android.testing.dummyime";
+ private UiDevice mUiDevice;
private Bundle mParams;
private IAutomationSupport mAutomationSupport;
+ private boolean mShouldDisableIme = false;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mShouldDisableIme = "true".equals(mParams.getString(DISABLE_IME));
+ if (mShouldDisableIme) {
+ setDummyIme();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (mShouldDisableIme) {
+ restoreActiveIme();
+ }
+ super.tearDown();
+ }
/**
* Get current instance of {@link UiDevice}. Works similar to calling the static
@@ -41,7 +72,7 @@ public class UiAutomatorTestCase extends InstrumentationTestCase {
* @since API Level 16
*/
public UiDevice getUiDevice() {
- return UiDevice.getInstance();
+ return mUiDevice;
}
/**
@@ -54,43 +85,34 @@ public class UiAutomatorTestCase extends InstrumentationTestCase {
return mParams;
}
- void setAutomationSupport(IAutomationSupport automationSupport) {
- mAutomationSupport = automationSupport;
- }
-
/**
* Provides support for running tests to report interim status
*
* @return IAutomationSupport
* @since API Level 16
- * @deprecated Use {@link Instrumentation#sendStatus(int, Bundle)} instead
*/
public IAutomationSupport getAutomationSupport() {
- if (mAutomationSupport == null) {
- mAutomationSupport = new InstrumentationAutomationSupport(getInstrumentation());
- }
return mAutomationSupport;
}
/**
- * Initializes this test case.
- *
- * @param params Instrumentation arguments.
+ * package private
+ * @param uiDevice
*/
- void initialize(Bundle params) {
- mParams = params;
+ void setUiDevice(UiDevice uiDevice) {
+ mUiDevice = uiDevice;
+ }
- // check if this is a monkey test mode
- String monkeyVal = mParams.getString("monkey");
- if (monkeyVal != null) {
- // only if the monkey key is specified, we alter the state of monkey
- // else we should leave things as they are.
- getInstrumentation().getUiAutomation().setRunAsMonkey(Boolean.valueOf(monkeyVal));
- }
+ /**
+ * package private
+ * @param params
+ */
+ void setParams(Bundle params) {
+ mParams = params;
+ }
- UiDevice.getInstance().initialize(new InstrumentationUiAutomatorBridge(
- getInstrumentation().getContext(),
- getInstrumentation().getUiAutomation()));
+ void setAutomationSupport(IAutomationSupport automationSupport) {
+ mAutomationSupport = automationSupport;
}
/**
@@ -101,4 +123,28 @@ public class UiAutomatorTestCase extends InstrumentationTestCase {
public void sleep(long ms) {
SystemClock.sleep(ms);
}
+
+ private void setDummyIme() throws RemoteException {
+ IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager
+ .getService(Context.INPUT_METHOD_SERVICE));
+ List<InputMethodInfo> infos = im.getInputMethodList();
+ String id = null;
+ for (InputMethodInfo info : infos) {
+ if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) {
+ id = info.getId();
+ }
+ }
+ if (id == null) {
+ throw new RuntimeException(String.format(
+ "Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE));
+ }
+ im.setInputMethod(null, id);
+ }
+
+ private void restoreActiveIme() throws RemoteException {
+ // TODO: figure out a way to restore active IME
+ // Currently retrieving active IME requires querying secure settings provider, which is hard
+ // to do without a Context; so the caveat here is that to make the post test device usable,
+ // the active IME needs to be manually switched.
+ }
}