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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java

Issue 11348033: Initialize device scale factor correctly on Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't truncate scale factor on Chrome OS. Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import android.content.Context;
8 import android.test.suitebuilder.annotation.MediumTest;
9 import android.util.DisplayMetrics;
10 import android.view.Display;
11 import android.view.WindowManager;
12
13 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.test.util.JavaScriptUtils;
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
16 import org.chromium.content.common.DeviceInfo;
17
18 /**
19 * Test suite for viewport-related properties.
20 */
21 public class ViewportTest extends ContentViewTestBase {
22
23 private TestCallbackHelperContainer mCallbackHelper;
24
25 /**
26 * Returns the TestCallbackHelperContainer associated with this ContentView,
27 * or creates it lazily.
28 */
29 protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
30 if (mCallbackHelper == null) {
31 mCallbackHelper = new TestCallbackHelperContainer(getContentView());
32 }
33 return mCallbackHelper;
34 }
35
36 protected String evaluateStringValue(String expression) throws Throwable {
37 return JavaScriptUtils.executeJavaScriptAndWaitForResult(this, getConten tView(),
38 getTestCallbackHelperContainer(), expression);
39 }
40
41 protected float evaluateFloatValue(String expression) throws Throwable {
42 return Float.valueOf(evaluateStringValue(expression));
43 }
44
45 protected int evaluateIntegerValue(String expression) throws Throwable {
46 return Integer.valueOf(evaluateStringValue(expression));
47 }
48
49 @MediumTest
50 @Feature({"Viewport", "InitialViewportSize"})
51 public void testDefaultViewportSize() throws Throwable {
52 launchContentShellWithUrl("about:blank");
53 waitForActiveShellToBeDoneLoading();
54
55 Context context = getInstrumentation().getTargetContext();
56 WindowManager winManager = (WindowManager) context.getSystemService(Cont ext.WINDOW_SERVICE);
57 DisplayMetrics metrics = new DisplayMetrics();
58 winManager.getDefaultDisplay().getMetrics(metrics);
59
60 // window.devicePixelRatio should match the default display. Only check to 1 decimal place
61 // to allow for rounding.
62 assertEquals(String.format("%.1g", metrics.density),
63 String.format("%.1g", evaluateFloatValue("window.devicePixelRati o")));
64
65 // Check that the viewport width is vaguely sensible.
66 int viewportWidth = evaluateIntegerValue("document.documentElement.clien tWidth");
67 assertTrue(Math.abs(evaluateIntegerValue("window.innerWidth") - viewport Width) <= 1);
68 assertTrue(viewportWidth >= 979);
69 assertTrue(viewportWidth <= Math.max(981, metrics.widthPixels / metrics. density + 1));
70 }
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698