| 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 bc21b08fccd3235da6d49275e73e4e54ed44b5b5..cdb00fe2ddcb30f878fb6edde1bde0a39f2a3d2b 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
|
| @@ -9,7 +9,6 @@
|
| 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;
|
| @@ -51,11 +50,6 @@
|
| }
|
| }
|
|
|
| - private void runOnUiThreadAndWait(Runnable runnable) {
|
| - ThreadUtils.runOnUiThreadBlocking(runnable);
|
| - getInstrumentation().waitForIdleSync();
|
| - }
|
| -
|
| /**
|
| * Locks the screen orientation to the predefined orientation type.
|
| */
|
| @@ -67,20 +61,14 @@
|
| * Locks the screen orientation to the predefined orientation type then wait
|
| * for the orientation change to happen.
|
| */
|
| - private void lockOrientationAndWait(final int orientation) throws InterruptedException {
|
| - runOnUiThreadAndWait(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - try {
|
| - lockOrientation(orientation);
|
| - } catch (Exception e) {
|
| - fail("Should not be there!");
|
| - }
|
| - }
|
| - });
|
| -
|
| - CriteriaHelper.pollForCriteria(
|
| - new OrientationChangeObserverCriteria(mObserver, orientationTypeToAngle(orientation)));
|
| + private boolean lockOrientationAndWait(int orientation)
|
| + throws InterruptedException {
|
| + OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria(
|
| + mObserver, orientationTypeToAngle(orientation));
|
| +
|
| + lockOrientation(orientation);
|
| +
|
| + return CriteriaHelper.pollForCriteria(criteria);
|
| }
|
|
|
| /**
|
| @@ -107,22 +95,13 @@
|
| }
|
|
|
| private void setUpForConfigurationListener() throws InterruptedException {
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - ScreenOrientationListener.getInstance().injectConfigurationListenerBackendForTest();
|
| - }
|
| - });
|
| -
|
| - final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| + ScreenOrientationListener.getInstance().injectConfigurationListenerBackendForTest();
|
| +
|
| + ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| waitForActiveShellToBeDoneLoading();
|
|
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
|
| - }
|
| - });
|
| + ScreenOrientationListener.getInstance().addObserver(
|
| + mObserver, getInstrumentation().getTargetContext());
|
| }
|
|
|
| private boolean setUpForDisplayListener() throws InterruptedException {
|
| @@ -130,16 +109,38 @@
|
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| return false;
|
|
|
| - final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| + ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
|
| waitForActiveShellToBeDoneLoading();
|
|
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
|
| - }
|
| - });
|
| + 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
|
| + @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
|
| @@ -185,6 +186,28 @@
|
| 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 {
|
| @@ -231,4 +254,5 @@
|
| lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
| assertEquals(-90, mObserver.mOrientation);
|
| }
|
| + */
|
| }
|
|
|