// Copyright (c) 2013 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.android_webview.test;

import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwSettings;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.ui.gfx.DeviceDisplayInfo;


public class AwTargetDensityDpiTest extends AwTestBase {

    /**
      * @MediumTest
      * @Feature({"AndroidWebView"})
      *
      * TODO(mkosiba): This is disabled only temporarily to enable the WebKit roll that contains
      * http://crrev.com/22574004
      */
    @DisabledTest
    public void testTargetDensityDpi() throws Throwable {
        final TestAwContentsClient contentClient = new TestAwContentsClient();
        final AwTestContainerView testContainerView =
                createAwTestContainerViewOnMainSync(contentClient);
        final AwContents awContents = testContainerView.getAwContents();
        AwSettings settings = getAwSettingsOnUiThread(awContents);
        CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper();

        final String pageTemplate = "<html><head>" +
                "<meta name='viewport' content='width=device-width, target-densityDpi=%s' />" +
                "</head><body onload='document.title=document.body.clientWidth'></body></html>";
        final String pageDeviceDpi = String.format(pageTemplate, "device-dpi");
        final String pageHighDpi = String.format(pageTemplate, "high-dpi");
        final String pageDpi100 = String.format(pageTemplate, "100");

        settings.setJavaScriptEnabled(true);

        DeviceDisplayInfo deviceInfo =
                DeviceDisplayInfo.create(getInstrumentation().getTargetContext());
        loadDataSync(awContents, onPageFinishedHelper, pageDeviceDpi, "text/html", false);
        int actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
        assertEquals((float)deviceInfo.getDisplayWidth(), (float)actualWidth, 10f);

        float displayWidth = (float)(deviceInfo.getDisplayWidth() / deviceInfo.getDIPScale());
        float deviceDpi = (float)(120f * deviceInfo.getDIPScale());
        loadDataSync(awContents, onPageFinishedHelper, pageHighDpi, "text/html", false);
        actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
        assertEquals(displayWidth * (240f / deviceDpi), (float)actualWidth, 10f);

        loadDataSync(awContents, onPageFinishedHelper, pageDpi100, "text/html", false);
        actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
        assertEquals(displayWidth * (100f / deviceDpi), (float)actualWidth, 10f);
    }
}

@@ -363,57 +363,8 @@
 gs;%0A
-import org.chromium.base.test.util.DisabledTest;%0A
 impo
@@ -403,16 +403,16 @@
 eature;%0A
+
 import o
@@ -512,17 +512,16 @@
 yInfo;%0A%0A
-%0A
 public c
@@ -577,20 +577,8 @@
 %0A   
- /**%0A      *
  @Me
@@ -589,20 +589,16 @@
 Test%0A   
-   *
  @Featur
@@ -623,174 +623,8 @@
 %22%7D)%0A
-      *%0A      * TODO(mkosiba): This is disabled only temporarily to enable the WebKit roll that contains%0A      * http://crrev.com/22574004%0A      */%0A    @DisabledTest%0A
     
@@ -2068,35 +2068,8 @@
 th()
- / deviceInfo.getDIPScale()
 );%0A 
@@ -2102,17 +2102,17 @@
 float)(1
-2
+6
 0f * dev
@@ -2131,24 +2131,25 @@
 IPScale());%0A
+%0A
         load

Update testTargetDensityDpi expectations.