Index: content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java |
index a8376470948fe66cdd2b2b8580d5ffd52434c264..375eca694bdb13a9a108492fb8f8321907c427bf 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java |
@@ -5,17 +5,12 @@ |
package org.chromium.content.browser; |
import android.content.pm.ActivityInfo; |
-import android.content.res.Configuration; |
-import android.graphics.Canvas; |
import android.test.suitebuilder.annotation.MediumTest; |
import android.test.suitebuilder.annotation.SmallTest; |
-import android.view.KeyEvent; |
-import android.view.MotionEvent; |
-import android.view.View; |
+import android.view.Surface; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.UrlUtils; |
-import org.chromium.content.browser.ContentViewCore.InternalAccessDelegate; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
import org.chromium.content.browser.test.util.JavaScriptUtils; |
@@ -34,104 +29,71 @@ public class ScreenOrientationTest extends ContentShellTestBase { |
UrlUtils.encodeHtmlDataUri("<html><body>foo</body></html>"); |
/** |
- * Class that is used to get notified when the activity configuration |
- * changes. |
+ * Whether we should allow 0 degrees when expecting 180 degrees. |
+ * Try server bots, for some yet unknown reasons, rotate to 0 degrees angle |
+ * when they should rotate to 180 degrees. See http://crbug.com/344461 |
*/ |
- private static class ConfigurationChangeAccessDelegate |
- implements InternalAccessDelegate { |
+ private static final boolean ALLOW_0_FOR_180 = true; |
- private interface ConfigurationChangedListener { |
- public void onConfigurationChanged(); |
- } |
- |
- private ConfigurationChangedListener mListener = null; |
- |
- private void setListener(ConfigurationChangedListener listener) { |
- mListener = listener; |
- } |
- |
- @Override |
- public boolean drawChild(Canvas canvas, View child, long drawingTime) { |
- return false; |
- } |
- |
- @Override |
- public boolean super_onKeyUp(int keyCode, KeyEvent event) { |
- return false; |
- } |
- |
- @Override |
- public boolean super_dispatchKeyEventPreIme(KeyEvent event) { |
- return false; |
- } |
- |
- @Override |
- public boolean super_dispatchKeyEvent(KeyEvent event) { |
- return false; |
- } |
+ /** |
+ * Criteria used to know when an orientation change happens. |
+ */ |
+ private class OrientationChangeListenerCriteria implements Criteria { |
- @Override |
- public boolean super_onGenericMotionEvent(MotionEvent event) { |
- return false; |
- } |
+ private final int mTargetOrientation; |
- @Override |
- public void super_onConfigurationChanged(Configuration newConfig) { |
- if (mListener != null) |
- mListener.onConfigurationChanged(); |
+ private OrientationChangeListenerCriteria(int targetOrientation) { |
+ mTargetOrientation = targetOrientation; |
} |
@Override |
- public void onScrollChanged(int lPix, int tPix, int oldlPix, int oldtPix) { |
+ public boolean isSatisfied() { |
+ return getOrientationAngle() == mTargetOrientation; |
} |
+ } |
- @Override |
- public boolean awakenScrollBars() { |
- return false; |
- } |
+ private ContentView mContentView; |
- @Override |
- public boolean super_awakenScrollBars(int startDelay, boolean invalidate) { |
- return false; |
+ /** |
+ * Returns the current device orientation angle. |
+ */ |
+ private int getOrientationAngle() { |
+ switch (getActivity().getWindowManager().getDefaultDisplay() |
+ .getRotation()) { |
+ case Surface.ROTATION_90: |
+ return 90; |
+ case Surface.ROTATION_180: |
+ return 180; |
+ case Surface.ROTATION_270: |
+ return 270; |
+ case Surface.ROTATION_0: |
+ return 0; |
+ default: |
+ fail("Should not be there!"); |
+ return 0; |
} |
} |
/** |
- * Criteria used to know when an orientation change happens. |
+ * Returns the expected orientation angle for a specific orientation type as |
+ * defined in ActivityInfor.screenOrientation. |
*/ |
- private static class OrientationChangeListenerCriteria implements Criteria { |
- |
- private boolean mSatisfied = false; |
- |
- private ConfigurationChangeAccessDelegate mAccessDelegate; |
- |
- private OrientationChangeListenerCriteria( |
- ConfigurationChangeAccessDelegate accessDelegate) { |
- mAccessDelegate = accessDelegate; |
- mAccessDelegate.setListener( |
- new ConfigurationChangeAccessDelegate.ConfigurationChangedListener() { |
- @Override |
- public void onConfigurationChanged() { |
- mSatisfied = true; |
- } |
- }); |
- } |
- |
- @Override |
- public boolean isSatisfied() { |
- if (mSatisfied) { |
- mAccessDelegate.setListener(null); |
- return true; |
- } |
- |
- return false; |
+ private static int orientationTypeToAngle(int orientation) { |
+ switch (orientation) { |
+ case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
+ return 0; |
+ case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
+ return 90; |
+ case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
+ return 180; |
+ case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
+ return 270; |
+ default: |
+ fail("Should not be there!"); |
+ return 0; |
} |
} |
- private ContentView mContentView; |
- |
- private ConfigurationChangeAccessDelegate mConfChangeAccessDelegate; |
- |
/** |
* Locks the screen orientation to the predefined orientation type. |
*/ |
@@ -154,7 +116,7 @@ public class ScreenOrientationTest extends ContentShellTestBase { |
private boolean lockOrientationAndWait(int orientation) |
throws InterruptedException { |
OrientationChangeListenerCriteria listenerCriteria = |
- new OrientationChangeListenerCriteria(mConfChangeAccessDelegate); |
+ new OrientationChangeListenerCriteria(orientationTypeToAngle(orientation)); |
lockOrientation(orientation); |
@@ -180,10 +142,6 @@ public class ScreenOrientationTest extends ContentShellTestBase { |
ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL); |
waitForActiveShellToBeDoneLoading(); |
mContentView = activity.getActiveContentView(); |
- |
- mConfChangeAccessDelegate = new ConfigurationChangeAccessDelegate(); |
- getContentViewCore(). |
- setContainerViewInternals(mConfChangeAccessDelegate); |
} |
@Override |
@@ -201,19 +159,45 @@ public class ScreenOrientationTest extends ContentShellTestBase { |
@MediumTest |
@Feature({"ScreenOrientation", "Main"}) |
public void testChanges() throws Throwable { |
+ lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
+ assertEquals(0, getWindowOrientation()); |
+ |
lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
assertEquals(90, getWindowOrientation()); |
- lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
- assertEquals(0, getWindowOrientation()); |
+ lockOrientationAndWait( |
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); |
+ int orientation = getWindowOrientation(); |
+ assertTrue(180 == orientation || (0 == orientation && ALLOW_0_FOR_180)); |
lockOrientationAndWait( |
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
assertEquals(-90, getWindowOrientation()); |
+ lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
+ assertEquals(0, getWindowOrientation()); |
+ } |
+ |
+ @MediumTest |
+ @Feature({"ScreenOrientation", "Main"}) |
+ public void testFlipChangePortrait() throws Throwable { |
+ lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
+ assertEquals(0, getWindowOrientation()); |
+ |
lockOrientationAndWait( |
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); |
int orientation = getWindowOrientation(); |
- assertTrue(orientation == 0 || orientation == 180); |
+ assertTrue(180 == orientation || (0 == orientation && ALLOW_0_FOR_180)); |
+ } |
+ |
+ @MediumTest |
+ @Feature({"ScreenOrientation", "Main"}) |
+ public void testFlipChangeLandscape() throws Throwable { |
+ lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
+ assertEquals(90, getWindowOrientation()); |
+ |
+ lockOrientationAndWait( |
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
+ assertEquals(-90, getWindowOrientation()); |
} |
} |