diff options
Diffstat (limited to 'test-runner')
18 files changed, 290 insertions, 71 deletions
diff --git a/test-runner/src/android/test/ActivityInstrumentationTestCase.java b/test-runner/src/android/test/ActivityInstrumentationTestCase.java index d12ff6f..a59ee35 100644 --- a/test-runner/src/android/test/ActivityInstrumentationTestCase.java +++ b/test-runner/src/android/test/ActivityInstrumentationTestCase.java @@ -18,8 +18,6 @@ package android.test; import android.app.Activity; -import java.lang.reflect.Field; - /** * This class provides functional testing of a single activity. The activity under test will * be created using the system infrastructure (by calling InstrumentationTestCase.launchActivity()) diff --git a/test-runner/src/android/test/ApplicationTestCase.java b/test-runner/src/android/test/ApplicationTestCase.java index ae5fa4d..f093181 100644 --- a/test-runner/src/android/test/ApplicationTestCase.java +++ b/test-runner/src/android/test/ApplicationTestCase.java @@ -16,8 +16,6 @@ package android.test; -import java.lang.reflect.Field; - import android.app.Application; import android.app.Instrumentation; import android.content.Context; diff --git a/test-runner/src/android/test/InstrumentationUtils.java b/test-runner/src/android/test/InstrumentationUtils.java index 4c59097..1a7002a 100644 --- a/test-runner/src/android/test/InstrumentationUtils.java +++ b/test-runner/src/android/test/InstrumentationUtils.java @@ -16,8 +16,6 @@ package android.test; -import java.lang.reflect.Field; - /** * * The InstrumentationUtils class has all the utility functions needed for diff --git a/test-runner/src/android/test/IsolatedContext.java b/test-runner/src/android/test/IsolatedContext.java index bc00f68..f971b5d 100644 --- a/test-runner/src/android/test/IsolatedContext.java +++ b/test-runner/src/android/test/IsolatedContext.java @@ -39,8 +39,6 @@ import android.os.Handler; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; import java.util.List; diff --git a/test-runner/src/android/test/LaunchPerformanceBase.java b/test-runner/src/android/test/LaunchPerformanceBase.java index c324446..d423e62 100644 --- a/test-runner/src/android/test/LaunchPerformanceBase.java +++ b/test-runner/src/android/test/LaunchPerformanceBase.java @@ -19,13 +19,6 @@ package android.test; import android.app.Instrumentation; import android.content.Intent; import android.os.Bundle; -import android.os.RemoteException; -import android.os.Debug; -import android.os.Process; -import android.os.ServiceManager; -import android.os.SystemClock; - -import java.util.ArrayList; /** diff --git a/test-runner/src/android/test/MoreAsserts.java b/test-runner/src/android/test/MoreAsserts.java index 83cc420..3364895 100644 --- a/test-runner/src/android/test/MoreAsserts.java +++ b/test-runner/src/android/test/MoreAsserts.java @@ -16,7 +16,6 @@ package android.test; -import com.google.android.collect.Lists; import junit.framework.Assert; import java.util.Arrays; @@ -129,6 +128,33 @@ public final class MoreAsserts { } /** + * @hide Asserts that array {@code actual} is the same size and every element equals + * those in array {@code expected}. On failure, message indicates first + * specific element mismatch. + */ + public static void assertEquals( + String message, long[] expected, long[] actual) { + if (expected.length != actual.length) { + failWrongLength(message, expected.length, actual.length); + } + for (int i = 0; i < expected.length; i++) { + if (expected[i] != actual[i]) { + failWrongElement(message, i, expected[i], actual[i]); + } + } + } + + /** + * @hide Asserts that array {@code actual} is the same size and every element equals + * those in array {@code expected}. On failure, message indicates first + * specific element mismatch. + */ + public static void assertEquals(long[] expected, long[] actual) { + assertEquals(null, expected, actual); + } + + + /** * Asserts that array {@code actual} is the same size and every element equals * those in array {@code expected}. On failure, message indicates first * specific element mismatch. diff --git a/test-runner/src/android/test/ProviderTestCase.java b/test-runner/src/android/test/ProviderTestCase.java index 1b323cf..4108f34 100644 --- a/test-runner/src/android/test/ProviderTestCase.java +++ b/test-runner/src/android/test/ProviderTestCase.java @@ -67,9 +67,8 @@ public abstract class ProviderTestCase<T extends ContentProvider> filenamePrefix); mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); - mProvider = mProviderClass.newInstance(); - mProvider.attachInfoForTesting(mProviderContext, null); - assertNotNull(mProvider); + mProvider = ProviderTestCase2.createProviderForTest( + mProviderContext, mProviderClass, mProviderAuthority); mResolver.addProvider(mProviderAuthority, getProvider()); } @@ -107,8 +106,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> resolver, targetContextWrapper); DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); - T provider = providerClass.newInstance(); - provider.attachInfoForTesting(context, null); + T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority); resolver.addProvider(authority, provider); return resolver; diff --git a/test-runner/src/android/test/ProviderTestCase2.java b/test-runner/src/android/test/ProviderTestCase2.java index dcd089d..1fa633e 100644 --- a/test-runner/src/android/test/ProviderTestCase2.java +++ b/test-runner/src/android/test/ProviderTestCase2.java @@ -19,6 +19,7 @@ package android.test; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.Context; +import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.test.mock.MockContext; import android.test.mock.MockContentResolver; @@ -138,14 +139,24 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro getContext(), // The context that file methods are delegated to filenamePrefix); mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); - - mProvider = mProviderClass.newInstance(); - mProvider.attachInfoForTesting(mProviderContext, null); - assertNotNull(mProvider); + mProvider = createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority); mResolver.addProvider(mProviderAuthority, getProvider()); } /** + * Creates and sets up a new instance of the provider. + */ + static <T extends ContentProvider> T createProviderForTest( + Context context, Class<T> providerClass, String authority) + throws IllegalAccessException, InstantiationException { + T instance = providerClass.newInstance(); + ProviderInfo providerInfo = new ProviderInfo(); + providerInfo.authority = authority; + instance.attachInfoForTesting(context, providerInfo); + return instance; + } + + /** * Tears down the environment for the test fixture. * <p> * Calls {@link android.content.ContentProvider#shutdown()} on the @@ -218,8 +229,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro Context context = new IsolatedContext(resolver, targetContextWrapper); DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); - T provider = providerClass.newInstance(); - provider.attachInfoForTesting(context, null); + T provider = createProviderForTest(context, providerClass, authority); resolver.addProvider(authority, provider); return resolver; diff --git a/test-runner/src/android/test/ServiceTestCase.java b/test-runner/src/android/test/ServiceTestCase.java index d8ced38..ba20c09 100644 --- a/test-runner/src/android/test/ServiceTestCase.java +++ b/test-runner/src/android/test/ServiceTestCase.java @@ -18,14 +18,11 @@ package android.test; import android.app.Application; import android.app.Service; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.IBinder; -import android.os.RemoteException; import android.test.mock.MockApplication; -import java.lang.reflect.Field; import java.util.Random; /** @@ -263,6 +260,7 @@ public abstract class ServiceTestCase<T extends Service> extends AndroidTestCase } if (mServiceCreated) { mService.onDestroy(); + mServiceCreated = false; } } diff --git a/test-runner/src/android/test/SingleLaunchActivityTestCase.java b/test-runner/src/android/test/SingleLaunchActivityTestCase.java index 79c554a..72c93ce 100644 --- a/test-runner/src/android/test/SingleLaunchActivityTestCase.java +++ b/test-runner/src/android/test/SingleLaunchActivityTestCase.java @@ -17,8 +17,6 @@ package android.test; import android.app.Activity; -import android.view.IWindowManager; -import android.os.ServiceManager; /** * If you would like to test a single activity with an diff --git a/test-runner/src/android/test/TouchUtils.java b/test-runner/src/android/test/TouchUtils.java index 0fbffcd..1b854b0 100644 --- a/test-runner/src/android/test/TouchUtils.java +++ b/test-runner/src/android/test/TouchUtils.java @@ -120,19 +120,13 @@ public class TouchUtils { */ public static void scrollToBottom(InstrumentationTestCase test, Activity activity, ViewGroup v) { - View firstChild; - int firstId = Integer.MIN_VALUE; - int firstTop = Integer.MIN_VALUE; - int prevId; - int prevTop; + ViewStateSnapshot prev; + ViewStateSnapshot next = new ViewStateSnapshot(v); do { - prevId = firstId; - prevTop = firstTop; + prev = next; TouchUtils.dragQuarterScreenUp(test, activity); - firstChild = v.getChildAt(0); - firstId = firstChild.getId(); - firstTop = firstChild.getTop(); - } while ((prevId != firstId) || (prevTop != firstTop)); + next = new ViewStateSnapshot(v); + } while (!prev.equals(next)); } /** @@ -160,19 +154,13 @@ public class TouchUtils { * @param v The ViewGroup that should be dragged */ public static void scrollToTop(InstrumentationTestCase test, Activity activity, ViewGroup v) { - View firstChild; - int firstId = Integer.MIN_VALUE; - int firstTop = Integer.MIN_VALUE; - int prevId; - int prevTop; + ViewStateSnapshot prev; + ViewStateSnapshot next = new ViewStateSnapshot(v); do { - prevId = firstId; - prevTop = firstTop; + prev = next; TouchUtils.dragQuarterScreenDown(test, activity); - firstChild = v.getChildAt(0); - firstId = firstChild.getId(); - firstTop = firstChild.getTop(); - } while ((prevId != firstId) || (prevTop != firstTop)); + next = new ViewStateSnapshot(v); + } while (!prev.equals(next)); } /** @@ -776,15 +764,12 @@ public class TouchUtils { MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0); inst.sendPointerSync(event); - inst.waitForIdleSync(); - for (int i = 0; i < stepCount; ++i) { y += yStep; x += xStep; eventTime = SystemClock.uptimeMillis(); event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x, y, 0); inst.sendPointerSync(event); - inst.waitForIdleSync(); } eventTime = SystemClock.uptimeMillis(); @@ -792,4 +777,51 @@ public class TouchUtils { inst.sendPointerSync(event); inst.waitForIdleSync(); } + + private static class ViewStateSnapshot { + final View mFirst; + final View mLast; + final int mFirstTop; + final int mLastBottom; + final int mChildCount; + private ViewStateSnapshot(ViewGroup viewGroup) { + mChildCount = viewGroup.getChildCount(); + if (mChildCount == 0) { + mFirst = mLast = null; + mFirstTop = mLastBottom = Integer.MIN_VALUE; + } else { + mFirst = viewGroup.getChildAt(0); + mLast = viewGroup.getChildAt(mChildCount - 1); + mFirstTop = mFirst.getTop(); + mLastBottom = mLast.getBottom(); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final ViewStateSnapshot that = (ViewStateSnapshot) o; + return mFirstTop == that.mFirstTop && + mLastBottom == that.mLastBottom && + mFirst == that.mFirst && + mLast == that.mLast && + mChildCount == that.mChildCount; + } + + @Override + public int hashCode() { + int result = mFirst != null ? mFirst.hashCode() : 0; + result = 31 * result + (mLast != null ? mLast.hashCode() : 0); + result = 31 * result + mFirstTop; + result = 31 * result + mLastBottom; + result = 31 * result + mChildCount; + return result; + } + } } diff --git a/test-runner/src/android/test/mock/MockContext.java b/test-runner/src/android/test/mock/MockContext.java index 0d9cd18..46c81b6 100644 --- a/test-runner/src/android/test/mock/MockContext.java +++ b/test-runner/src/android/test/mock/MockContext.java @@ -175,6 +175,11 @@ public class MockContext extends Context { } @Override + public File getNoBackupFilesDir() { + throw new UnsupportedOperationException(); + } + + @Override public File getExternalFilesDir(String type) { throw new UnsupportedOperationException(); } @@ -190,6 +195,11 @@ public class MockContext extends Context { } @Override + public File getCodeCacheDir() { + throw new UnsupportedOperationException(); + } + + @Override public File getExternalCacheDir() { throw new UnsupportedOperationException(); } @@ -350,7 +360,17 @@ public class MockContext extends Context { throw new UnsupportedOperationException(); } + /** @hide */ + @Override + public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, int appOp, BroadcastReceiver resultReceiver, + Handler scheduler, + int initialCode, String initialData, Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + @Override + public void sendStickyBroadcast(Intent intent) { throw new UnsupportedOperationException(); } @@ -552,6 +572,13 @@ public class MockContext extends Context { /** {@hide} */ @Override + public Context createApplicationContext(ApplicationInfo application, int flags) + throws PackageManager.NameNotFoundException { + return null; + } + + /** {@hide} */ + @Override public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) throws PackageManager.NameNotFoundException { throw new UnsupportedOperationException(); @@ -575,7 +602,7 @@ public class MockContext extends Context { @Override public boolean isRestricted() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } /** @hide */ @@ -598,4 +625,9 @@ public class MockContext extends Context { public File[] getExternalCacheDirs() { throw new UnsupportedOperationException(); } + + @Override + public File[] getExternalMediaDirs() { + throw new UnsupportedOperationException(); + } } diff --git a/test-runner/src/android/test/mock/MockCursor.java b/test-runner/src/android/test/mock/MockCursor.java index 5b8a4f4..a37c6eb 100644 --- a/test-runner/src/android/test/mock/MockCursor.java +++ b/test-runner/src/android/test/mock/MockCursor.java @@ -24,8 +24,6 @@ import android.database.DataSetObserver; import android.net.Uri; import android.os.Bundle; -import java.util.Map; - /** * <P> * A mock {@link android.database.Cursor} class that isolates the test code from real diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java index 661bd41..afe1d5d 100644 --- a/test-runner/src/android/test/mock/MockPackageManager.java +++ b/test-runner/src/android/test/mock/MockPackageManager.java @@ -16,6 +16,7 @@ package android.test.mock; +import android.app.PackageInstallObserver; import android.content.ComponentName; import android.content.Intent; import android.content.IntentFilter; @@ -30,8 +31,11 @@ import android.content.pm.IPackageInstallObserver; import android.content.pm.IPackageMoveObserver; import android.content.pm.IPackageStatsObserver; import android.content.pm.InstrumentationInfo; +import android.content.pm.KeySet; import android.content.pm.ManifestDigest; import android.content.pm.PackageInfo; +import android.content.pm.PackageInstaller; +import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; @@ -40,13 +44,11 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; -import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.content.res.XmlResourceParser; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.os.Binder; -import android.os.RemoteException; import android.os.UserHandle; import java.util.List; @@ -80,6 +82,12 @@ public class MockPackageManager extends PackageManager { } @Override + public Intent getLeanbackLaunchIntentForPackage(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public int[] getPackageGids(String packageName) throws NameNotFoundException { throw new UnsupportedOperationException(); } @@ -299,6 +307,12 @@ public class MockPackageManager extends PackageManager { throw new UnsupportedOperationException(); } + /** @hide */ + @Override + public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) { + throw new UnsupportedOperationException(); + } + @Override public List<ProviderInfo> queryContentProviders(String processName, int uid, int flags) { throw new UnsupportedOperationException(); @@ -338,6 +352,27 @@ public class MockPackageManager extends PackageManager { } @Override + public Drawable getActivityBanner(ComponentName activityName) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityBanner(Intent intent) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationBanner(ApplicationInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationBanner(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override public Drawable getApplicationIcon(ApplicationInfo info) { throw new UnsupportedOperationException(); } @@ -368,6 +403,29 @@ public class MockPackageManager extends PackageManager { } @Override + public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, + Rect badgeLocation, + int badgeDensity) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Drawable getUserBadgeForDensity(UserHandle user, int density) { + throw new UnsupportedOperationException(); + } + + @Override + public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override public CharSequence getText(String packageName, int resid, ApplicationInfo appInfo) { throw new UnsupportedOperationException(); } @@ -582,6 +640,30 @@ public class MockPackageManager extends PackageManager { throw new UnsupportedOperationException(); } + /** @hide */ + @Override + public KeySet getKeySetByAlias(String packageName, String alias) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public KeySet getSigningKeySet(String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isSignedBy(String packageName, KeySet ks) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isSignedByExactly(String packageName, KeySet ks) { + throw new UnsupportedOperationException(); + } + /** * @hide */ @@ -606,7 +688,7 @@ public class MockPackageManager extends PackageManager { * @hide */ @Override - public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked, + public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden, UserHandle user) { return false; } @@ -615,7 +697,7 @@ public class MockPackageManager extends PackageManager { * @hide */ @Override - public boolean getApplicationBlockedSettingAsUser(String packageName, UserHandle user) { + public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) { return false; } @@ -646,4 +728,69 @@ public class MockPackageManager extends PackageManager { public VerifierDeviceIdentity getVerifierDeviceIdentity() { throw new UnsupportedOperationException(); } + + /** + * @hide + */ + @Override + public void installPackage(Uri packageURI, PackageInstallObserver observer, + int flags, String installerPackageName) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void installPackageWithVerification(Uri packageURI, + PackageInstallObserver observer, int flags, String installerPackageName, + Uri verificationURI, ManifestDigest manifestDigest, + ContainerEncryptionParams encryptionParams) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void installPackageWithVerificationAndEncryption(Uri packageURI, + PackageInstallObserver observer, int flags, String installerPackageName, + VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId, + int flags) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void clearCrossProfileIntentFilters(int sourceUserId) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + public PackageInstaller getPackageInstaller() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public boolean isPackageAvailable(String packageName) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } } diff --git a/test-runner/src/android/test/suitebuilder/TestSuiteBuilder.java b/test-runner/src/android/test/suitebuilder/TestSuiteBuilder.java index 28f7216..8c89489 100644 --- a/test-runner/src/android/test/suitebuilder/TestSuiteBuilder.java +++ b/test-runner/src/android/test/suitebuilder/TestSuiteBuilder.java @@ -29,8 +29,6 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import java.lang.reflect.InvocationTargetException; -import java.util.Enumeration; import java.util.List; import java.util.Set; import java.util.HashSet; diff --git a/test-runner/src/junit/runner/FailureDetailView.java b/test-runner/src/junit/runner/FailureDetailView.java index 1b8365a..c846191 100644 --- a/test-runner/src/junit/runner/FailureDetailView.java +++ b/test-runner/src/junit/runner/FailureDetailView.java @@ -12,7 +12,7 @@ import junit.framework.*; public interface FailureDetailView { // The following definition was removed for compatibility with Android // libraries. - // /** + // /** // * Returns the component used to present the TraceView // */ // public Component getComponent(); diff --git a/test-runner/src/junit/runner/LoadingTestCollector.java b/test-runner/src/junit/runner/LoadingTestCollector.java index 489d9d6..9101900 100644 --- a/test-runner/src/junit/runner/LoadingTestCollector.java +++ b/test-runner/src/junit/runner/LoadingTestCollector.java @@ -1,7 +1,6 @@ package junit.runner; import java.lang.reflect.*; -import junit.runner.*; import junit.framework.*; /** diff --git a/test-runner/src/junit/runner/Sorter.java b/test-runner/src/junit/runner/Sorter.java index 7731f66..8d9341d 100644 --- a/test-runner/src/junit/runner/Sorter.java +++ b/test-runner/src/junit/runner/Sorter.java @@ -2,8 +2,6 @@ package junit.runner; import java.util.*; -import junit.runner.*; - /** * A custom quick sort with support to customize the swap behaviour. * NOTICE: We can't use the the sorting support from the JDK 1.2 collection |