Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java

Issue 431083005: Revert of Re-enable ScreenOrientationListenerTest.java and run locking on UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
+ */
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698