summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2010-09-01 09:05:37 -0700
committerWu-cheng Li <wuchengli@google.com>2010-09-03 17:03:00 -0700
commit0e88af05305daa2276c91c7dea1461d7b6549f65 (patch)
treefa3882768461597a72c2542ade6f1903ade4c72a /tests/src
parent91561bdb6ab42d5a262201fb4044bdc5949ca07c (diff)
downloadLegacyCamera-0e88af05305daa2276c91c7dea1461d7b6549f65.zip
LegacyCamera-0e88af05305daa2276c91c7dea1461d7b6549f65.tar.gz
LegacyCamera-0e88af05305daa2276c91c7dea1461d7b6549f65.tar.bz2
Add the test for activity leak.
bug:2949181 Change-Id: I3a804f360611d8195ff5a9dc5046ad75789329b3
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/camera/functional/CameraTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/src/com/android/camera/functional/CameraTest.java b/tests/src/com/android/camera/functional/CameraTest.java
index 9eca03e..bf0bb64 100644
--- a/tests/src/com/android/camera/functional/CameraTest.java
+++ b/tests/src/com/android/camera/functional/CameraTest.java
@@ -1,5 +1,6 @@
package com.android.camera.functional;
+import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
@@ -7,11 +8,16 @@ import android.os.Process;
import android.provider.MediaStore;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
import java.io.File;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
public class CameraTest extends InstrumentationTestCase {
+ private static final String TAG = "CameraTest";
private static final String CAMERA_PACKAGE = "com.google.android.camera";
+ private static final String CAMERA_ACTIVITY = "com.android.camera.Camera";
private static final String CAMCORDER_ACTIVITY = "com.android.camera.VideoCamera";
@LargeTest
@@ -28,4 +34,35 @@ public class CameraTest extends InstrumentationTestCase {
assertEquals(-1, f.getCanonicalPath().indexOf("test_fd_leak.3gp"));
}
}
+
+ @LargeTest
+ public void testActivityLeak() throws Exception {
+ checkActivityLeak(CAMERA_ACTIVITY);
+ checkActivityLeak(CAMCORDER_ACTIVITY);
+ }
+
+ private void checkActivityLeak(String activityName) throws Exception {
+ final int TEST_COUNT = 5;
+ Intent intent = new Intent();
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClassName(CAMERA_PACKAGE, activityName);
+ ArrayList<WeakReference<Activity>> refs =
+ new ArrayList<WeakReference<Activity>>();
+ for (int i = 0; i < TEST_COUNT; i++) {
+ Activity activity = getInstrumentation().startActivitySync(intent);
+ refs.add(new WeakReference<Activity>(activity));
+ activity.finish();
+ getInstrumentation().waitForIdleSync();
+ activity = null;
+ }
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().runFinalization();
+ Runtime.getRuntime().gc();
+ int refCount = 0;
+ for (WeakReference<Activity> c: refs) {
+ if (c.get() != null) refCount++;
+ }
+ // If applications are leaking activity, every reference is reachable.
+ assertTrue(refCount != TEST_COUNT);
+ }
}