| Index: content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java
|
| index cdb00fe2ddcb30f878fb6edde1bde0a39f2a3d2b..d00e07256de701798f431da42815bab77ca22047 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java
|
| @@ -6,9 +6,10 @@ package org.chromium.content.browser;
|
|
|
| import android.content.pm.ActivityInfo;
|
| import android.os.Build;
|
| +import android.test.suitebuilder.annotation.LargeTest;
|
| import android.test.suitebuilder.annotation.MediumTest;
|
| -import android.test.suitebuilder.annotation.SmallTest;
|
|
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| @@ -61,14 +62,23 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
| * Locks the screen orientation to the predefined orientation type then wait
|
| * for the orientation change to happen.
|
| */
|
| - private boolean lockOrientationAndWait(int orientation)
|
| - throws InterruptedException {
|
| - OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria(
|
| - mObserver, orientationTypeToAngle(orientation));
|
| -
|
| - lockOrientation(orientation);
|
| -
|
| - return CriteriaHelper.pollForCriteria(criteria);
|
| + private void lockOrientationAndWait(final int orientation) throws InterruptedException {
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + try {
|
| + lockOrientation(orientation);
|
| + } catch (Exception e) {
|
| + fail("Should not be there!");
|
| + }
|
| + }
|
| + });
|
| + // TODO(mlamouri): this slows the tests down, we could consider removing
|
| + // this if it doesn't flakes the test.
|
| + getInstrumentation().waitForIdleSync();
|
| +
|
| + CriteriaHelper.pollForCriteria(
|
| + new OrientationChangeObserverCriteria(mObserver, orientationTypeToAngle(orientation)));
|
| }
|
|
|
| /**
|
| @@ -84,6 +94,19 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
| super.setUp();
|
|
|
| mObserver = new MockOrientationObserver();
|
| +
|
| + final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| + waitForActiveShellToBeDoneLoading();
|
| +
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
|
| + }
|
| + });
|
| +
|
| + // Make sure we start all the tests with the same orientation.
|
| + lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| }
|
|
|
| @Override
|
| @@ -94,60 +117,9 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
| super.tearDown();
|
| }
|
|
|
| - private void setUpForConfigurationListener() throws InterruptedException {
|
| - ScreenOrientationListener.getInstance().injectConfigurationListenerBackendForTest();
|
| -
|
| - ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| - waitForActiveShellToBeDoneLoading();
|
| -
|
| - ScreenOrientationListener.getInstance().addObserver(
|
| - mObserver, getInstrumentation().getTargetContext());
|
| - }
|
| -
|
| - private boolean setUpForDisplayListener() throws InterruptedException {
|
| - // This can't work for pre JB-MR1 SDKs.
|
| - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| - return false;
|
| -
|
| - ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| - waitForActiveShellToBeDoneLoading();
|
| -
|
| - ScreenOrientationListener.getInstance().addObserver(
|
| - mObserver, getInstrumentation().getTargetContext());
|
| - return true;
|
| - }
|
| -
|
| - // At least one of these tests flakes 50% on all runs of
|
| - // contentshell_instrumentation_tests.
|
| - // crbug.com/356483
|
| - /*
|
| - @SmallTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testConfigurationListenerDefault() throws Exception {
|
| - setUpForConfigurationListener();
|
| -
|
| - assertFalse(mObserver.mHasChanged);
|
| - assertEquals(-1, mObserver.mOrientation);
|
| - }
|
| -
|
| - @SmallTest
|
| + @LargeTest
|
| @Feature({"ScreenOrientation"})
|
| - public void testConfigurationListenerAsyncSetup() throws Exception {
|
| - setUpForConfigurationListener();
|
| -
|
| - // We should get a onScreenOrientationChange call asynchronously.
|
| - CriteriaHelper.pollForCriteria(new OrientationChangeObserverCriteria(
|
| - mObserver));
|
| -
|
| - assertTrue(mObserver.mHasChanged);
|
| - assertTrue(mObserver.mOrientation != -1);
|
| - }
|
| -
|
| - @MediumTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testConfigurationListenerChanges() throws Exception {
|
| - setUpForConfigurationListener();
|
| -
|
| + public void testVariousOrientationChanges() throws Exception {
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| assertEquals(90, mObserver.mOrientation);
|
|
|
| @@ -164,74 +136,9 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
|
|
| @MediumTest
|
| @Feature({"ScreenOrientation"})
|
| - public void testConfigurationListenerFlipPortrait() throws Exception {
|
| - setUpForConfigurationListener();
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| - assertEquals(0, mObserver.mOrientation);
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
| - assertEquals(0, mObserver.mOrientation);
|
| - }
|
| -
|
| - @MediumTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testConfigurationListenerFlipLandscape() throws Exception {
|
| - setUpForConfigurationListener();
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| - assertEquals(90, mObserver.mOrientation);
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
| - assertEquals(90, mObserver.mOrientation);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testDisplayListenerDefault() throws Exception {
|
| - if (!setUpForDisplayListener())
|
| - return;
|
| -
|
| - assertEquals(-1, mObserver.mOrientation);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testDisplayListenerAsyncSetup() throws Exception {
|
| - if (!setUpForDisplayListener())
|
| - return;
|
| -
|
| - // We should get a onScreenOrientationChange call asynchronously.
|
| - CriteriaHelper.pollForCriteria(new OrientationChangeObserverCriteria(
|
| - mObserver));
|
| -
|
| - assertTrue(mObserver.mOrientation != -1);
|
| - }
|
| -
|
| - @MediumTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testDisplayListenerChanges() throws Exception {
|
| - if (!setUpForDisplayListener())
|
| - return;
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| - assertEquals(90, mObserver.mOrientation);
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
| - assertTrue(mObserver.mOrientation == 180 ||
|
| - (ALLOW_0_FOR_180 && mObserver.mOrientation == 0));
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
| - assertEquals(-90, mObserver.mOrientation);
|
| -
|
| - lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| - assertEquals(0, mObserver.mOrientation);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"ScreenOrientation"})
|
| - public void testDisplayListenerFlipPortrait() throws Exception {
|
| - if (!setUpForDisplayListener())
|
| + public void testFlipPortrait() throws Exception {
|
| + // This can't work for pre JB-MR1 SDKs.
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| return;
|
|
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| @@ -242,10 +149,11 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
| (ALLOW_0_FOR_180 && mObserver.mOrientation == 0));
|
| }
|
|
|
| - @SmallTest
|
| + @MediumTest
|
| @Feature({"ScreenOrientation"})
|
| - public void testDisplayListenerFlipLandscape() throws Exception {
|
| - if (!setUpForDisplayListener())
|
| + public void testFlipLandscape() throws Exception {
|
| + // This can't work for pre JB-MR1 SDKs.
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| return;
|
|
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| @@ -254,5 +162,4 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
| assertEquals(-90, mObserver.mOrientation);
|
| }
|
| - */
|
| }
|
|
|