summaryrefslogtreecommitdiffstats
path: root/tests/Compatibility
diff options
context:
space:
mode:
authorTsu Chiang Chuang <tsu@google.com>2013-04-30 15:58:04 -0700
committerTsu Chiang Chuang <tsu@google.com>2013-05-01 07:54:48 -0700
commit14c716be79b0135f6e0a22e22f432f5aacde2f21 (patch)
tree00d5b7d2672e1d68eecbc915056acfdf8d95dabc /tests/Compatibility
parentf0e8c78a11c43f23ea314166707039e2c4b5361f (diff)
downloadframeworks_base-14c716be79b0135f6e0a22e22f432f5aacde2f21.zip
frameworks_base-14c716be79b0135f6e0a22e22f432f5aacde2f21.tar.gz
frameworks_base-14c716be79b0135f6e0a22e22f432f5aacde2f21.tar.bz2
Make sure the app is still app after launching.
Bug:8755950 Change-Id: Ie30d84cb94787d8b2e7bdc65e329a311581f4a3f
Diffstat (limited to 'tests/Compatibility')
-rw-r--r--tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java75
1 files changed, 61 insertions, 14 deletions
diff --git a/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java b/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
index 7ae0fb8..f5c4c34 100644
--- a/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
+++ b/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
@@ -18,9 +18,12 @@ package com.android.compatibilitytest;
import android.app.ActivityManager;
import android.app.ActivityManager.ProcessErrorStateInfo;
+import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.test.InstrumentationTestCase;
import android.util.Log;
@@ -28,9 +31,11 @@ import android.util.Log;
import junit.framework.Assert;
import java.util.Collection;
+import java.util.List;
/**
- * Application Compatibility Test that launches an application and detects crashes.
+ * Application Compatibility Test that launches an application and detects
+ * crashes.
*/
public class AppCompatibility extends InstrumentationTestCase {
@@ -49,10 +54,10 @@ public class AppCompatibility extends InstrumentationTestCase {
private Bundle mArgs;
@Override
- public void setUp() throws Exception{
+ public void setUp() throws Exception {
super.setUp();
mRunner = (AppCompatibilityRunner) getInstrumentation();
- assertNotNull("Could not fetch InstrumentationTestRunner.",mRunner);
+ assertNotNull("Could not fetch InstrumentationTestRunner.", mRunner);
mContext = mRunner.getTargetContext();
Assert.assertNotNull("Could not get the Context", mContext);
@@ -83,7 +88,9 @@ public class AppCompatibility extends InstrumentationTestCase {
}
/**
- * Actual test case that launches the package and throws an exception on the first error.
+ * Actual test case that launches the package and throws an exception on the
+ * first error.
+ *
* @throws Exception
*/
public void testAppStability() throws Exception {
@@ -91,9 +98,11 @@ public class AppCompatibility extends InstrumentationTestCase {
if (packageName != null) {
Log.d(TAG, "Launching app " + packageName);
Collection<ProcessErrorStateInfo> err = launchActivity(packageName);
- // Make sure there are no errors when launching the application, otherwise raise an
+ // Make sure there are no errors when launching the application,
+ // otherwise raise an
// exception with the first error encountered.
assertNull(getFirstError(err), err);
+ assertTrue("App crashed after launch.", processStillUp(packageName));
} else {
Log.d(TAG, "Missing argument, use " + PACKAGE_TO_LAUNCH +
" to specify the package to launch");
@@ -102,6 +111,7 @@ public class AppCompatibility extends InstrumentationTestCase {
/**
* Gets the first error in collection and return the long message for it.
+ *
* @param in {@link Collection} of {@link ProcessErrorStateInfo} to parse.
* @return {@link String} the long message of the error.
*/
@@ -118,8 +128,11 @@ public class AppCompatibility extends InstrumentationTestCase {
/**
* Launches and activity and queries for errors.
- * @param packageName {@link String} the package name of the application to launch.
- * @return {@link Collection} of {@link ProcessErrorStateInfo} detected during the app launch.
+ *
+ * @param packageName {@link String} the package name of the application to
+ * launch.
+ * @return {@link Collection} of {@link ProcessErrorStateInfo} detected
+ * during the app launch.
*/
private Collection<ProcessErrorStateInfo> launchActivity(String packageName) {
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
@@ -129,14 +142,20 @@ public class AppCompatibility extends InstrumentationTestCase {
Intent intent = mPackageManager.getLaunchIntentForPackage(packageName);
// Skip if the apk does not have a launch intent.
if (intent == null) {
+ Log.d(TAG, "Skipping " + packageName + "; missing launch intent");
return null;
}
- // We check for any Crash or ANR dialogs that are already up, and we ignore them. This is
- // so that we don't report crashes that were caused by prior apps (which those particular
- // tests should have caught and reported already). Otherwise, test failures would cascade
- // from the initial broken app to many/all of the tests following that app's launch.
- final Collection<ProcessErrorStateInfo> preErr = mActivityManager.getProcessesInErrorState();
+ // We check for any Crash or ANR dialogs that are already up, and we
+ // ignore them. This is
+ // so that we don't report crashes that were caused by prior apps (which
+ // those particular
+ // tests should have caught and reported already). Otherwise, test
+ // failures would cascade
+ // from the initial broken app to many/all of the tests following that
+ // app's launch.
+ final Collection<ProcessErrorStateInfo> preErr =
+ mActivityManager.getProcessesInErrorState();
// Launch Activity
mContext.startActivity(intent);
@@ -155,15 +174,43 @@ public class AppCompatibility extends InstrumentationTestCase {
// ignore
}
- // See if there are any errors. We wait until down here to give ANRs as much time as
+ // See if there are any errors. We wait until down here to give ANRs as
+ // much time as
// possible to occur.
final Collection<ProcessErrorStateInfo> postErr =
mActivityManager.getProcessesInErrorState();
- // Take the difference between the error processes we see now, and the ones that were
+ // Take the difference between the error processes we see now, and the
+ // ones that were
// present when we started
if (preErr != null && postErr != null) {
postErr.removeAll(preErr);
}
return postErr;
}
+
+ /**
+ * Determine if a given package is still running.
+ *
+ * @param packageName {@link String} package to look for
+ * @return True if package is running, false otherwise.
+ */
+ private boolean processStillUp(String packageName) {
+ try {
+ PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, 0);
+ String processName = packageInfo.applicationInfo.processName;
+ List<RunningAppProcessInfo> runningApps = mActivityManager.getRunningAppProcesses();
+ for (RunningAppProcessInfo app : runningApps) {
+ if (app.processName.equalsIgnoreCase(processName)) {
+ Log.d(TAG, "Found process " + app.processName);
+ return true;
+ }
+ }
+ Log.d(TAG, "Failed to find process " + processName + " with package name "
+ + packageName);
+ } catch (NameNotFoundException e) {
+ Log.w(TAG, "Failed to find package " + packageName);
+ return false;
+ }
+ return false;
+ }
}