Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / ViewportTest.java
1 // Copyright 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.util.DisplayMetrics;
9 import android.view.WindowManager;
10
11 import org.chromium.base.test.util.DisabledTest;
12 import org.chromium.content.browser.test.util.JavaScriptUtils;
13
14 /**
15  * Test suite for viewport-related properties.
16  */
17 public class ViewportTest extends ContentViewTestBase {
18
19     protected String evaluateStringValue(String expression) throws Throwable {
20         return JavaScriptUtils.executeJavaScriptAndWaitForResult(getWebContents(),
21                 expression);
22     }
23
24     protected float evaluateFloatValue(String expression) throws Throwable {
25         return Float.valueOf(evaluateStringValue(expression));
26     }
27
28     protected int evaluateIntegerValue(String expression) throws Throwable {
29         return Integer.parseInt(evaluateStringValue(expression));
30     }
31
32     /*
33     @MediumTest
34     @Feature({"Viewport", "InitialViewportSize"})
35     https://bugs.webkit.org/show_bug.cgi?id=107424
36     */
37     @DisabledTest
38     public void testDefaultViewportSize() throws Throwable {
39         launchContentShellWithUrl("about:blank");
40         waitForActiveShellToBeDoneLoading();
41
42         Context context = getInstrumentation().getTargetContext();
43         WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
44         DisplayMetrics metrics = new DisplayMetrics();
45         winManager.getDefaultDisplay().getMetrics(metrics);
46
47         // window.devicePixelRatio should match the default display. Only check to 1 decimal place
48         // to allow for rounding.
49         assertEquals(metrics.density, evaluateFloatValue("window.devicePixelRatio"), 0.1);
50
51         // Check that the viewport width is vaguely sensible.
52         int viewportWidth = evaluateIntegerValue("document.documentElement.clientWidth");
53         assertTrue(Math.abs(evaluateIntegerValue("window.innerWidth") - viewportWidth) <= 1);
54         assertTrue(viewportWidth >= 979);
55         assertTrue(viewportWidth <= Math.max(981, metrics.widthPixels / metrics.density + 1));
56     }
57 }