| 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 375eca694bdb13a9a108492fb8f8321907c427bf..a8376470948fe66cdd2b2b8580d5ffd52434c264 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,12 +5,17 @@
|
| 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.Surface;
|
| +import android.view.KeyEvent;
|
| +import android.view.MotionEvent;
|
| +import android.view.View;
|
|
|
| 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;
|
| @@ -29,70 +34,103 @@
|
| UrlUtils.encodeHtmlDataUri("<html><body>foo</body></html>");
|
|
|
| /**
|
| - * 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 final boolean ALLOW_0_FOR_180 = true;
|
| + * Class that is used to get notified when the activity configuration
|
| + * changes.
|
| + */
|
| + private static class ConfigurationChangeAccessDelegate
|
| + implements InternalAccessDelegate {
|
| +
|
| + 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;
|
| + }
|
| +
|
| + @Override
|
| + public boolean super_onGenericMotionEvent(MotionEvent event) {
|
| + return false;
|
| + }
|
| +
|
| + @Override
|
| + public void super_onConfigurationChanged(Configuration newConfig) {
|
| + if (mListener != null)
|
| + mListener.onConfigurationChanged();
|
| + }
|
| +
|
| + @Override
|
| + public void onScrollChanged(int lPix, int tPix, int oldlPix, int oldtPix) {
|
| + }
|
| +
|
| + @Override
|
| + public boolean awakenScrollBars() {
|
| + return false;
|
| + }
|
| +
|
| + @Override
|
| + public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
|
| + return false;
|
| + }
|
| + }
|
|
|
| /**
|
| * Criteria used to know when an orientation change happens.
|
| */
|
| - private class OrientationChangeListenerCriteria implements Criteria {
|
| -
|
| - private final int mTargetOrientation;
|
| -
|
| - private OrientationChangeListenerCriteria(int targetOrientation) {
|
| - mTargetOrientation = targetOrientation;
|
| + 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() {
|
| - return getOrientationAngle() == mTargetOrientation;
|
| + if (mSatisfied) {
|
| + mAccessDelegate.setListener(null);
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| }
|
| }
|
|
|
| private ContentView mContentView;
|
|
|
| - /**
|
| - * 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;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Returns the expected orientation angle for a specific orientation type as
|
| - * defined in ActivityInfor.screenOrientation.
|
| - */
|
| - 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 ConfigurationChangeAccessDelegate mConfChangeAccessDelegate;
|
|
|
| /**
|
| * Locks the screen orientation to the predefined orientation type.
|
| @@ -116,7 +154,7 @@
|
| private boolean lockOrientationAndWait(int orientation)
|
| throws InterruptedException {
|
| OrientationChangeListenerCriteria listenerCriteria =
|
| - new OrientationChangeListenerCriteria(orientationTypeToAngle(orientation));
|
| + new OrientationChangeListenerCriteria(mConfChangeAccessDelegate);
|
|
|
| lockOrientation(orientation);
|
|
|
| @@ -142,6 +180,10 @@
|
| ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| waitForActiveShellToBeDoneLoading();
|
| mContentView = activity.getActiveContentView();
|
| +
|
| + mConfChangeAccessDelegate = new ConfigurationChangeAccessDelegate();
|
| + getContentViewCore().
|
| + setContainerViewInternals(mConfChangeAccessDelegate);
|
| }
|
|
|
| @Override
|
| @@ -159,45 +201,19 @@
|
| @MediumTest
|
| @Feature({"ScreenOrientation", "Main"})
|
| public void testChanges() throws Throwable {
|
| + lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| + assertEquals(90, getWindowOrientation());
|
| +
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| assertEquals(0, getWindowOrientation());
|
|
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| - assertEquals(90, 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(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());
|
| + assertTrue(orientation == 0 || orientation == 180);
|
| }
|
| }
|
|
|