OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 import android.webkit.WebSettings; | 10 import android.webkit.WebSettings; |
(...skipping 12 matching lines...) Expand all Loading... | |
23 import org.chromium.content.browser.ContentSettings; | 23 import org.chromium.content.browser.ContentSettings; |
24 import org.chromium.content.browser.ContentSettings.LayoutAlgorithm; | 24 import org.chromium.content.browser.ContentSettings.LayoutAlgorithm; |
25 import org.chromium.content.browser.ContentViewCore; | 25 import org.chromium.content.browser.ContentViewCore; |
26 import org.chromium.content.browser.test.util.CallbackHelper; | 26 import org.chromium.content.browser.test.util.CallbackHelper; |
27 import org.chromium.content.browser.test.util.Criteria; | 27 import org.chromium.content.browser.test.util.Criteria; |
28 import org.chromium.content.browser.test.util.CriteriaHelper; | 28 import org.chromium.content.browser.test.util.CriteriaHelper; |
29 import org.chromium.content.browser.test.util.HistoryUtils; | 29 import org.chromium.content.browser.test.util.HistoryUtils; |
30 import org.chromium.net.test.util.TestWebServer; | 30 import org.chromium.net.test.util.TestWebServer; |
31 import org.chromium.ui.gfx.DeviceDisplayInfo; | 31 import org.chromium.ui.gfx.DeviceDisplayInfo; |
32 | 32 |
33 import java.util.concurrent.Callable; | |
33 import java.util.regex.Matcher; | 34 import java.util.regex.Matcher; |
34 import java.util.regex.Pattern; | 35 import java.util.regex.Pattern; |
35 import java.util.ArrayList; | 36 import java.util.ArrayList; |
36 import java.util.List; | 37 import java.util.List; |
37 | 38 |
38 /** | 39 /** |
39 * A test suite for ContentSettings class. The key objective is to verify that e ach | 40 * A test suite for ContentSettings class. The key objective is to verify that e ach |
40 * settings applies either to each individual view or to all views of the | 41 * settings applies either to each individual view or to all views of the |
41 * application | 42 * application |
42 */ | 43 */ |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 } | 1101 } |
1101 | 1102 |
1102 private String getData() { | 1103 private String getData() { |
1103 return "<html><head>" + | 1104 return "<html><head>" + |
1104 "<meta name='viewport' content='width=" + VIEWPORT_TAG_LAYOU T_WIDTH + "' />" + | 1105 "<meta name='viewport' content='width=" + VIEWPORT_TAG_LAYOU T_WIDTH + "' />" + |
1105 "</head>" + | 1106 "</head>" + |
1106 "<body onload='document.title=document.body.clientWidth'></b ody></html>"; | 1107 "<body onload='document.title=document.body.clientWidth'></b ody></html>"; |
1107 } | 1108 } |
1108 } | 1109 } |
1109 | 1110 |
1111 class AwSettingsLoadWithOverviewModeTestHelper extends AwSettingsTestHelper< Boolean> { | |
1112 private static final float DEFAULT_PAGE_SCALE = 1.0f; | |
1113 | |
1114 AwSettingsLoadWithOverviewModeTestHelper( | |
1115 AwContents awContents, | |
1116 TestAwContentsClient contentViewClient, | |
1117 boolean withViewPortTag) throws Throwable { | |
1118 super(awContents, contentViewClient, true); | |
1119 mWithViewPortTag = withViewPortTag; | |
1120 mContentSettings.setUseWideViewPort(true); | |
1121 } | |
1122 | |
1123 @Override | |
1124 protected Boolean getAlteredValue() { | |
1125 return ENABLED; | |
1126 } | |
1127 | |
1128 @Override | |
1129 protected Boolean getInitialValue() { | |
1130 return DISABLED; | |
1131 } | |
1132 | |
1133 @Override | |
1134 protected Boolean getCurrentValue() { | |
1135 return mContentSettings.getLoadWithOverviewMode(); | |
1136 } | |
1137 | |
1138 @Override | |
1139 protected void setCurrentValue(Boolean value) { | |
1140 mExpectScaleChange = mContentSettings.getLoadWithOverviewMode() != v alue; | |
1141 if (mExpectScaleChange) { | |
1142 mOnScaleChangedCallCount = | |
1143 mContentViewClient.getOnScaleChangedHelper().getCallCoun t(); | |
1144 } | |
1145 mContentSettings.setLoadWithOverviewMode(value); | |
1146 } | |
1147 | |
1148 @Override | |
1149 protected void doEnsureSettingHasValue(Boolean value) throws Throwable { | |
1150 loadDataSync(getData()); | |
1151 if (mExpectScaleChange) { | |
1152 mContentViewClient.getOnScaleChangedHelper(). | |
1153 waitForCallback(mOnScaleChangedCallCount); | |
1154 mExpectScaleChange = false; | |
1155 } | |
1156 float currentScale = AwSettingsTest.this.getScaleOnUiThread(mAwConte nts); | |
1157 if (value) { | |
1158 assertTrue("Expected: " + currentScale + " < " + DEFAULT_PAGE_SC ALE, | |
1159 currentScale < DEFAULT_PAGE_SCALE); | |
1160 } else { | |
1161 assertEquals(DEFAULT_PAGE_SCALE, currentScale); | |
1162 } | |
1163 } | |
1164 | |
1165 private String getData() { | |
1166 return "<html><head>" + | |
1167 (mWithViewPortTag ? "<meta name='viewport' content='width=30 00' />" : "") + | |
1168 "</head>" + | |
1169 "<body></body></html>"; | |
1170 } | |
1171 | |
1172 private final boolean mWithViewPortTag; | |
1173 private boolean mExpectScaleChange; | |
1174 private int mOnScaleChangedCallCount; | |
1175 } | |
1176 | |
1110 // The test verifies that JavaScript is disabled upon WebView | 1177 // The test verifies that JavaScript is disabled upon WebView |
1111 // creation without accessing ContentSettings. If the test passes, | 1178 // creation without accessing ContentSettings. If the test passes, |
1112 // it means that WebView-specific web preferences configuration | 1179 // it means that WebView-specific web preferences configuration |
1113 // is applied on WebView creation. JS state is used, because it is | 1180 // is applied on WebView creation. JS state is used, because it is |
1114 // enabled by default in Chrome, but must be disabled by default | 1181 // enabled by default in Chrome, but must be disabled by default |
1115 // in WebView. | 1182 // in WebView. |
1116 @SmallTest | 1183 @SmallTest |
1117 @Feature({"AndroidWebView", "Preferences"}) | 1184 @Feature({"AndroidWebView", "Preferences"}) |
1118 public void testJavaScriptDisabledByDefault() throws Throwable { | 1185 public void testJavaScriptDisabledByDefault() throws Throwable { |
1119 final String JS_ENABLED_STRING = "JS has run"; | 1186 final String JS_ENABLED_STRING = "JS has run"; |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2140 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9 80); | 2207 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9 80); |
2141 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth, "text/html", false); | 2208 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth, "text/html", false); |
2142 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); | 2209 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); |
2143 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, | 2210 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, |
2144 Math.abs(displayWidth - actualWidth) <= 1); | 2211 Math.abs(displayWidth - actualWidth) <= 1); |
2145 loadDataSync( | 2212 loadDataSync( |
2146 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t ext/html", false); | 2213 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t ext/html", false); |
2147 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); | 2214 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); |
2148 } | 2215 } |
2149 | 2216 |
2217 @SmallTest | |
2218 @Feature({"AndroidWebView", "Preferences"}) | |
2219 public void testLoadWithOverviewModeWithTwoViews() throws Throwable { | |
2220 ViewPair views = createViews(); | |
2221 runPerViewSettingsTest( | |
2222 new AwSettingsLoadWithOverviewModeTestHelper( | |
2223 views.getContents0(), views.getClient0(), false), | |
2224 new AwSettingsLoadWithOverviewModeTestHelper( | |
2225 views.getContents1(), views.getClient1(), false)); | |
2226 } | |
2227 | |
2228 @SmallTest | |
2229 @Feature({"AndroidWebView", "Preferences"}) | |
2230 public void testLoadWithOverviewModeViewportTagWithTwoViews() throws Throwab le { | |
2231 ViewPair views = createViews(); | |
2232 runPerViewSettingsTest( | |
2233 new AwSettingsLoadWithOverviewModeTestHelper( | |
2234 views.getContents0(), views.getClient0(), true), | |
2235 new AwSettingsLoadWithOverviewModeTestHelper( | |
2236 views.getContents1(), views.getClient1(), true)); | |
2237 } | |
2238 | |
2239 @SmallTest | |
2240 @Feature({"AndroidWebView", "Preferences"}) | |
2241 // Verify that LoadViewOverviewMode doesn't affect pages with initial scale | |
2242 // set in the viewport tag, | |
benm (inactive)
2013/02/14 18:29:38
Is this documented?
nit: s/,/./ ... I had to find
mnaganov (inactive)
2013/02/15 10:30:19
No, figured out experimentally. The JavaDoc is bar
| |
2243 public void testLoadWithOverviewModeViewportScale() throws Throwable { | |
2244 final TestAwContentsClient contentClient = new TestAwContentsClient(); | |
2245 final AwTestContainerView testContainerView = | |
2246 createAwTestContainerViewOnMainSync(contentClient); | |
2247 final AwContents awContents = testContainerView.getAwContents(); | |
2248 ContentSettings settings = getContentSettingsOnUiThread(awContents); | |
2249 CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHel per(); | |
2250 | |
2251 final int pageScale = 2; | |
2252 final String page = "<html><head>" + | |
2253 "<meta name='viewport' content='width=3000, initial-scale=" + pa geScale + | |
2254 "' /></head>" + | |
2255 "<body></body></html>"; | |
2256 | |
2257 assertFalse(settings.getUseWideViewPort()); | |
2258 assertFalse(settings.getLoadWithOverviewMode()); | |
2259 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false) ; | |
2260 assertEquals(1.0f, getScaleOnUiThread(awContents)); | |
2261 | |
2262 settings.setUseWideViewPort(true); | |
2263 settings.setLoadWithOverviewMode(true); | |
2264 int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().ge tCallCount(); | |
2265 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false) ; | |
2266 contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCa llCount); | |
2267 assertEquals((float)pageScale, getScaleOnUiThread(awContents)); | |
2268 } | |
2269 | |
2150 static class ViewPair { | 2270 static class ViewPair { |
2151 private final AwContents contents0; | 2271 private final AwContents contents0; |
2152 private final TestAwContentsClient client0; | 2272 private final TestAwContentsClient client0; |
2153 private final AwContents contents1; | 2273 private final AwContents contents1; |
2154 private final TestAwContentsClient client1; | 2274 private final TestAwContentsClient client1; |
2155 | 2275 |
2156 ViewPair(AwContents contents0, TestAwContentsClient client0, | 2276 ViewPair(AwContents contents0, TestAwContentsClient client0, |
2157 AwContents contents1, TestAwContentsClient client1) { | 2277 AwContents contents1, TestAwContentsClient client1) { |
2158 this.contents0 = contents0; | 2278 this.contents0 = contents0; |
2159 this.client0 = client0; | 2279 this.client0 = client0; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2264 private void useTestResourceContext() { | 2384 private void useTestResourceContext() { |
2265 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation() .getContext()); | 2385 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation() .getContext()); |
2266 } | 2386 } |
2267 | 2387 |
2268 /** | 2388 /** |
2269 * Configure the browser to load resources from the browser application. | 2389 * Configure the browser to load resources from the browser application. |
2270 */ | 2390 */ |
2271 private void resetResourceContext() { | 2391 private void resetResourceContext() { |
2272 AndroidProtocolHandler.setResourceContextForTesting(null); | 2392 AndroidProtocolHandler.setResourceContextForTesting(null); |
2273 } | 2393 } |
2394 | |
2395 private float getScaleOnUiThread(final AwContents awContents) throws Throwab le { | |
2396 return runTestOnUiThreadAndGetResult(new Callable<Float>() { | |
2397 @Override | |
2398 public Float call() throws Exception { | |
2399 return awContents.getContentViewCore().getScale(); | |
2400 } | |
2401 }); | |
2402 } | |
2274 } | 2403 } |
OLD | NEW |