diff options
author | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 17:16:02 +0000 |
---|---|---|
committer | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 17:16:02 +0000 |
commit | 5c90d03daec06693271c4ec0066a452e7a7e7b8a (patch) | |
tree | bd0ee5087c976526fc557eff46a71aff5874c195 /android_webview | |
parent | d830c09a119ef8fdb996c54cf7dc27696a12c637 (diff) | |
download | chromium_src-5c90d03daec06693271c4ec0066a452e7a7e7b8a.zip chromium_src-5c90d03daec06693271c4ec0066a452e7a7e7b8a.tar.gz chromium_src-5c90d03daec06693271c4ec0066a452e7a7e7b8a.tar.bz2 |
[Android WebView] Implement WebSettings.{get|set}UseWideViewport
The setting is mapped directly onto WebKit's WebSettings.viewportEnabled
R=benm@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11759023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
3 files changed, 131 insertions, 0 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java index 6d1b840..ac4d11b 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java @@ -56,6 +56,7 @@ public class AwContentsClientOnScaleChangedTest extends AndroidWebViewTestBase { @SmallTest public void testScaleUp() throws Throwable { + getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), CommonResources.ABOUT_HTML, "text/html", false); ContentViewCore core = mAwContents.getContentViewCore(); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java index 803dc6b..261c108 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java @@ -26,6 +26,7 @@ import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.HistoryUtils; +import org.chromium.content.common.DeviceInfo; import org.chromium.net.test.util.TestWebServer; import java.util.regex.Matcher; @@ -848,6 +849,8 @@ public class AwSettingsTest extends AndroidWebViewTestBase { AwContents awContents, TestAwContentsClient contentViewClient) throws Throwable { super(awContents, contentViewClient); + // Font autosizing doesn't step in for narrow layout widths. + mContentSettings.setUseWideViewPort(true); } @Override @@ -1051,6 +1054,59 @@ public class AwSettingsTest extends AndroidWebViewTestBase { private TestWebServer mWebServer; } + // To verify whether UseWideViewport works, we check, if the page width specified + // in the "meta viewport" tag is applied. When UseWideViewport is turned off, the + // "viewport" tag is ignored, and the layout width is set to device width in DIP pixels. + // We specify a very high width value to make sure that it doesn't intersect with + // device screen widths (in DIP pixels). + class AwSettingsUseWideViewportTestHelper extends AwSettingsTestHelper<Boolean> { + static private final String VIEWPORT_TAG_LAYOUT_WIDTH = "3000"; + + AwSettingsUseWideViewportTestHelper( + AwContents awContents, + TestAwContentsClient contentViewClient) throws Throwable { + super(awContents, contentViewClient, true); + } + + @Override + protected Boolean getAlteredValue() { + return ENABLED; + } + + @Override + protected Boolean getInitialValue() { + return DISABLED; + } + + @Override + protected Boolean getCurrentValue() { + return mContentSettings.getUseWideViewPort(); + } + + @Override + protected void setCurrentValue(Boolean value) { + mContentSettings.setUseWideViewPort(value); + } + + @Override + protected void doEnsureSettingHasValue(Boolean value) throws Throwable { + loadDataSync(getData()); + final String bodyWidth = getTitleOnUiThread(); + if (value) { + assertTrue(bodyWidth, VIEWPORT_TAG_LAYOUT_WIDTH.equals(bodyWidth)); + } else { + assertFalse(bodyWidth, VIEWPORT_TAG_LAYOUT_WIDTH.equals(bodyWidth)); + } + } + + private String getData() { + return "<html><head>" + + "<meta name='viewport' content='width=" + VIEWPORT_TAG_LAYOUT_WIDTH + "' />" + + "</head>" + + "<body onload='document.title=document.body.clientWidth'></body></html>"; + } + } + // The test verifies that JavaScript is disabled upon WebView // creation without accessing ContentSettings. If the test passes, // it means that WebView-specific web preferences configuration @@ -2012,6 +2068,75 @@ public class AwSettingsTest extends AndroidWebViewTestBase { } } + @SmallTest + @Feature({"AndroidWebView", "Preferences"}) + public void testUseWideViewportWithTwoViews() throws Throwable { + ViewPair views = createViews(); + runPerViewSettingsTest( + new AwSettingsUseWideViewportTestHelper(views.getContents0(), views.getClient0()), + new AwSettingsUseWideViewportTestHelper(views.getContents1(), views.getClient1())); + } + + @SmallTest + @Feature({"AndroidWebView", "Preferences"}) + public void testUseWideViewportLayoutWidth() throws Throwable { + final TestAwContentsClient contentClient = new TestAwContentsClient(); + final AwTestContainerView testContainerView = + createAwTestContainerViewOnMainSync(contentClient); + final AwContents awContents = testContainerView.getAwContents(); + ContentSettings settings = getContentSettingsOnUiThread(awContents); + CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper(); + + final String pageTemplate = "<html><head>%s</head>" + + "<body onload='document.title=document.body.clientWidth'></body></html>"; + final String pageNoViewport = String.format(pageTemplate, ""); + final String pageViewportDeviceWidth = String.format( + pageTemplate, + "<meta name='viewport' content='width=device-width' />"); + final String viewportTagSpecifiedWidth = "3000"; + final String pageViewportSpecifiedWidth = String.format( + pageTemplate, + "<meta name='viewport' content='width=" + viewportTagSpecifiedWidth + "' />"); + + DeviceInfo deviceInfo = DeviceInfo.create(getInstrumentation().getTargetContext()); + int displayWidth = (int) (deviceInfo.getWidth() / deviceInfo.getDPIScale()); + + settings.setJavaScriptEnabled(true); + assertFalse(settings.getUseWideViewPort()); + // When UseWideViewPort is off, "meta viewport" tags are ignored, + // and the layout width is set to device width in CSS pixels. + // Thus, all 3 pages will have the same body width. + loadDataSync(awContents, onPageFinishedHelper, pageNoViewport, "text/html", false); + int actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); + // Avoid rounding errors. + assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, + Math.abs(displayWidth - actualWidth) <= 1); + loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth, "text/html", false); + actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); + assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, + Math.abs(displayWidth - actualWidth) <= 1); + loadDataSync( + awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "text/html", false); + actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); + assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, + Math.abs(displayWidth - actualWidth) <= 1); + + settings.setUseWideViewPort(true); + // When UseWideViewPort is on, "meta viewport" tag is used. + // If there is no viewport tag, or width isn't specified, + // then layout width is set to max(980, <device-width-in-DIP-pixels>) + loadDataSync(awContents, onPageFinishedHelper, pageNoViewport, "text/html", false); + actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); + assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 980); + loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth, "text/html", false); + actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); + assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, + Math.abs(displayWidth - actualWidth) <= 1); + loadDataSync( + awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "text/html", false); + assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); + } + static class ViewPair { private final AwContents contents0; private final TestAwContentsClient client0; diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewZoomTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewZoomTest.java index b9bfd5b..13bbae8 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewZoomTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewZoomTest.java @@ -193,6 +193,7 @@ public class ContentViewZoomTest extends AndroidWebViewTestBase { } private void runMagnificationTest(boolean supportZoom) throws Throwable { + getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), getZoomableHtml(), "text/html", false); // It takes some time for scaling to settle down. @@ -238,6 +239,7 @@ public class ContentViewZoomTest extends AndroidWebViewTestBase { @Feature({"AndroidWebView"}) public void testZoomUsingMultiTouch() throws Throwable { ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); + webSettings.setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), getZoomableHtml(), "text/html", false); @@ -260,6 +262,7 @@ public class ContentViewZoomTest extends AndroidWebViewTestBase { @FlakyTest public void testZoomControls() throws Throwable { ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); + webSettings.setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), getZoomableHtml(), "text/html", false); @@ -284,6 +287,7 @@ public class ContentViewZoomTest extends AndroidWebViewTestBase { @Feature({"AndroidWebView"}) public void testZoomControlsOnNonZoomableContent() throws Throwable { ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); + webSettings.setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), getNonZoomableHtml(), "text/html", false); @@ -307,6 +311,7 @@ public class ContentViewZoomTest extends AndroidWebViewTestBase { @DisabledTest public void testZoomControlsOnOrientationChange() throws Throwable { ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); + webSettings.setUseWideViewPort(true); loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), getZoomableHtml(), "text/html", false); |