0

[Android WebView] Wire up the viewport quirks settings

Wires up Blink WebSettings introduced in
https://codereview.chromium.org/22909031 and then updated in
https://codereview.chromium.org/23691017

These quirks are to maintain compatibility with Android apps built on
the Android SDK prior to and including version 18. Presumably, this
can be removed any time after 2015.

BUG=277369,282130

Review URL: https://chromiumcodereview.appspot.com/23572016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221557 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
mnaganov@chromium.org
2013-09-06 01:24:46 +00:00
parent 8320026574
commit c6317be87d
10 changed files with 151 additions and 90 deletions

@ -2660,30 +2660,6 @@ public class AwSettingsTest extends AwTestBase {
return TestContentProvider.createContentUrl(target);
}
/**
* Returns pure page scale.
*/
private float getScaleOnUiThread(final AwContents awContents) throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
return awContents.getContentViewCore().getScale();
}
});
}
/**
* Returns page scale multiplied by the screen density.
*/
private float getPixelScaleOnUiThread(final AwContents awContents) throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
return awContents.getScale();
}
});
}
private void simulateDoubleTapCenterOfWebViewOnUiThread(final AwTestContainerView webView)
throws Throwable {
final AwContents awContents = webView.getAwContents();

@ -1,52 +0,0 @@
// 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.Feature;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.ui.gfx.DeviceDisplayInfo;
public class AwTargetDensityDpiTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
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());
float deviceDpi = (float)(160f * 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);
}
}

@ -328,4 +328,28 @@ public class AwTestBase
}
});
}
/**
* Returns pure page scale.
*/
protected float getScaleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
return awContents.getContentViewCore().getScale();
}
});
}
/**
* Returns page scale multiplied by the screen density.
*/
protected float getPixelScaleOnUiThread(final AwContents awContents) throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
return awContents.getScale();
}
});
}
}

@ -0,0 +1,110 @@
// Copyright 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.Feature;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.ui.gfx.DeviceDisplayInfo;
public class AwViewportTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
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());
float deviceDpi = (float)(160f * 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);
}
@MediumTest
@Feature({"AndroidWebView"})
public void testWideViewportInitialScaleDoesNotExpandFixedLayoutWidth() 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 page = "<html><head>" +
"<meta name='viewport' content='width=device-width, initial-scale=0.5' />" +
"</head><body onload='document.title=document.body.clientWidth'></body></html>";
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
DeviceDisplayInfo deviceInfo =
DeviceDisplayInfo.create(getInstrumentation().getTargetContext());
loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
float displayWidth = (float)(deviceInfo.getDisplayWidth() / deviceInfo.getDIPScale());
int actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
assertEquals(displayWidth, (float)actualWidth, 10f);
assertEquals(1.0f, getScaleOnUiThread(awContents));
}
@MediumTest
@Feature({"AndroidWebView"})
public void testZeroValuesQuirk() 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 page = "<html><head>" +
"<meta name='viewport' content='width=0, height=0, initial-scale=0.0, " +
" minimum-scale=0.0, maximum-scale=0.0' />" +
"</head><body onload='document.title=document.body.clientWidth'></body></html>";
settings.setJavaScriptEnabled(true);
DeviceDisplayInfo deviceInfo =
DeviceDisplayInfo.create(getInstrumentation().getTargetContext());
loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
float displayWidth = (float)(deviceInfo.getDisplayWidth() / deviceInfo.getDIPScale());
int actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
assertEquals(displayWidth, (float)actualWidth, 10f);
assertEquals(1.0f, getScaleOnUiThread(awContents));
settings.setUseWideViewPort(true);
loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
assertEquals(displayWidth, (float)actualWidth, 10f);
assertEquals(1.0f, getScaleOnUiThread(awContents));
}
}

@ -91,15 +91,6 @@ public class AwZoomTest extends AwTestBase {
});
}
private float getScaleOnUiThread() throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
return mAwContents.getScale();
}
});
}
private View getZoomControlsOnUiThread() throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<View>() {
@Override
@ -119,7 +110,7 @@ public class AwZoomTest extends AwTestBase {
}
private boolean zoomInOnUiThreadAndWait() throws Throwable {
final float previousScale = getScaleOnUiThread();
final float previousScale = getPixelScaleOnUiThread(mAwContents);
if (!runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@ -132,7 +123,7 @@ public class AwZoomTest extends AwTestBase {
}
private boolean zoomOutOnUiThreadAndWait() throws Throwable {
final float previousScale = getScaleOnUiThread();
final float previousScale = getPixelScaleOnUiThread(mAwContents);
if (!runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@ -149,10 +140,10 @@ public class AwZoomTest extends AwTestBase {
@Override
public boolean isSatisfied() {
try {
return previousScale != getScaleOnUiThread();
return previousScale != getPixelScaleOnUiThread(mAwContents);
} catch (Throwable t) {
t.printStackTrace();
fail("Failed to getScaleOnUiThread: " + t.toString());
fail("Failed to getPixelScaleOnUiThread: " + t.toString());
return false;
}
}

@ -206,6 +206,8 @@ void AwSettings::UpdateWebkitPreferencesLocked(JNIEnv* env, jobject obj) {
bool support_quirks = Java_AwSettings_getSupportLegacyQuirksLocked(env, obj);
prefs.support_deprecated_target_density_dpi = support_quirks;
prefs.use_legacy_background_size_shorthand_behavior = support_quirks;
prefs.viewport_meta_layout_size_quirk = support_quirks;
prefs.viewport_meta_zero_values_quirk = support_quirks;
prefs.password_echo_enabled =
Java_AwSettings_getPasswordEchoEnabled(env, obj);

@ -204,6 +204,8 @@ IPC_STRUCT_TRAITS_BEGIN(WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(support_deprecated_target_density_dpi)
IPC_STRUCT_TRAITS_MEMBER(use_legacy_background_size_shorthand_behavior)
IPC_STRUCT_TRAITS_MEMBER(use_wide_viewport)
IPC_STRUCT_TRAITS_MEMBER(viewport_meta_layout_size_quirk)
IPC_STRUCT_TRAITS_MEMBER(viewport_meta_zero_values_quirk)
#endif
IPC_STRUCT_TRAITS_END()

@ -338,6 +338,10 @@ void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
settings->setUseLegacyBackgroundSizeShorthandBehavior(
prefs.use_legacy_background_size_shorthand_behavior);
settings->setUseWideViewport(prefs.use_wide_viewport);
settings->setViewportMetaLayoutSizeQuirk(
prefs.viewport_meta_layout_size_quirk);
settings->setViewportMetaZeroValuesQuirk(
prefs.viewport_meta_zero_values_quirk);
#endif
WebNetworkStateNotifier::setOnLine(prefs.is_online);

@ -128,7 +128,9 @@ WebPreferences::WebPreferences()
user_gesture_required_for_media_playback(true),
support_deprecated_target_density_dpi(false),
use_legacy_background_size_shorthand_behavior(false),
use_wide_viewport(true)
use_wide_viewport(true),
viewport_meta_layout_size_quirk(false),
viewport_meta_zero_values_quirk(false)
#endif
{
standard_font_family_map[webkit_glue::kCommonScript] =

@ -172,6 +172,8 @@ struct WEBKIT_COMMON_EXPORT WebPreferences {
bool support_deprecated_target_density_dpi;
bool use_legacy_background_size_shorthand_behavior;
bool use_wide_viewport;
bool viewport_meta_layout_size_quirk;
bool viewport_meta_zero_values_quirk;
#endif
// We try to keep the default values the same as the default values in