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

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: 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 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.
61 // to allow for rounding.
62 assertEquals(String.format("%.4g", metrics.density),
63 String.format("%.4g", evaluateFloatValue("window.devicePixelRati o")));
64
65 // 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
66 assertEquals(metrics.widthPixels, evaluateIntegerValue("screen.width"));
67 assertEquals(metrics.heightPixels, evaluateIntegerValue("screen.height") );
68
69 // FIXME: We should check the exact expected values for inner and outer sizes, but for
70 // now we only ensure they are not the same with a non-identity device p ixel 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
71 if (metrics.density != 1) {
72 assertFalse(evaluateIntegerValue("window.innerWidth") ==
73 evaluateIntegerValue("window.outerWidth"));
74 assertFalse(evaluateIntegerValue("window.innerHeight") ==
75 evaluateIntegerValue("window.outerHeight"));
76 }
77 }
78 }
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_view_impl.cc » ('j') | content/renderer/render_view_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698