diff options
Diffstat (limited to 'com/android/uiautomator/testrunner/UiAutomatorTestCase.java')
-rw-r--r-- | com/android/uiautomator/testrunner/UiAutomatorTestCase.java | 106 |
1 files changed, 30 insertions, 76 deletions
diff --git a/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/com/android/uiautomator/testrunner/UiAutomatorTestCase.java index 3d5476d0..7c9aeded 100644 --- a/com/android/uiautomator/testrunner/UiAutomatorTestCase.java +++ b/com/android/uiautomator/testrunner/UiAutomatorTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2013 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,55 +16,24 @@ package com.android.uiautomator.testrunner; -import android.content.Context; +import android.app.Instrumentation; import android.os.Bundle; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.SystemClock; -import android.view.inputmethod.InputMethodInfo; +import android.test.InstrumentationTestCase; -import com.android.internal.view.IInputMethodManager; +import com.android.uiautomator.core.InstrumentationUiAutomatorBridge; import com.android.uiautomator.core.UiDevice; -import junit.framework.TestCase; - -import java.util.List; - /** - * 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 + * UI Automator test case that is executed on the device. * @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 TestCase { +public class UiAutomatorTestCase extends InstrumentationTestCase { - 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 @@ -72,7 +41,7 @@ public class UiAutomatorTestCase extends TestCase { * @since API Level 16 */ public UiDevice getUiDevice() { - return mUiDevice; + return UiDevice.getInstance(); } /** @@ -85,34 +54,43 @@ public class UiAutomatorTestCase extends TestCase { 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; } /** - * package private - * @param uiDevice - */ - void setUiDevice(UiDevice uiDevice) { - mUiDevice = uiDevice; - } - - /** - * package private - * @param params + * Initializes this test case. + * + * @param params Instrumentation arguments. */ - void setParams(Bundle params) { + void initialize(Bundle params) { mParams = params; - } - void setAutomationSupport(IAutomationSupport automationSupport) { - mAutomationSupport = automationSupport; + // 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)); + } + + UiDevice.getInstance().initialize(new InstrumentationUiAutomatorBridge( + getInstrumentation().getContext(), + getInstrumentation().getUiAutomation())); } /** @@ -123,28 +101,4 @@ public class UiAutomatorTestCase extends TestCase { 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. - } } |