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

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

Issue 608503003: Properly interpret orientation provider/listener test values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set mNaturalOrientation default value to ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED Created 6 years, 3 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 | « content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java ('k') | 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/ScreenOrientationProviderTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationProviderTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationProviderTest.java
index 1ed3f4a52072ebfe24bc47949740210cf33a9c24..f2e0edba7fc87935e4161da8aef4d6f238145afd 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationProviderTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationProviderTest.java
@@ -4,6 +4,8 @@
package org.chromium.content.browser;
+import android.app.Activity;
+import android.content.pm.ActivityInfo;
import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ThreadUtils;
@@ -15,6 +17,7 @@ import org.chromium.content.browser.test.util.OrientationChangeObserverCriteria;
import org.chromium.content_public.common.ScreenOrientationValues;
import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellTestBase;
+import org.chromium.ui.gfx.DeviceDisplayInfo;
/**
* Tests for ScreenOrientationListener and its implementations.
@@ -30,26 +33,70 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase {
private MockOrientationObserver mObserver;
+ private int mNaturalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+
private boolean checkOrientationForLock(int orientations) {
- switch (orientations) {
- case ScreenOrientationValues.PORTRAIT_PRIMARY:
- return mObserver.mOrientation == 0;
- case ScreenOrientationValues.PORTRAIT_SECONDARY:
- return mObserver.mOrientation == 180 ||
- (ALLOW_0_FOR_180 && mObserver.mOrientation == 0);
- case ScreenOrientationValues.LANDSCAPE_PRIMARY:
- return mObserver.mOrientation == 90;
- case ScreenOrientationValues.LANDSCAPE_SECONDARY:
- return mObserver.mOrientation == -90;
- case ScreenOrientationValues.PORTRAIT:
- return mObserver.mOrientation == 0 || mObserver.mOrientation == 180;
- case ScreenOrientationValues.LANDSCAPE:
- return mObserver.mOrientation == 90 || mObserver.mOrientation == -90;
- case ScreenOrientationValues.ANY:
- // The orientation should not change but might and the value could be anything.
- return true;
- default:
- return !mObserver.mHasChanged;
+ if (mNaturalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
+ switch (orientations) {
+ case ScreenOrientationValues.PORTRAIT_PRIMARY:
+ return mObserver.mOrientation == 0;
+ case ScreenOrientationValues.PORTRAIT_SECONDARY:
+ return mObserver.mOrientation == 180 ||
+ (ALLOW_0_FOR_180 && mObserver.mOrientation == 0);
+ case ScreenOrientationValues.LANDSCAPE_PRIMARY:
+ return mObserver.mOrientation == 90;
+ case ScreenOrientationValues.LANDSCAPE_SECONDARY:
+ return mObserver.mOrientation == -90;
+ case ScreenOrientationValues.PORTRAIT:
+ return mObserver.mOrientation == 0 || mObserver.mOrientation == 180;
+ case ScreenOrientationValues.LANDSCAPE:
+ return mObserver.mOrientation == 90 || mObserver.mOrientation == -90;
+ case ScreenOrientationValues.ANY:
+ // The orientation should not change but might and the value could be anything.
+ return true;
+ default:
+ return !mObserver.mHasChanged;
+ }
+ } else { // mNaturalOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ switch (orientations) {
+ case ScreenOrientationValues.PORTRAIT_PRIMARY:
+ return mObserver.mOrientation == -90;
+ case ScreenOrientationValues.PORTRAIT_SECONDARY:
+ return mObserver.mOrientation == 90;
+ case ScreenOrientationValues.LANDSCAPE_PRIMARY:
+ return mObserver.mOrientation == 0;
+ case ScreenOrientationValues.LANDSCAPE_SECONDARY:
+ return mObserver.mOrientation == 180 ||
+ (ALLOW_0_FOR_180 && mObserver.mOrientation == 0);
+ case ScreenOrientationValues.PORTRAIT:
+ return mObserver.mOrientation == 90 || mObserver.mOrientation == -90;
+ case ScreenOrientationValues.LANDSCAPE:
+ return mObserver.mOrientation == 0 || mObserver.mOrientation == 180;
+ case ScreenOrientationValues.ANY:
+ // The orientation should not change but might and the value could be anything.
+ return true;
+ default:
+ return !mObserver.mHasChanged;
+ }
+ }
+ }
+
+ /**
+ * Retrieves device natural orientation.
+ */
+ private int getNaturalOrientation(Activity activity) {
+ DeviceDisplayInfo displayInfo = DeviceDisplayInfo.create(activity);
+ int rotation = displayInfo.getRotationDegrees();
+ if (rotation == 0 || rotation == 180) {
+ if (displayInfo.getDisplayHeight() >= displayInfo.getDisplayWidth()) {
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ }
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ } else {
+ if (displayInfo.getDisplayHeight() < displayInfo.getDisplayWidth()) {
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ }
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
}
@@ -90,6 +137,10 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase {
}
});
+ // Calculate device natural orientation, as mObserver.mOrientation
+ // is difference between current and natural orientation in degrees.
+ mNaturalOrientation = getNaturalOrientation(activity);
+
// Make sure we start all the tests with the same orientation.
lockOrientationAndWait(ScreenOrientationValues.PORTRAIT_PRIMARY);
« no previous file with comments | « content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationListenerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698