summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 15:30:39 +0000
committermlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 15:30:39 +0000
commitecd6b74df5b3a0a03d8baa237f5aca5aff9ced55 (patch)
tree5d367290698eb5dc652bcd9144678dbe27b5ed9f
parentd4b5d9f1f9e717974c9f25c65d88f6e7aff9cdbf (diff)
downloadchromium_src-ecd6b74df5b3a0a03d8baa237f5aca5aff9ced55.zip
chromium_src-ecd6b74df5b3a0a03d8baa237f5aca5aff9ced55.tar.gz
chromium_src-ecd6b74df5b3a0a03d8baa237f5aca5aff9ced55.tar.bz2
Integration tests for window.orientation.
This is making the web content believe the orientation has changes in order to test the entire stack between the Chrome Android implementation and the web content behaviour. BUG=None Review URL: https://codereview.chromium.org/189193004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256236 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java3
-rw-r--r--content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationIntegrationTest.java107
-rw-r--r--content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java219
3 files changed, 109 insertions, 220 deletions
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 2e8d56d..cea213c 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -1949,7 +1949,8 @@ public class ContentViewCore
/**
* Send the screen orientation value to the renderer.
*/
- private void sendOrientationChangeEvent(int orientation) {
+ @VisibleForTesting
+ void sendOrientationChangeEvent(int orientation) {
if (mNativeContentViewCore == 0) return;
nativeSendOrientationChangeEvent(mNativeContentViewCore, orientation);
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationIntegrationTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationIntegrationTest.java
new file mode 100644
index 0000000..51f31d5
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationIntegrationTest.java
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.UrlUtils;
+import org.chromium.content.browser.test.util.JavaScriptUtils;
+import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
+import org.chromium.content_shell_apk.ContentShellActivity;
+import org.chromium.content_shell_apk.ContentShellTestBase;
+
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Integration tests for Screen Orientation API (and legacy API).
+ */
+public class ScreenOrientationIntegrationTest extends ContentShellTestBase {
+
+ private static final String DEFAULT_URL = UrlUtils.encodeHtmlDataUri(
+ "<html><script>var changes=0;</script>" +
+ "<body onorientationchange='changes++;'>foo</body>" +
+ "</html>");
+
+ private ContentView mContentView;
+
+ /**
+ * Returns the screen orientation as seen by |window.orientation|.
+ */
+ private int getWindowOrientation()
+ throws InterruptedException, TimeoutException {
+ return Integer.parseInt(
+ JavaScriptUtils.executeJavaScriptAndWaitForResult(
+ mContentView,
+ new TestCallbackHelperContainer(mContentView),
+ "window.orientation"));
+ }
+
+ /**
+ * Returns the number of times the web content received a orientationchange
+ * event.
+ */
+ private int getWindowOrientationChangeCount()
+ throws InterruptedException, TimeoutException {
+ return Integer.parseInt(
+ JavaScriptUtils.executeJavaScriptAndWaitForResult(
+ mContentView,
+ new TestCallbackHelperContainer(mContentView),
+ "changes"));
+ }
+
+ /**
+ * Simulate a screen orientation change for the web content.
+ */
+ private void updateScreenOrientationForContent(int orientation) {
+ mContentView.getContentViewCore().sendOrientationChangeEvent(orientation);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
+ waitForActiveShellToBeDoneLoading();
+
+ mContentView = activity.getActiveContentView();
+ }
+
+ @SmallTest
+ @Feature({"ScreenOrientation"})
+ public void testNoOp() throws Throwable {
+ assertEquals(0, getWindowOrientationChangeCount());
+ }
+
+ @SmallTest
+ @Feature({"ScreenOrientation"})
+ public void testExpectedValues() throws Throwable {
+ int[] values = { 90, -90, 180, 0 };
+
+ for (int i = 0; i < values.length; ++i) {
+ updateScreenOrientationForContent(values[i]);
+ assertEquals(values[i], getWindowOrientation());
+ assertEquals(i + 1, getWindowOrientationChangeCount());
+ }
+ }
+
+ // We can't test unexpected value because it is branching to a NOTREACHED().
+
+ @SmallTest
+ @Feature({"ScreenOrientation"})
+ public void testNoChange() throws Throwable {
+ updateScreenOrientationForContent(90);
+ assertEquals(90, getWindowOrientation());
+ assertEquals(1, getWindowOrientationChangeCount());
+
+ updateScreenOrientationForContent(90);
+ assertEquals(90, getWindowOrientation());
+ assertEquals(1, getWindowOrientationChangeCount());
+
+ updateScreenOrientationForContent(90);
+ assertEquals(90, getWindowOrientation());
+ assertEquals(1, getWindowOrientationChangeCount());
+ }
+}
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
deleted file mode 100644
index a8376470..0000000
--- a/content/public/android/javatests/src/org/chromium/content/browser/ScreenOrientationTest.java
+++ /dev/null
@@ -1,219 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-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.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;
-import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
-import org.chromium.content_shell_apk.ContentShellActivity;
-import org.chromium.content_shell_apk.ContentShellTestBase;
-
-import java.util.concurrent.TimeoutException;
-
-/**
- * Integration tests for Screen Orientation API (and legacy API).
- */
-public class ScreenOrientationTest extends ContentShellTestBase {
-
- private static final String DEFAULT_URL =
- UrlUtils.encodeHtmlDataUri("<html><body>foo</body></html>");
-
- /**
- * 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 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() {
- if (mSatisfied) {
- mAccessDelegate.setListener(null);
- return true;
- }
-
- return false;
- }
- }
-
- private ContentView mContentView;
-
- private ConfigurationChangeAccessDelegate mConfChangeAccessDelegate;
-
- /**
- * Locks the screen orientation to the predefined orientation type.
- */
- private void lockOrientation(int orientation) {
- getActivity().setRequestedOrientation(orientation);
- }
-
- /**
- * Unlock the screen orientation. Equivalent to locking to unspecified.
- */
- private void unlockOrientation() {
- getActivity().setRequestedOrientation(
- ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- }
-
- /**
- * Locks the screen orientation to the predefined orientation type then wait
- * for the orientation change to happen.
- */
- private boolean lockOrientationAndWait(int orientation)
- throws InterruptedException {
- OrientationChangeListenerCriteria listenerCriteria =
- new OrientationChangeListenerCriteria(mConfChangeAccessDelegate);
-
- lockOrientation(orientation);
-
- return CriteriaHelper.pollForCriteria(listenerCriteria);
- }
-
- /**
- * Returns the screen orientation as seen by |window.orientation|.
- */
- private int getWindowOrientation()
- throws InterruptedException, TimeoutException {
- return Integer.parseInt(
- JavaScriptUtils.executeJavaScriptAndWaitForResult(
- mContentView,
- new TestCallbackHelperContainer(mContentView),
- "window.orientation"));
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
- waitForActiveShellToBeDoneLoading();
- mContentView = activity.getActiveContentView();
-
- mConfChangeAccessDelegate = new ConfigurationChangeAccessDelegate();
- getContentViewCore().
- setContainerViewInternals(mConfChangeAccessDelegate);
- }
-
- @Override
- public void tearDown() throws Exception {
- unlockOrientation();
- super.tearDown();
- }
-
- @SmallTest
- @Feature({"ScreenOrientation", "Main"})
- public void testDefault() throws Throwable {
- assertEquals(0, getWindowOrientation());
- }
-
- @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_REVERSE_LANDSCAPE);
- assertEquals(-90, getWindowOrientation());
-
- lockOrientationAndWait(
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
- int orientation = getWindowOrientation();
- assertTrue(orientation == 0 || orientation == 180);
- }
-}