Merge "Suppress NinePatchDrawableTest#testGetOpacity" into froyo
diff --git a/tests/src/android/app/cts/OrientationTestUtils.java b/tests/src/android/app/cts/OrientationTestUtils.java
new file mode 100644
index 0000000..7b2b568
--- /dev/null
+++ b/tests/src/android/app/cts/OrientationTestUtils.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.app.cts;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.pm.ActivityInfo;
+
+public class OrientationTestUtils {
+
+ /**
+ * Change the activity's orientation to something different and then switch back. This is used
+ * to trigger {@link Activity#onConfigurationChanged(android.content.res.Configuration)}.
+ *
+ * @param activity whose orientation will be changed and restored
+ */
+ public static void toggleOrientation(Activity activity) {
+ toggleOrientationSync(activity, null);
+ }
+
+ /**
+ * Same as {@link #toggleOrientation(Activity)} except {@link Instrumentation#waitForIdleSync()}
+ * is called after each orientation change.
+ *
+ * @param activity whose orientation will be changed and restored
+ * @param instrumentation use for idle syncing
+ */
+ public static void toggleOrientationSync(final Activity activity,
+ final Instrumentation instrumentation) {
+ final int originalOrientation = activity.getResources().getConfiguration().orientation;
+ final int newOrientation = originalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ changeOrientation(activity, instrumentation, newOrientation);
+ changeOrientation(activity, instrumentation, originalOrientation);
+ }
+
+ private static void changeOrientation(final Activity activity,
+ Instrumentation instrumentation, final int orientation) {
+ activity.setRequestedOrientation(orientation);
+ if (instrumentation != null) {
+ instrumentation.waitForIdleSync();
+ }
+ }
+}
diff --git a/tests/tests/app/src/android/app/cts/ApplicationTest.java b/tests/tests/app/src/android/app/cts/ApplicationTest.java
index c0c777c..2dfb97d 100644
--- a/tests/tests/app/src/android/app/cts/ApplicationTest.java
+++ b/tests/tests/app/src/android/app/cts/ApplicationTest.java
@@ -16,17 +16,17 @@
package android.app.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.app.Activity;
import android.app.Application;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
import android.test.InstrumentationTestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
/**
* Test {@link Application}.
@@ -78,13 +78,10 @@
runTestOnUiThread(new Runnable() {
public void run() {
- // make sure the configuration has been changed.
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ OrientationTestUtils.toggleOrientation(activity);
}
});
- getInstrumentation().waitForIdleSync();
-
+ instrumentation.waitForIdleSync();
assertTrue(mockApp.isOnConfigurationChangedCalled);
}
diff --git a/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java b/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
index 8b64a56..140ccaa 100644
--- a/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
@@ -16,29 +16,28 @@
package android.app.cts;
-import android.app.DatePickerDialog;
-import android.app.Instrumentation;
-import android.app.DatePickerDialog.OnDateSetListener;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.pm.ActivityInfo;
-import android.test.ActivityInstrumentationTestCase2;
-import android.text.TextUtils.TruncateAt;
-import android.view.KeyEvent;
-import android.widget.DatePicker;
-import android.widget.TextView;
import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+import android.app.DatePickerDialog;
+import android.app.Instrumentation;
+import android.app.DatePickerDialog.OnDateSetListener;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.test.ActivityInstrumentationTestCase2;
+import android.text.TextUtils.TruncateAt;
+import android.view.KeyEvent;
+import android.widget.DatePicker;
+import android.widget.TextView;
+
@TestTargetClass(DatePickerDialog.class)
public class DatePickerDialogTest extends ActivityInstrumentationTestCase2<DialogStubActivity> {
private Instrumentation mInstrumentation;
private DialogStubActivity mActivity;
- private int mOrientation;
public DatePickerDialogTest() {
super("com.android.cts.stub", DialogStubActivity.class);
@@ -49,13 +48,11 @@
super.setUp();
mInstrumentation = getInstrumentation();
mActivity = getActivity();
- mOrientation = mActivity.getRequestedOrientation();
}
@Override
protected void tearDown() throws Exception {
if (mActivity != null) {
- mActivity.setRequestedOrientation(mOrientation);
mActivity.finish();
}
super.tearDown();
@@ -174,10 +171,9 @@
assertEquals(mActivity.updatedDay, mActivity.INITIAL_DAY_OF_MONTH);
assertTrue(DialogStubActivity.onDateChangedCalled);
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mInstrumentation.waitForIdleSync();
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- mInstrumentation.waitForIdleSync();
+ assertFalse(mActivity.onSaveInstanceStateCalled);
+ assertFalse(DialogStubActivity.onRestoreInstanceStateCalled);
+ OrientationTestUtils.toggleOrientationSync(mActivity, mInstrumentation);
assertTrue(mActivity.onSaveInstanceStateCalled);
assertTrue(DialogStubActivity.onRestoreInstanceStateCalled);
}
diff --git a/tests/tests/app/src/android/app/cts/DialogTest.java b/tests/tests/app/src/android/app/cts/DialogTest.java
index ea7deca..4d02896 100644
--- a/tests/tests/app/src/android/app/cts/DialogTest.java
+++ b/tests/tests/app/src/android/app/cts/DialogTest.java
@@ -326,10 +326,12 @@
public void testOnSaveInstanceState() {
popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mInstrumentation.waitForIdleSync();
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- mInstrumentation.waitForIdleSync();
+
+ assertFalse(d.isOnSaveInstanceStateCalled);
+ assertFalse(TestDialog.isOnRestoreInstanceStateCalled);
+
+ OrientationTestUtils.toggleOrientationSync(mActivity, mInstrumentation);
+
assertTrue(d.isOnSaveInstanceStateCalled);
assertTrue(TestDialog.isOnRestoreInstanceStateCalled);
}
diff --git a/tests/tests/app/src/android/app/cts/ListActivityTest.java b/tests/tests/app/src/android/app/cts/ListActivityTest.java
index 43ebd05..d3a43f9 100644
--- a/tests/tests/app/src/android/app/cts/ListActivityTest.java
+++ b/tests/tests/app/src/android/app/cts/ListActivityTest.java
@@ -23,7 +23,6 @@
import dalvik.annotation.TestTargets;
import android.app.ListActivity;
-import android.content.pm.ActivityInfo;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.view.View;
@@ -34,7 +33,7 @@
@TestTargetClass(ListActivity.class)
public class ListActivityTest extends ActivityInstrumentationTestCase2<ListActivityTestHelper> {
private ListActivityTestHelper mStubListActivity;
- private int mScreenOrientation;
+
public ListActivityTest() {
super("com.android.cts.stub", ListActivityTestHelper.class);
}
@@ -44,7 +43,6 @@
super.setUp();
mStubListActivity = getActivity();
assertNotNull(mStubListActivity);
- mScreenOrientation = mStubListActivity.getRequestedOrientation();
}
protected void waitForAction() throws InterruptedException {
@@ -167,20 +165,7 @@
assertEquals(arrayAdapter, mStubListActivity.getListView().getAdapter());
assertTrue(mStubListActivity.isOnContentChangedCalled);
assertFalse(ListActivityTestHelper.isOnRestoreInstanceStateCalled);
- mStubListActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- getInstrumentation().waitForIdleSync();
- mStubListActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- getInstrumentation().waitForIdleSync();
+ OrientationTestUtils.toggleOrientationSync(mStubListActivity, getInstrumentation());
assertTrue(ListActivityTestHelper.isOnRestoreInstanceStateCalled);
}
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- if (mStubListActivity != null) {
- mStubListActivity.setRequestedOrientation(mScreenOrientation);
- getInstrumentation().waitForIdleSync();
- }
- }
-
}
diff --git a/tests/tests/app/src/android/app/cts/TabActivityTest.java b/tests/tests/app/src/android/app/cts/TabActivityTest.java
index a4595a5..649a56d 100644
--- a/tests/tests/app/src/android/app/cts/TabActivityTest.java
+++ b/tests/tests/app/src/android/app/cts/TabActivityTest.java
@@ -145,10 +145,7 @@
sendKeys(KeyEvent.KEYCODE_BACK);
mInstrumentation.waitForIdleSync();
assertFalse(MockTabActivity.isOnRestoreInstanceStateCalled);
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mInstrumentation.waitForIdleSync();
- mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- mInstrumentation.waitForIdleSync();
+ OrientationTestUtils.toggleOrientationSync(mActivity, mInstrumentation);
assertTrue(MockTabActivity.isOnRestoreInstanceStateCalled);
}