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