OLD | NEW |
---|---|
(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); | |
bulach
2012/11/06 13:42:09
nit: aren't 979 / 981 device and orientation depen
johnme
2012/11/06 15:45:34
Nope, Clank's minimum viewport width for desktop s
Sami
2012/11/06 17:08:47
Thanks for confirming that John. I also checked th
| |
69 assertTrue(viewportWidth <= Math.max(981, metrics.widthPixels / metrics. density + 1)); | |
70 } | |
71 } | |
OLD | NEW |