Index: content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5240ee89798db0eb0fd0e565c448d6150aa957a3 |
--- /dev/null |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2012 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.Context; |
+import android.test.suitebuilder.annotation.MediumTest; |
+import android.util.DisplayMetrics; |
+import android.view.Display; |
+import android.view.WindowManager; |
+ |
+import org.chromium.base.test.util.Feature; |
+import org.chromium.content.browser.test.util.JavaScriptUtils; |
+import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
+import org.chromium.content.common.DeviceInfo; |
+ |
+/** |
+ * Test suite for viewport-related properties. |
+ */ |
+public class ViewportTest extends ContentViewTestBase { |
+ |
+ private TestCallbackHelperContainer mCallbackHelper; |
+ |
+ /** |
+ * Returns the TestCallbackHelperContainer associated with this ContentView, |
+ * or creates it lazily. |
+ */ |
+ protected TestCallbackHelperContainer getTestCallbackHelperContainer() { |
+ if (mCallbackHelper == null) { |
+ mCallbackHelper = new TestCallbackHelperContainer(getContentView()); |
+ } |
+ return mCallbackHelper; |
+ } |
+ |
+ protected String evaluateStringValue(String expression) throws Throwable { |
+ return JavaScriptUtils.executeJavaScriptAndWaitForResult(this, getContentView(), |
+ getTestCallbackHelperContainer(), expression); |
+ } |
+ |
+ protected float evaluateFloatValue(String expression) throws Throwable { |
+ return Float.valueOf(evaluateStringValue(expression)); |
+ } |
+ |
+ protected int evaluateIntegerValue(String expression) throws Throwable { |
+ return Integer.valueOf(evaluateStringValue(expression)); |
+ } |
+ |
+ @MediumTest |
+ @Feature({"Viewport", "InitialViewportSize"}) |
+ public void testDefaultViewportSize() throws Throwable { |
+ launchContentShellWithUrl("about:blank"); |
+ waitForActiveShellToBeDoneLoading(); |
+ |
+ Context context = getInstrumentation().getTargetContext(); |
+ WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
+ DisplayMetrics metrics = new DisplayMetrics(); |
+ winManager.getDefaultDisplay().getMetrics(metrics); |
+ |
+ // window.devicePixelRatio should match the default display. Only check to 4 decimal places |
johnme
2012/10/30 14:38:23
I might only check to 1dp. For example anywhere in
Sami
2012/10/31 11:12:57
Good point. Done.
|
+ // to allow for rounding. |
+ assertEquals(String.format("%.4g", metrics.density), |
+ String.format("%.4g", evaluateFloatValue("window.devicePixelRatio"))); |
+ |
+ // Screen size should match the default display. |
johnme
2012/10/30 14:38:23
That's not necessarily true. Beverloo and I think
Sami
2012/10/31 11:12:57
That sounds like a different bug. I'll just remove
|
+ assertEquals(metrics.widthPixels, evaluateIntegerValue("screen.width")); |
+ assertEquals(metrics.heightPixels, evaluateIntegerValue("screen.height")); |
+ |
+ // FIXME: We should check the exact expected values for inner and outer sizes, but for |
+ // now we only ensure they are not the same with a non-identity device pixel ratio. |
johnme
2012/10/30 14:38:23
It's not clear why you expect them to be different
Sami
2012/10/31 11:12:57
I've replaced this with the test we designed offli
|
+ if (metrics.density != 1) { |
+ assertFalse(evaluateIntegerValue("window.innerWidth") == |
+ evaluateIntegerValue("window.outerWidth")); |
+ assertFalse(evaluateIntegerValue("window.innerHeight") == |
+ evaluateIntegerValue("window.outerHeight")); |
+ } |
+ } |
+} |