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 mAwContents.resetScrollAndScaleState(); |
| 1239 } |
| 1240 |
| 1241 @Override |
| 1242 protected void doEnsureSettingHasValue(Boolean value) throws Throwable { |
| 1243 loadDataSync(getData()); |
| 1244 if (mExpectScaleChange) { |
| 1245 mContentViewClient.getOnScaleChangedHelper(). |
| 1246 waitForCallback(mOnScaleChangedCallCount); |
| 1247 mExpectScaleChange = false; |
| 1248 } |
| 1249 float currentScale = AwSettingsTest.this.getScaleOnUiThread(mAwConte
nts); |
| 1250 if (value) { |
| 1251 assertTrue("Expected: " + currentScale + " < " + DEFAULT_PAGE_SC
ALE, |
| 1252 currentScale < DEFAULT_PAGE_SCALE); |
| 1253 } else { |
| 1254 assertEquals(DEFAULT_PAGE_SCALE, currentScale); |
| 1255 } |
| 1256 } |
| 1257 |
| 1258 private String getData() { |
| 1259 return "<html><head>" + |
| 1260 (mWithViewPortTag ? "<meta name='viewport' content='width=30
00' />" : "") + |
| 1261 "</head>" + |
| 1262 "<body></body></html>"; |
| 1263 } |
| 1264 |
| 1265 private final boolean mWithViewPortTag; |
| 1266 private boolean mExpectScaleChange; |
| 1267 private int mOnScaleChangedCallCount; |
| 1268 } |
| 1269 |
1202 // The test verifies that JavaScript is disabled upon WebView | 1270 // The test verifies that JavaScript is disabled upon WebView |
1203 // creation without accessing ContentSettings. If the test passes, | 1271 // creation without accessing ContentSettings. If the test passes, |
1204 // it means that WebView-specific web preferences configuration | 1272 // it means that WebView-specific web preferences configuration |
1205 // is applied on WebView creation. JS state is used, because it is | 1273 // is applied on WebView creation. JS state is used, because it is |
1206 // enabled by default in Chrome, but must be disabled by default | 1274 // enabled by default in Chrome, but must be disabled by default |
1207 // in WebView. | 1275 // in WebView. |
1208 @SmallTest | 1276 @SmallTest |
1209 @Feature({"AndroidWebView", "Preferences"}) | 1277 @Feature({"AndroidWebView", "Preferences"}) |
1210 public void testJavaScriptDisabledByDefault() throws Throwable { | 1278 public void testJavaScriptDisabledByDefault() throws Throwable { |
1211 final String JS_ENABLED_STRING = "JS has run"; | 1279 final String JS_ENABLED_STRING = "JS has run"; |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9
80); | 2352 assertTrue("Expected: >= 980 , Actual: " + actualWidth, actualWidth >= 9
80); |
2285 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth,
"text/html", false); | 2353 loadDataSync(awContents, onPageFinishedHelper, pageViewportDeviceWidth,
"text/html", false); |
2286 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); | 2354 actualWidth = Integer.parseInt(getTitleOnUiThread(awContents)); |
2287 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, | 2355 assertTrue("Expected: " + displayWidth + ", Actual: " + actualWidth, |
2288 Math.abs(displayWidth - actualWidth) <= 1); | 2356 Math.abs(displayWidth - actualWidth) <= 1); |
2289 loadDataSync( | 2357 loadDataSync( |
2290 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t
ext/html", false); | 2358 awContents, onPageFinishedHelper, pageViewportSpecifiedWidth, "t
ext/html", false); |
2291 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); | 2359 assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); |
2292 } | 2360 } |
2293 | 2361 |
| 2362 @SmallTest |
| 2363 @Feature({"AndroidWebView", "Preferences"}) |
| 2364 public void testLoadWithOverviewModeWithTwoViews() throws Throwable { |
| 2365 ViewPair views = createViews(); |
| 2366 runPerViewSettingsTest( |
| 2367 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2368 views.getContents0(), views.getClient0(), false), |
| 2369 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2370 views.getContents1(), views.getClient1(), false)); |
| 2371 } |
| 2372 |
| 2373 @SmallTest |
| 2374 @Feature({"AndroidWebView", "Preferences"}) |
| 2375 public void testLoadWithOverviewModeViewportTagWithTwoViews() throws Throwab
le { |
| 2376 ViewPair views = createViews(); |
| 2377 runPerViewSettingsTest( |
| 2378 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2379 views.getContents0(), views.getClient0(), true), |
| 2380 new AwSettingsLoadWithOverviewModeTestHelper( |
| 2381 views.getContents1(), views.getClient1(), true)); |
| 2382 } |
| 2383 |
| 2384 @SmallTest |
| 2385 @Feature({"AndroidWebView", "Preferences"}) |
| 2386 // Verify that LoadViewOverviewMode doesn't affect pages with initial scale |
| 2387 // set in the viewport tag. |
| 2388 public void testLoadWithOverviewModeViewportScale() throws Throwable { |
| 2389 final TestAwContentsClient contentClient = new TestAwContentsClient(); |
| 2390 final AwTestContainerView testContainerView = |
| 2391 createAwTestContainerViewOnMainSync(contentClient); |
| 2392 final AwContents awContents = testContainerView.getAwContents(); |
| 2393 ContentSettings settings = getContentSettingsOnUiThread(awContents); |
| 2394 CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHel
per(); |
| 2395 |
| 2396 final int pageScale = 2; |
| 2397 final String page = "<html><head>" + |
| 2398 "<meta name='viewport' content='width=3000, initial-scale=" + pa
geScale + |
| 2399 "' /></head>" + |
| 2400 "<body></body></html>"; |
| 2401 |
| 2402 assertFalse(settings.getUseWideViewPort()); |
| 2403 assertFalse(settings.getLoadWithOverviewMode()); |
| 2404 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false)
; |
| 2405 assertEquals(1.0f, getScaleOnUiThread(awContents)); |
| 2406 |
| 2407 settings.setUseWideViewPort(true); |
| 2408 settings.setLoadWithOverviewMode(true); |
| 2409 awContents.resetScrollAndScaleState(); |
| 2410 int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().ge
tCallCount(); |
| 2411 loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false)
; |
| 2412 contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCa
llCount); |
| 2413 assertEquals((float)pageScale, getScaleOnUiThread(awContents)); |
| 2414 } |
| 2415 |
2294 static class ViewPair { | 2416 static class ViewPair { |
2295 private final AwContents contents0; | 2417 private final AwContents contents0; |
2296 private final TestAwContentsClient client0; | 2418 private final TestAwContentsClient client0; |
2297 private final AwContents contents1; | 2419 private final AwContents contents1; |
2298 private final TestAwContentsClient client1; | 2420 private final TestAwContentsClient client1; |
2299 | 2421 |
2300 ViewPair(AwContents contents0, TestAwContentsClient client0, | 2422 ViewPair(AwContents contents0, TestAwContentsClient client0, |
2301 AwContents contents1, TestAwContentsClient client1) { | 2423 AwContents contents1, TestAwContentsClient client1) { |
2302 this.contents0 = contents0; | 2424 this.contents0 = contents0; |
2303 this.client0 = client0; | 2425 this.client0 = client0; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 private void useTestResourceContext() { | 2530 private void useTestResourceContext() { |
2409 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); | 2531 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); |
2410 } | 2532 } |
2411 | 2533 |
2412 /** | 2534 /** |
2413 * Configure the browser to load resources from the browser application. | 2535 * Configure the browser to load resources from the browser application. |
2414 */ | 2536 */ |
2415 private void resetResourceContext() { | 2537 private void resetResourceContext() { |
2416 AndroidProtocolHandler.setResourceContextForTesting(null); | 2538 AndroidProtocolHandler.setResourceContextForTesting(null); |
2417 } | 2539 } |
| 2540 |
| 2541 private float getScaleOnUiThread(final AwContents awContents) throws Throwab
le { |
| 2542 return runTestOnUiThreadAndGetResult(new Callable<Float>() { |
| 2543 @Override |
| 2544 public Float call() throws Exception { |
| 2545 return awContents.getContentViewCore().getScale(); |
| 2546 } |
| 2547 }); |
| 2548 } |
2418 } | 2549 } |
OLD | NEW |