From 90762d35a99e32ed22cdfb1f81252544ee22e30b Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Thu, 11 Feb 2010 20:07:17 -0800 Subject: Modify ActivityInstrumentationTestCase2 to not require hardcoded package name. Deprecate old constructor. Bug 2440167 --- .../test/ActivityInstrumentationTestCase.java | 24 ++++++++--------- .../test/ActivityInstrumentationTestCase2.java | 31 +++++++++++++++------- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'test-runner') diff --git a/test-runner/android/test/ActivityInstrumentationTestCase.java b/test-runner/android/test/ActivityInstrumentationTestCase.java index f6b31ad..d12ff6f 100644 --- a/test-runner/android/test/ActivityInstrumentationTestCase.java +++ b/test-runner/android/test/ActivityInstrumentationTestCase.java @@ -40,29 +40,26 @@ public abstract class ActivityInstrumentationTestCase boolean mInitialTouchMode = false; /** - * NOTE: The parameter pkg must refer to the package identifier of the - * package hosting the activity to be launched, which is specified in the AndroidManifest.xml - * file. This is not necessarily the same as the java package name. + * Creates an {@link ActivityInstrumentationTestCase} in non-touch mode. * - * @param pkg The package hosting the activity to be launched. - * @param activityClass The activity to test. + * @param pkg ignored - no longer in use. + * @param activityClass The activity to test. This must be a class in the instrumentation + * targetPackage specified in the AndroidManifest.xml */ public ActivityInstrumentationTestCase(String pkg, Class activityClass) { this(pkg, activityClass, false); } /** - * NOTE: The parameter pkg must refer to the package identifier of the - * package hosting the activity to be launched, which is specified in the AndroidManifest.xml - * file. This is not necessarily the same as the java package name. - * - * @param pkg The package hosting the activity to be launched. - * @param activityClass The activity to test. + * Creates an {@link ActivityInstrumentationTestCase}. + * + * @param pkg ignored - no longer in use. + * @param activityClass The activity to test. This must be a class in the instrumentation + * targetPackage specified in the AndroidManifest.xml * @param initialTouchMode true = in touch mode */ public ActivityInstrumentationTestCase(String pkg, Class activityClass, boolean initialTouchMode) { - mPackage = pkg; mActivityClass = activityClass; mInitialTouchMode = initialTouchMode; } @@ -77,7 +74,8 @@ public abstract class ActivityInstrumentationTestCase super.setUp(); // set initial touch mode getInstrumentation().setInTouchMode(mInitialTouchMode); - setActivity(launchActivity(mPackage, mActivityClass, null)); + final String targetPackageName = getInstrumentation().getTargetContext().getPackageName(); + setActivity(launchActivity(targetPackageName, mActivityClass, null)); } @Override diff --git a/test-runner/android/test/ActivityInstrumentationTestCase2.java b/test-runner/android/test/ActivityInstrumentationTestCase2.java index 679f634..e8570bd 100644 --- a/test-runner/android/test/ActivityInstrumentationTestCase2.java +++ b/test-runner/android/test/ActivityInstrumentationTestCase2.java @@ -40,21 +40,31 @@ import java.lang.reflect.Method; */ public abstract class ActivityInstrumentationTestCase2 extends ActivityTestCase { - String mPackage; Class mActivityClass; boolean mInitialTouchMode = false; Intent mActivityIntent = null; /** - * NOTE: The parameter pkg must refer to the package identifier of the - * package hosting the activity to be launched, which is specified in the AndroidManifest.xml - * file. This is not necessarily the same as the java package name. - * - * @param pkg The package hosting the activity to be launched. - * @param activityClass The activity to test. + * Creates an {@link ActivityInstrumentationTestCase2}. + * + * @param pkg ignored - no longer in use. + * @param activityClass The activity to test. This must be a class in the instrumentation + * targetPackage specified in the AndroidManifest.xml + * + * @deprecated use {@link #ActivityInstrumentationTestCase2(Class)} instead */ + @Deprecated public ActivityInstrumentationTestCase2(String pkg, Class activityClass) { - mPackage = pkg; + this(activityClass); + } + + /** + * Creates an {@link ActivityInstrumentationTestCase2}. + * + * @param activityClass The activity to test. This must be a class in the instrumentation + * targetPackage specified in the AndroidManifest.xml + */ + public ActivityInstrumentationTestCase2(Class activityClass) { mActivityClass = activityClass; } @@ -82,11 +92,12 @@ public abstract class ActivityInstrumentationTestCase2 if (a == null) { // set initial touch mode getInstrumentation().setInTouchMode(mInitialTouchMode); + final String targetPackage = getInstrumentation().getTargetContext().getPackageName(); // inject custom intent, if provided if (mActivityIntent == null) { - a = launchActivity(mPackage, mActivityClass, null); + a = launchActivity(targetPackage, mActivityClass, null); } else { - a = launchActivityWithIntent(mPackage, mActivityClass, mActivityIntent); + a = launchActivityWithIntent(targetPackage, mActivityClass, mActivityIntent); } setActivity(a); } -- cgit v1.1