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; |
11 | 11 |
12 import org.apache.http.Header; | 12 import org.apache.http.Header; |
13 import org.apache.http.HttpRequest; | 13 import org.apache.http.HttpRequest; |
14 import org.chromium.android_webview.AndroidProtocolHandler; | 14 import org.chromium.android_webview.AndroidProtocolHandler; |
15 import org.chromium.android_webview.AwContents; | 15 import org.chromium.android_webview.AwContents; |
16 import org.chromium.android_webview.AwSettings; | 16 import org.chromium.android_webview.AwSettings; |
17 import org.chromium.android_webview.test.util.CommonResources; | 17 import org.chromium.android_webview.test.util.CommonResources; |
18 import org.chromium.android_webview.test.util.ImagePageGenerator; | 18 import org.chromium.android_webview.test.util.ImagePageGenerator; |
19 import org.chromium.base.test.util.DisabledTest; | |
20 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
21 import org.chromium.base.test.util.TestFileUtil; | 20 import org.chromium.base.test.util.TestFileUtil; |
22 import org.chromium.base.test.util.UrlUtils; | 21 import org.chromium.base.test.util.UrlUtils; |
23 import org.chromium.content.browser.ContentSettings; | 22 import org.chromium.content.browser.ContentSettings; |
24 import org.chromium.content.browser.ContentViewCore; | 23 import org.chromium.content.browser.ContentViewCore; |
25 import org.chromium.content.browser.test.util.CallbackHelper; | 24 import org.chromium.content.browser.test.util.CallbackHelper; |
26 import org.chromium.content.browser.test.util.Criteria; | 25 import org.chromium.content.browser.test.util.Criteria; |
27 import org.chromium.content.browser.test.util.CriteriaHelper; | 26 import org.chromium.content.browser.test.util.CriteriaHelper; |
28 import org.chromium.content.browser.test.util.HistoryUtils; | 27 import org.chromium.content.browser.test.util.HistoryUtils; |
29 import org.chromium.net.test.util.TestWebServer; | 28 import org.chromium.net.test.util.TestWebServer; |
(...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 } | 2213 } |
2215 | 2214 |
2216 @SmallTest | 2215 @SmallTest |
2217 @Feature({"AndroidWebView", "Preferences", "AppCache"}) | 2216 @Feature({"AndroidWebView", "Preferences", "AppCache"}) |
2218 public void testAppCache() throws Throwable { | 2217 public void testAppCache() throws Throwable { |
2219 final TestAwContentsClient contentClient = new TestAwContentsClient(); | 2218 final TestAwContentsClient contentClient = new TestAwContentsClient(); |
2220 final AwTestContainerView testContainer = | 2219 final AwTestContainerView testContainer = |
2221 createAwTestContainerViewOnMainSync(false, contentClient); | 2220 createAwTestContainerViewOnMainSync(false, contentClient); |
2222 final AwContents awContents = testContainer.getAwContents(); | 2221 final AwContents awContents = testContainer.getAwContents(); |
2223 final ContentSettings settings = getContentSettingsOnUiThread(awContents
); | 2222 final ContentSettings settings = getContentSettingsOnUiThread(awContents
); |
2224 // Not sure why, but I'm experiencing DCHECK failures at net/disk_cache/
in_flight_io.cc:98 | |
2225 // w/o this line. crbug.com/163383 | |
2226 clearCacheOnUiThread(awContents, true); | |
2227 settings.setJavaScriptEnabled(true); | 2223 settings.setJavaScriptEnabled(true); |
2228 // Note that the cache isn't actually enabled until the call to setAppCa
chePath. | 2224 // Note that the cache isn't actually enabled until the call to setAppCa
chePath. |
2229 settings.setAppCacheEnabled(true); | 2225 settings.setAppCacheEnabled(true); |
2230 | 2226 |
2231 TestWebServer webServer = null; | 2227 TestWebServer webServer = null; |
2232 try { | 2228 try { |
2233 webServer = new TestWebServer(false); | 2229 webServer = new TestWebServer(false); |
2234 ManifestTestHelper helper = new ManifestTestHelper( | 2230 ManifestTestHelper helper = new ManifestTestHelper( |
2235 webServer, "testAppCache.html", "appcache.manifest"); | 2231 webServer, "testAppCache.html", "appcache.manifest"); |
2236 loadUrlSync( | 2232 loadUrlSync( |
2237 awContents, | 2233 awContents, |
2238 contentClient.getOnPageFinishedHelper(), | 2234 contentClient.getOnPageFinishedHelper(), |
2239 helper.getHtmlUrl()); | 2235 helper.getHtmlUrl()); |
2240 helper.waitUntilHtmlIsRequested(0); | 2236 helper.waitUntilHtmlIsRequested(0); |
2241 // Unfortunately, there is no other good way of verifying that AppCa
che is | 2237 // Unfortunately, there is no other good way of verifying that AppCa
che is |
2242 // disabled, other than checking that it didn't try to fetch the man
ifest. | 2238 // disabled, other than checking that it didn't try to fetch the man
ifest. |
2243 Thread.sleep(1000); | 2239 Thread.sleep(1000); |
2244 assertEquals(0, webServer.getRequestCount(helper.getManifestPath()))
; | 2240 assertEquals(0, webServer.getRequestCount(helper.getManifestPath()))
; |
2245 settings.setAppCachePath("whatever"); // Enables AppCache. | 2241 settings.setAppCachePath("whatever"); // Enables AppCache. |
2246 loadUrlSync( | 2242 loadUrlSync( |
2247 awContents, | 2243 awContents, |
2248 contentClient.getOnPageFinishedHelper(), | 2244 contentClient.getOnPageFinishedHelper(), |
2249 helper.getHtmlUrl()); | 2245 helper.getHtmlUrl()); |
2250 helper.waitUntilManifestIsRequested(0); | 2246 helper.waitUntilManifestIsRequested(0); |
2251 } finally { | 2247 } finally { |
2252 if (webServer != null) webServer.shutdown(); | 2248 if (webServer != null) webServer.shutdown(); |
2253 } | 2249 } |
2254 } | 2250 } |
2255 | 2251 |
2256 /* | 2252 @SmallTest |
2257 * @SmallTest | 2253 @Feature({"AndroidWebView", "Preferences", "AppCache"}) |
2258 * @Feature({"AndroidWebView", "Preferences", "AppCache"}) | |
2259 * BUG=crbug.com/163383 | |
2260 * If you run this test with a non-empty profile, it will crash, | |
2261 * unless you delete the test's data directory. | |
2262 */ | |
2263 @DisabledTest | |
2264 public void testAppCacheNormal() throws Throwable { | 2254 public void testAppCacheNormal() throws Throwable { |
2265 // We don't use the test helper here, because making sure that AppCache | 2255 // We don't use the test helper here, because making sure that AppCache |
2266 // is disabled takes a lot of time, so running through the usual drill | 2256 // is disabled takes a lot of time, so running through the usual drill |
2267 // will take about 20 seconds. | 2257 // will take about 20 seconds. |
2268 ViewPair views = createViews(NORMAL_VIEW, NORMAL_VIEW); | 2258 ViewPair views = createViews(NORMAL_VIEW, NORMAL_VIEW); |
2269 ContentSettings settings0 = getContentSettingsOnUiThread(views.getConten
ts0()); | 2259 ContentSettings settings0 = getContentSettingsOnUiThread(views.getConten
ts0()); |
2270 settings0.setJavaScriptEnabled(true); | 2260 settings0.setJavaScriptEnabled(true); |
2271 settings0.setAppCachePath("whatever"); | 2261 settings0.setAppCachePath("whatever"); |
2272 settings0.setAppCacheEnabled(true); | 2262 settings0.setAppCacheEnabled(true); |
2273 ContentSettings settings1 = getContentSettingsOnUiThread(views.getConten
ts1()); | 2263 ContentSettings settings1 = getContentSettingsOnUiThread(views.getConten
ts1()); |
2274 settings1.setJavaScriptEnabled(true); | 2264 settings1.setJavaScriptEnabled(true); |
2275 // AppCachePath setting is global, no need to set it for the second view
. | 2265 // AppCachePath setting is global, no need to set it for the second view
. |
2276 settings1.setAppCacheEnabled(true); | 2266 settings1.setAppCacheEnabled(true); |
2277 | 2267 |
2278 clearCacheOnUiThread(views.getContents0(), true); | |
2279 | |
2280 TestWebServer webServer = null; | 2268 TestWebServer webServer = null; |
2281 try { | 2269 try { |
2282 webServer = new TestWebServer(false); | 2270 webServer = new TestWebServer(false); |
2283 ManifestTestHelper helper0 = new ManifestTestHelper( | 2271 ManifestTestHelper helper0 = new ManifestTestHelper( |
2284 webServer, "testAppCache_0.html", "appcache.manifest_0"); | 2272 webServer, "testAppCache_0.html", "appcache.manifest_0"); |
2285 loadUrlSync( | 2273 loadUrlSync( |
2286 views.getContents0(), | 2274 views.getContents0(), |
2287 views.getClient0().getOnPageFinishedHelper(), | 2275 views.getClient0().getOnPageFinishedHelper(), |
2288 helper0.getHtmlUrl()); | 2276 helper0.getHtmlUrl()); |
2289 int manifestRequests0 = helper0.waitUntilManifestIsRequested(0); | 2277 int manifestRequests0 = helper0.waitUntilManifestIsRequested(0); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); | 2428 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation()
.getContext()); |
2441 } | 2429 } |
2442 | 2430 |
2443 /** | 2431 /** |
2444 * Configure the browser to load resources from the browser application. | 2432 * Configure the browser to load resources from the browser application. |
2445 */ | 2433 */ |
2446 private void resetResourceContext() { | 2434 private void resetResourceContext() { |
2447 AndroidProtocolHandler.setResourceContextForTesting(null); | 2435 AndroidProtocolHandler.setResourceContextForTesting(null); |
2448 } | 2436 } |
2449 } | 2437 } |
OLD | NEW |