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 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 } | 1193 } |
1193 | 1194 |
1194 private String getData() { | 1195 private String getData() { |
1195 return "<html><head>" + | 1196 return "<html><head>" + |
1196 "<meta name='viewport' content='width=" + VIEWPORT_TAG_LAYOU
T_WIDTH + "' />" + | 1197 "<meta name='viewport' content='width=" + VIEWPORT_TAG_LAYOU
T_WIDTH + "' />" + |
1197 "</head>" + | 1198 "</head>" + |
1198 "<body onload='document.title=document.body.clientWidth'></b
ody></html>"; | 1199 "<body onload='document.title=document.body.clientWidth'></b
ody></html>"; |
1199 } | 1200 } |
1200 } | 1201 } |
1201 | 1202 |
| 1203 class AwSettingsLoadWithOverviewModeTestHelper extends AwSettingsTestHelper<
Boolean> { |
| 1204 private static final float DEFAULT_PAGE_SCALE = 1.0f; |
| 1205 |
| 1206 AwSettingsLoadWithOverviewModeTestHelper( |
| 1207 AwContents awContents, |
| 1208 TestAwContentsClient contentViewClient, |
| 1209 boolean withViewPortTag) throws Throwable { |
| 1210 super(awContents, contentViewClient, true); |
| 1211 mWithViewPortTag = withViewPortTag; |
| 1212 mContentSettings.setUseWideViewPort(true); |
| 1213 } |
| 1214 |
| 1215 @Override |
| 1216 protected Boolean getAlteredValue() { |
| 1217 return ENABLED; |
| 1218 } |
| 1219 |
| 1220 @Override |
| 1221 protected Boolean getInitialValue() { |
| 1222 return DISABLED; |
| 1223 } |
| 1224 |
| 1225 @Override |
| 1226 protected Boolean getCurrentValue() { |
| 1227 return mContentSettings.getLoadWithOverviewMode(); |
| 1228 } |
| 1229 |
| 1230 @Override |
| 1231 protected void setCurrentValue(Boolean value) { |
| 1232 mExpectScaleChange = mContentSettings.getLoadWithOverviewMode() != v
alue; |
| 1233 if (mExpectScaleChange) { |
| 1234 mOnScaleChangedCallCount = |
| 1235 mContentViewClient.getOnScaleChangedHelper().getCallCoun
t(); |
| 1236 } |
| 1237 mContentSettings.setLoadWithOverviewMode(value); |
| 1238 } |
| 1239 |
| 1240 @Override |
| 1241 protected void doEnsureSettingHasValue(Boolean value) throws Throwable { |
| 1242 loadDataSync(getData()); |
| 1243 if (mExpectScaleChange) { |
| 1244 mContentViewClient.getOnScaleChangedHelper(). |
| 1245 waitForCallback(mOnScaleChangedCallCount); |
| 1246 mExpectScaleChange = false; |
| 1247 } |
| 1248 float currentScale = AwSettingsTest.this.getScaleOnUiThread(mAwConte
nts); |
| 1249 if (value) { |
| 1250 assertTrue("Expected: " + currentScale + " < " + DEFAULT_PAGE_SC
ALE, |
| 1251 currentScale < DEFAULT_PAGE_SCALE); |
| 1252 } else { |
| 1253 assertEquals(DEFAULT_PAGE_SCALE, currentScale); |
| 1254 } |
| 1255 } |
| 1256 |
| 1257 private String getData() { |
| 1258 return "<html><head>" + |
| 1259 (mWithViewPortTag ? "<meta name='viewport' content='width=30
00' />" : "") + |
| 1260 "</head>" + |
| 1261 "<body></body></html>"; |
| 1262 } |
| 1263 |
| 1264 private final boolean mWithViewPortTag; |
| 1265 private boolean mExpectScaleChange; |
| 1266 private int mOnScaleChangedCallCount; |
| 1267 } |
| 1268 |
1202 // The test verifies that JavaScript is disabled upon WebView | 1269 // The test verifies that JavaScript is disabled upon WebView |
1203 // creation without accessing ContentSettings. If the test passes, | 1270 // creation without accessing ContentSettings. If the test passes, |
1204 // it means that WebView-specific web preferences configuration | 1271 // it means that WebView-specific web preferences configuration |
1205 // is applied on WebView creation. JS state is used, because it is | 1272 // is applied on WebView creation. JS state is used, because it is |
1206 // enabled by default in Chrome, but must be disabled by default | 1273 // enabled by default in Chrome, but must be disabled by default |
1207 // in WebView. | 1274 // in WebView. |
1208 @SmallTest | 1275 @SmallTest |
1209 @Feature({"AndroidWebView", "Preferences"}) | 1276 @Feature({"AndroidWebView", "Preferences"}) |
1210 public void testJavaScriptDisabledByDefault() throws Throwable { | 1277 public void testJavaScriptDisabledByDefault() throws Throwable { |
1211 final String JS_ENABLED_STRING = "JS has run"; | 1278 final String JS_ENABLED_STRING = "JS has run"; |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2279 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9
80); | 2346 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9
80); |
2280 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth,
"text/html", false); | 2347 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth,
"text/html", false); |
2281 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); | 2348 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); |
2282 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, | 2349 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, |
2283 Math.abs(displayWidth - actualWidth) <= 1); | 2350 Math.abs(displayWidth - actualWidth) <= 1); |
2284 loadDataSync( | 2351 loadDataSync( |
2285 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t
ext/html", false); | 2352 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t
ext/html", false); |
2286 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); | 2353 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); |
2287 } | 2354 } |
2288 | 2355 |
| 2356 @SmallTest |
| 2357 @Feature({"AndroidWebView", "Preferences"}) |
| 2358 public void testLoadWithOverviewModeWithTwoViews() throws Throwable { |
| 2359 ViewPair views = createViews(); |
| 2360 runPerViewSettingsTest( |
| 2361 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2362 views.getContents0(), views.getClient0(), false), |
| 2363 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2364 views.getContents1(), views.getClient1(), false)); |
| 2365 } |
| 2366 |
| 2367 @SmallTest |
| 2368 @Feature({"AndroidWebView", "Preferences"}) |
| 2369 public void testLoadWithOverviewModeViewportTagWithTwoViews() throws Throwab
le { |
| 2370 ViewPair views = createViews(); |
| 2371 runPerViewSettingsTest( |
| 2372 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2373 views.getContents0(), views.getClient0(), true), |
| 2374 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2375 views.getContents1(), views.getClient1(), true)); |
| 2376 } |
| 2377 |
| 2378 @SmallTest |
| 2379 @Feature({"AndroidWebView", "Preferences"}) |
| 2380 // Verify that LoadViewOverviewMode doesn't affect pages with initial scale |
| 2381 // set in the viewport tag. |
| 2382 public void testLoadWithOverviewModeViewportScale() throws Throwable { |
| 2383 final TestAwContentsClient contentClient = new TestAwContentsClient(); |
| 2384 final AwTestContainerView testContainerView = |
| 2385 createAwTestContainerViewOnMainSync(contentClient); |
| 2386 final AwContents awContents = testContainerView.getAwContents(); |
| 2387 ContentSettings settings = getContentSettingsOnUiThread(awContents); |
| 2388 CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHel
per(); |
| 2389 |
| 2390 final int pageScale = 2; |
| 2391 final String page = "<html><head>" + |
| 2392 "<meta name='viewport' content='width=3000, initial-scale=" + pa
geScale + |
| 2393 "' /></head>" + |
| 2394 "<body></body></html>"; |
| 2395 |
| 2396 assertFalse(settings.getUseWideViewPort()); |
| 2397 assertFalse(settings.getLoadWithOverviewMode()); |
| 2398 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false)
; |
| 2399 assertEquals(1.0f, getScaleOnUiThread(awContents)); |
| 2400 |
| 2401 settings.setUseWideViewPort(true); |
| 2402 settings.setLoadWithOverviewMode(true); |
| 2403 int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().ge
tCallCount(); |
| 2404 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false)
; |
| 2405 contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCa
llCount); |
| 2406 assertEquals((float)pageScale, getScaleOnUiThread(awContents)); |
| 2407 } |
| 2408 |
2289 static class ViewPair { | 2409 static class ViewPair { |
2290 private final AwContents contents0; | 2410 private final AwContents contents0; |
2291 private final TestAwContentsClient client0; | 2411 private final TestAwContentsClient client0; |
2292 private final AwContents contents1; | 2412 private final AwContents contents1; |
2293 private final TestAwContentsClient client1; | 2413 private final TestAwContentsClient client1; |
2294 | 2414 |
2295 ViewPair(AwContents contents0, TestAwContentsClient client0, | 2415 ViewPair(AwContents contents0, TestAwContentsClient client0, |
2296 AwContents contents1, TestAwContentsClient client1) { | 2416 AwContents contents1, TestAwContentsClient client1) { |
2297 this.contents0 = contents0; | 2417 this.contents0 = contents0; |
2298 this.client0 = client0; | 2418 this.client0 = client0; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 private void useTestResourceContext() { | 2523 private void useTestResourceContext() { |
2404 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); | 2524 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); |
2405 } | 2525 } |
2406 | 2526 |
2407 /** | 2527 /** |
2408 * Configure the browser to load resources from the browser application. | 2528 * Configure the browser to load resources from the browser application. |
2409 */ | 2529 */ |
2410 private void resetResourceContext() { | 2530 private void resetResourceContext() { |
2411 AndroidProtocolHandler.setResourceContextForTesting(null); | 2531 AndroidProtocolHandler.setResourceContextForTesting(null); |
2412 } | 2532 } |
| 2533 |
| 2534 private float getScaleOnUiThread(final AwContents awContents) throws Throwab
le { |
| 2535 return runTestOnUiThreadAndGetResult(new Callable<Float>() { |
| 2536 @Override |
| 2537 public Float call() throws Exception { |
| 2538 return awContents.getContentViewCore().getScale(); |
| 2539 } |
| 2540 }); |
| 2541 } |
2413 } | 2542 } |
OLD | NEW |