Merge "Fix TextViewTests#testMarquee for Landscape Mode" into eclair
diff --git a/tests/res/layout/gridlayout_anim_controller_layout.xml b/tests/res/layout/gridlayout_anim_controller_layout.xml
index fdc1033..000389e 100644
--- a/tests/res/layout/gridlayout_anim_controller_layout.xml
+++ b/tests/res/layout/gridlayout_anim_controller_layout.xml
@@ -21,7 +21,7 @@
android:padding="10dp"
android:verticalSpacing="20dp"
android:horizontalSpacing="20dp"
- android:numColumns="auto_fit"
+ android:numColumns="3"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
diff --git a/tests/src/android/app/cts/ActivityTestsBase.java b/tests/src/android/app/cts/ActivityTestsBase.java
index 7bbedd8..faf74f0 100644
--- a/tests/src/android/app/cts/ActivityTestsBase.java
+++ b/tests/src/android/app/cts/ActivityTestsBase.java
@@ -21,12 +21,20 @@
import android.content.Intent;
import android.test.AndroidTestCase;
import android.test.PerformanceTestCase;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.List;
public class ActivityTestsBase extends AndroidTestCase implements PerformanceTestCase,
LaunchpadActivity.CallingTest {
public static final String PERMISSION_GRANTED = "android.app.cts.permission.TEST_GRANTED";
public static final String PERMISSION_DENIED = "android.app.cts.permission.TEST_DENIED";
+ private static final String TAG = "ActivityTestsBase";
+
+ private static final int TIMEOUT_MS = 60 * 1000;
+
protected Intent mIntent;
private PerformanceTestCase.Intermediates mIntermediates;
@@ -125,6 +133,11 @@
}
public int runLaunchpad(String action) {
+ startLaunchpadActivity(action);
+ return waitForResultOrThrow(TIMEOUT_MS);
+ }
+
+ private void startLaunchpadActivity(String action) {
LaunchpadActivity.setCallingTest(this);
synchronized (this) {
@@ -133,8 +146,6 @@
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(mIntent);
}
-
- return waitForResultOrThrow(60 * 1000);
}
public int waitForResultOrThrow(int timeoutMs) {
@@ -186,6 +197,45 @@
return mResultCode;
}
+ /**
+ * Runs multiple launch pad activities until successfully finishing one or
+ * exhausting them all and throwing an exception.
+ *
+ * @param testName to make it easier to debug failures
+ * @param testClass to make it easier to debug failures
+ * @param firstAction to run
+ * @param moreActions to run in sequence if the first action fails
+ */
+ public void runMultipleLaunchpads(String testName, Class<?> testClass,
+ String firstAction, String... moreActions) {
+ List<String> actions = new ArrayList<String>();
+ actions.add(firstAction);
+ for (String action : moreActions) {
+ actions.add(action);
+ }
+
+ RuntimeException lastException = null;
+ String testIdentifier = testClass.getSimpleName() + "#" + testName + ":";
+
+ for (String action : actions) {
+ startLaunchpadActivity(action);
+ try {
+ int res = waitForResultOrThrow(TIMEOUT_MS);
+ if (res == Activity.RESULT_OK) {
+ return;
+ } else {
+ Log.w(TAG, testIdentifier + action + " returned result " + res);
+ }
+ } catch (RuntimeException e) {
+ Log.w(TAG, testIdentifier + action + " threw exception", e);
+ }
+ }
+
+ if (lastException != null) {
+ throw lastException;
+ }
+ }
+
public int getResultCode() {
return mResultCode;
}
diff --git a/tests/src/android/app/cts/LaunchpadActivity.java b/tests/src/android/app/cts/LaunchpadActivity.java
index 566e7b7..aa6d9808 100644
--- a/tests/src/android/app/cts/LaunchpadActivity.java
+++ b/tests/src/android/app/cts/LaunchpadActivity.java
@@ -84,8 +84,10 @@
public static final int FORWARDED_RESULT = 2;
public static final String LIFECYCLE_BASIC = "android.app.cts.activity.LIFECYCLE_BASIC";
- public static final String LIFECYCLE_SCREEN = "android.app.cts.activity.LIFECYCLE_SCREEN";
- public static final String LIFECYCLE_DIALOG = "android.app.cts.activity.LIFECYCLE_DIALOG";
+ public static final String LIFECYCLE_SCREEN_ON_STOP = "android.app.cts.activity.LIFECYCLE_SCREEN_ON_STOP";
+ public static final String LIFECYCLE_SCREEN_ON_RESUME = "android.app.cts.activity.LIFECYCLE_SCREEN_ON_RESUME";
+ public static final String LIFECYCLE_DIALOG_ON_STOP = "android.app.cts.activity.LIFECYCLE_DIALOG_ON_STOP";
+ public static final String LIFECYCLE_DIALOG_ON_RESUME = "android.app.cts.activity.LIFECYCLE_DIALOG_ON_RESUME";
public static final String LIFECYCLE_FINISH_CREATE = "android.app.cts.activity.LIFECYCLE_FINISH_CREATE";
public static final String LIFECYCLE_FINISH_START = "android.app.cts.activity.LIFECYCLE_FINISH_START";
@@ -162,16 +164,26 @@
setExpectedLifecycle(new String[] {
ON_START, ON_RESUME, DO_FINISH, ON_PAUSE, ON_STOP, ON_DESTROY
});
- } else if (LIFECYCLE_SCREEN.equals(action)) {
+ } else if (LIFECYCLE_SCREEN_ON_STOP.equals(action)) {
setExpectedLifecycle(new String[] {
ON_START, ON_RESUME, DO_LOCAL_SCREEN, ON_FREEZE, ON_PAUSE, ON_STOP, ON_RESTART,
ON_START, ON_RESUME, DO_FINISH, ON_PAUSE, ON_STOP, ON_DESTROY
});
- } else if (LIFECYCLE_DIALOG.equals(action)) {
+ } else if (LIFECYCLE_SCREEN_ON_RESUME.equals(action)) {
+ setExpectedLifecycle(new String[] {
+ ON_START, ON_RESUME, DO_LOCAL_SCREEN, ON_FREEZE, ON_PAUSE, ON_RESUME, DO_FINISH,
+ ON_PAUSE, ON_STOP, ON_DESTROY
+ });
+ } else if (LIFECYCLE_DIALOG_ON_RESUME.equals(action)) {
setExpectedLifecycle(new String[] {
ON_START, ON_RESUME, DO_LOCAL_DIALOG, ON_FREEZE, ON_PAUSE, ON_RESUME,
DO_FINISH, ON_PAUSE, ON_STOP, ON_DESTROY
});
+ } else if (LIFECYCLE_DIALOG_ON_STOP.equals(action)) {
+ setExpectedLifecycle(new String[] {
+ ON_START, ON_RESUME, DO_LOCAL_DIALOG, ON_FREEZE, ON_PAUSE, ON_STOP, ON_RESTART,
+ ON_START, ON_RESUME, DO_FINISH, ON_PAUSE, ON_STOP, ON_DESTROY
+ });
} else if (LIFECYCLE_FINISH_CREATE.equals(action)) {
// This one behaves a little differently when running in a group.
if (getParent() == null) {
@@ -394,19 +406,22 @@
}
private void checkLifecycle(String where) {
+ String action = getIntent().getAction();
+
if (mExpectedLifecycle == null) {
return;
}
if (mNextLifecycle >= mExpectedLifecycle.length) {
- finishBad("Activity lifecycle incorrect: received " + where
+ finishBad("Activity lifecycle for " + action + " incorrect: received " + where
+ " but don't expect any more calls");
mExpectedLifecycle = null;
return;
}
if (!mExpectedLifecycle[mNextLifecycle].equals(where)) {
- finishBad("Activity lifecycle incorrect: received " + where + " but expected "
- + mExpectedLifecycle[mNextLifecycle] + " at " + mNextLifecycle);
+ finishBad("Activity lifecycle for " + action + " incorrect: received " + where
+ + " but expected " + mExpectedLifecycle[mNextLifecycle]
+ + " at " + mNextLifecycle);
mExpectedLifecycle = null;
return;
}
@@ -420,7 +435,7 @@
final String next = mExpectedLifecycle[mNextLifecycle];
if (where.equals(ON_DESTROY)) {
- finishBad("Activity lifecycle incorrect: received " + where
+ finishBad("Activity lifecycle for " + action + " incorrect: received " + where
+ " but expected more actions (next is " + next + ")");
mExpectedLifecycle = null;
return;
diff --git a/tests/tests/app/src/android/app/cts/ActivityGroupTest.java b/tests/tests/app/src/android/app/cts/ActivityGroupTest.java
index 05287cd..b0739f4 100644
--- a/tests/tests/app/src/android/app/cts/ActivityGroupTest.java
+++ b/tests/tests/app/src/android/app/cts/ActivityGroupTest.java
@@ -170,7 +170,9 @@
@BrokenTest(value="bug 2189784, needs investigation")
public void testTabScreen() throws Exception {
mIntent = mTabIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_SCREEN);
+ runMultipleLaunchpads("testTabScreen", getClass(),
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_STOP,
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_RESUME);
}
@TestTargets({
@@ -238,7 +240,9 @@
@BrokenTest(value="bug 2189784, needs investigation")
public void testTabDialog() throws Exception {
mIntent = mTabIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_DIALOG);
+ runMultipleLaunchpads("testTabDialog", getClass(),
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_RESUME,
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_STOP);
}
@TestTargets({
diff --git a/tests/tests/app/src/android/app/cts/LifecycleTest.java b/tests/tests/app/src/android/app/cts/LifecycleTest.java
index 56517ae..5f69306 100644
--- a/tests/tests/app/src/android/app/cts/LifecycleTest.java
+++ b/tests/tests/app/src/android/app/cts/LifecycleTest.java
@@ -3466,7 +3466,9 @@
})
public void testTabDialog() {
mIntent = mTabIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_DIALOG);
+ runMultipleLaunchpads("testTabDialog", getClass(),
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_RESUME,
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_STOP);
}
@TestTargets({
@@ -4148,7 +4150,9 @@
})
public void testDialog() {
mIntent = mTopIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_DIALOG);
+ runMultipleLaunchpads("testDialog", getClass(),
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_RESUME,
+ LaunchpadActivity.LIFECYCLE_DIALOG_ON_STOP);
}
@TestTargets({
@@ -4830,7 +4834,9 @@
})
public void testTabScreen() {
mIntent = mTabIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_SCREEN);
+ runMultipleLaunchpads("testTabScreen", getClass(),
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_RESUME,
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_STOP);
}
@TestTargets({
@@ -5513,7 +5519,9 @@
})
public void testScreen() {
mIntent = mTopIntent;
- runLaunchpad(LaunchpadActivity.LIFECYCLE_SCREEN);
+ runMultipleLaunchpads("testScreen", getClass(),
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_RESUME,
+ LaunchpadActivity.LIFECYCLE_SCREEN_ON_STOP);
}
@TestTargets({
diff --git a/tests/tests/graphics/src/android/graphics/cts/MovieTest.java b/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
index c377d5e..5621212 100644
--- a/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
@@ -28,6 +28,8 @@
import android.graphics.Movie;
import android.graphics.Paint;
import android.test.ActivityInstrumentationTestCase2;
+import android.widget.cts.WidgetTestUtils;
+
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -199,11 +201,14 @@
public void testGetMovieProperties() {
assertEquals(1000, mMovie.duration());
assertFalse(mMovie.isOpaque());
- int expectedHeight = getActivity().getResources().getDrawable(MOVIE)
- .getIntrinsicHeight();
- assertEquals(expectedHeight, mMovie.height());
- int expectedWidth = getActivity().getResources().getDrawable(MOVIE)
- .getIntrinsicWidth();
- assertEquals(expectedWidth, mMovie.width());
+
+ int expectedHeight = getActivity().getResources().getDrawable(MOVIE).getIntrinsicHeight();
+ int scaledHeight = WidgetTestUtils.convertDipToPixels(getActivity(), mMovie.height());
+ assertEquals(expectedHeight, scaledHeight);
+
+ int expectedWidth = getActivity().getResources().getDrawable(MOVIE).getIntrinsicWidth();
+ int scaledWidth = WidgetTestUtils.convertDipToPixels(getActivity(), mMovie.width());
+ assertEquals(expectedWidth, scaledWidth);
+
}
}
\ No newline at end of file
diff --git a/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java b/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
index a70aec6..0f04bac 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
@@ -504,11 +504,16 @@
setAdapter();
+ View row = mListView.getChildAt(0);
+ int rowHeight = row.getHeight();
+ int middleOfSecondRow = rowHeight + rowHeight/2;
+
int position1 = mListView.pointToPosition(0, 0);
- int position2 = mListView.pointToPosition(50, 200);
+ int position2 = mListView.pointToPosition(50, middleOfSecondRow);
assertEquals(mAdapter_countries.getItemId(position1), mListView.pointToRowId(0, 0));
- assertEquals(mAdapter_countries.getItemId(position2), mListView.pointToRowId(50, 200));
+ assertEquals(mAdapter_countries.getItemId(position2),
+ mListView.pointToRowId(50, middleOfSecondRow));
assertTrue(position2 > position1);
}