| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 import android.graphics.Color; | 8 import android.graphics.Color; |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| 11 import android.util.Pair; | 11 import android.util.Pair; |
| 12 import android.webkit.WebResourceResponse; |
| 12 | 13 |
| 13 import org.chromium.android_webview.AwContents; | 14 import org.chromium.android_webview.AwContents; |
| 14 import org.chromium.android_webview.AwWebResourceResponse; | |
| 15 import org.chromium.android_webview.test.util.AwTestTouchUtils; | 15 import org.chromium.android_webview.test.util.AwTestTouchUtils; |
| 16 import org.chromium.android_webview.test.util.CommonResources; | 16 import org.chromium.android_webview.test.util.CommonResources; |
| 17 import org.chromium.android_webview.test.util.GraphicsTestUtils; | 17 import org.chromium.android_webview.test.util.GraphicsTestUtils; |
| 18 import org.chromium.android_webview.test.util.JSUtils; | 18 import org.chromium.android_webview.test.util.JSUtils; |
| 19 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
| 20 import org.chromium.base.test.util.MinAndroidSdkLevel; | 20 import org.chromium.base.test.util.MinAndroidSdkLevel; |
| 21 import org.chromium.base.test.util.TestFileUtil; | 21 import org.chromium.base.test.util.TestFileUtil; |
| 22 import org.chromium.content.browser.test.util.CallbackHelper; | 22 import org.chromium.content.browser.test.util.CallbackHelper; |
| 23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; | 23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; |
| 24 import org.chromium.net.test.util.TestWebServer; | 24 import org.chromium.net.test.util.TestWebServer; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 * Tests for the WebViewClient.shouldInterceptRequest() method. | 38 * Tests for the WebViewClient.shouldInterceptRequest() method. |
| 39 */ | 39 */ |
| 40 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) | 40 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) |
| 41 public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { | 41 public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
| 42 | 42 |
| 43 private static class TestAwContentsClient | 43 private static class TestAwContentsClient |
| 44 extends org.chromium.android_webview.test.TestAwContentsClient { | 44 extends org.chromium.android_webview.test.TestAwContentsClient { |
| 45 | 45 |
| 46 public static class ShouldInterceptRequestHelper extends CallbackHelper
{ | 46 public static class ShouldInterceptRequestHelper extends CallbackHelper
{ |
| 47 private List<String> mShouldInterceptRequestUrls = new ArrayList<Str
ing>(); | 47 private List<String> mShouldInterceptRequestUrls = new ArrayList<Str
ing>(); |
| 48 private ConcurrentHashMap<String, AwWebResourceResponse> mReturnValu
esByUrls = | 48 private ConcurrentHashMap<String, WebResourceResponse> mReturnValues
ByUrls = |
| 49 new ConcurrentHashMap<String, AwWebResourceResponse>(); | 49 new ConcurrentHashMap<String, WebResourceResponse>(); |
| 50 private ConcurrentHashMap<String, AwWebResourceRequest> mRequestsByU
rls = | 50 private ConcurrentHashMap<String, WebResourceRequestImpl> mRequestsB
yUrls = |
| 51 new ConcurrentHashMap<String, AwWebResourceRequest>(); | 51 new ConcurrentHashMap<String, WebResourceRequestImpl>(); |
| 52 // This is read from the IO thread, so needs to be marked volatile. | 52 // This is read from the IO thread, so needs to be marked volatile. |
| 53 private volatile AwWebResourceResponse mShouldInterceptRequestReturn
Value = null; | 53 private volatile WebResourceResponse mShouldInterceptRequestReturnVa
lue = null; |
| 54 void setReturnValue(AwWebResourceResponse value) { | 54 void setReturnValue(WebResourceResponse value) { |
| 55 mShouldInterceptRequestReturnValue = value; | 55 mShouldInterceptRequestReturnValue = value; |
| 56 } | 56 } |
| 57 void setReturnValueForUrl(String url, AwWebResourceResponse value) { | 57 void setReturnValueForUrl(String url, WebResourceResponse value) { |
| 58 mReturnValuesByUrls.put(url, value); | 58 mReturnValuesByUrls.put(url, value); |
| 59 } | 59 } |
| 60 public List<String> getUrls() { | 60 public List<String> getUrls() { |
| 61 assert getCallCount() > 0; | 61 assert getCallCount() > 0; |
| 62 return mShouldInterceptRequestUrls; | 62 return mShouldInterceptRequestUrls; |
| 63 } | 63 } |
| 64 public AwWebResourceResponse getReturnValue(String url) { | 64 public WebResourceResponse getReturnValue(String url) { |
| 65 AwWebResourceResponse value = mReturnValuesByUrls.get(url); | 65 WebResourceResponse value = mReturnValuesByUrls.get(url); |
| 66 if (value != null) return value; | 66 if (value != null) return value; |
| 67 return mShouldInterceptRequestReturnValue; | 67 return mShouldInterceptRequestReturnValue; |
| 68 } | 68 } |
| 69 public AwWebResourceRequest getRequestsForUrl(String url) { | 69 public WebResourceRequestImpl getRequestsForUrl(String url) { |
| 70 assert getCallCount() > 0; | 70 assert getCallCount() > 0; |
| 71 assert mRequestsByUrls.containsKey(url); | 71 assert mRequestsByUrls.containsKey(url); |
| 72 return mRequestsByUrls.get(url); | 72 return mRequestsByUrls.get(url); |
| 73 } | 73 } |
| 74 public void notifyCalled(AwWebResourceRequest request) { | 74 public void notifyCalled(WebResourceRequestImpl request) { |
| 75 mShouldInterceptRequestUrls.add(request.url); | 75 mShouldInterceptRequestUrls.add(request.getUrlString()); |
| 76 mRequestsByUrls.put(request.url, request); | 76 mRequestsByUrls.put(request.getUrlString(), request); |
| 77 notifyCalled(); | 77 notifyCalled(); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 public static class OnLoadResourceHelper extends CallbackHelper { | 81 public static class OnLoadResourceHelper extends CallbackHelper { |
| 82 private String mUrl; | 82 private String mUrl; |
| 83 | 83 |
| 84 public String getUrl() { | 84 public String getUrl() { |
| 85 assert getCallCount() > 0; | 85 assert getCallCount() > 0; |
| 86 return mUrl; | 86 return mUrl; |
| 87 } | 87 } |
| 88 | 88 |
| 89 public void notifyCalled(String url) { | 89 public void notifyCalled(String url) { |
| 90 mUrl = url; | 90 mUrl = url; |
| 91 notifyCalled(); | 91 notifyCalled(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 @Override | 95 @Override |
| 96 public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest
request) { | 96 public WebResourceResponse shouldInterceptRequest(WebResourceRequestImpl
request) { |
| 97 AwWebResourceResponse returnValue = | 97 WebResourceResponse returnValue = |
| 98 mShouldInterceptRequestHelper.getReturnValue(request.url); | 98 mShouldInterceptRequestHelper.getReturnValue(request.getUrlS
tring()); |
| 99 mShouldInterceptRequestHelper.notifyCalled(request); | 99 mShouldInterceptRequestHelper.notifyCalled(request); |
| 100 return returnValue; | 100 return returnValue; |
| 101 } | 101 } |
| 102 | 102 |
| 103 @Override | 103 @Override |
| 104 public void onLoadResource(String url) { | 104 public void onLoadResource(String url) { |
| 105 super.onLoadResource(url); | 105 super.onLoadResource(url); |
| 106 mOnLoadResourceHelper.notifyCalled(url); | 106 mOnLoadResourceHelper.notifyCalled(url); |
| 107 } | 107 } |
| 108 | 108 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 131 headers.add(Pair.create("Content-Type", "text/html")); | 131 headers.add(Pair.create("Content-Type", "text/html")); |
| 132 headers.add(Pair.create("Cache-Control", "no-store")); | 132 headers.add(Pair.create("Cache-Control", "no-store")); |
| 133 return webServer.setResponse(httpPath, html, headers); | 133 return webServer.setResponse(httpPath, html, headers); |
| 134 } | 134 } |
| 135 | 135 |
| 136 private String addAboutPageToTestServer(TestWebServer webServer) { | 136 private String addAboutPageToTestServer(TestWebServer webServer) { |
| 137 return addPageToTestServer(webServer, "/" + CommonResources.ABOUT_FILENA
ME, | 137 return addPageToTestServer(webServer, "/" + CommonResources.ABOUT_FILENA
ME, |
| 138 CommonResources.ABOUT_HTML); | 138 CommonResources.ABOUT_HTML); |
| 139 } | 139 } |
| 140 | 140 |
| 141 private AwWebResourceResponse stringToAwWebResourceResponse(String input) th
rows Throwable { | 141 private WebResourceResponse stringToAwWebResourceResponse(String input) thro
ws Throwable { |
| 142 final String mimeType = "text/html"; | 142 final String mimeType = "text/html"; |
| 143 final String encoding = "UTF-8"; | 143 final String encoding = "UTF-8"; |
| 144 | 144 |
| 145 return new AwWebResourceResponse( | 145 return new WebResourceResponse( |
| 146 mimeType, encoding, new ByteArrayInputStream(input.getBytes(enco
ding))); | 146 mimeType, encoding, new ByteArrayInputStream(input.getBytes(enco
ding))); |
| 147 } | 147 } |
| 148 | 148 |
| 149 private TestWebServer mWebServer; | 149 private TestWebServer mWebServer; |
| 150 private TestAwContentsClient mContentsClient; | 150 private TestAwContentsClient mContentsClient; |
| 151 private AwTestContainerView mTestContainerView; | 151 private AwTestContainerView mTestContainerView; |
| 152 private AwContents mAwContents; | 152 private AwContents mAwContents; |
| 153 private TestAwContentsClient.ShouldInterceptRequestHelper mShouldInterceptRe
questHelper; | 153 private TestAwContentsClient.ShouldInterceptRequestHelper mShouldInterceptRe
questHelper; |
| 154 | 154 |
| 155 @Override | 155 @Override |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 final String subframeUrl = addAboutPageToTestServer(mWebServer); | 194 final String subframeUrl = addAboutPageToTestServer(mWebServer); |
| 195 final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/page_
with_iframe.html", | 195 final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/page_
with_iframe.html", |
| 196 CommonResources.makeHtmlPageFrom("", | 196 CommonResources.makeHtmlPageFrom("", |
| 197 "<iframe src=\"" + subframeUrl + "\"/>")); | 197 "<iframe src=\"" + subframeUrl + "\"/>")); |
| 198 | 198 |
| 199 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 199 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 200 loadUrlAsync(mAwContents, pageWithIframeUrl); | 200 loadUrlAsync(mAwContents, pageWithIframeUrl); |
| 201 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); | 201 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
| 202 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); | 202 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
| 203 assertEquals(false, | 203 assertEquals(false, |
| 204 mShouldInterceptRequestHelper.getRequestsForUrl(subframeUrl).isM
ainFrame); | 204 mShouldInterceptRequestHelper.getRequestsForUrl(subframeUrl).isF
orMainFrame()); |
| 205 assertEquals(true, | 205 assertEquals(true, mShouldInterceptRequestHelper.getRequestsForUrl(pageW
ithIframeUrl) |
| 206 mShouldInterceptRequestHelper.getRequestsForUrl(pageWithIframeUr
l).isMainFrame); | 206 .isForMainFrame()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 @SmallTest | 209 @SmallTest |
| 210 @Feature({"AndroidWebView"}) | 210 @Feature({"AndroidWebView"}) |
| 211 public void testCalledWithCorrectMethodParam() throws Throwable { | 211 public void testCalledWithCorrectMethodParam() throws Throwable { |
| 212 final String pageToPostToUrl = addAboutPageToTestServer(mWebServer); | 212 final String pageToPostToUrl = addAboutPageToTestServer(mWebServer); |
| 213 final String pageWithFormUrl = addPageToTestServer(mWebServer, "/page_wi
th_form.html", | 213 final String pageWithFormUrl = addPageToTestServer(mWebServer, "/page_wi
th_form.html", |
| 214 CommonResources.makeHtmlPageWithSimplePostFormTo(pageToPostToUrl
)); | 214 CommonResources.makeHtmlPageWithSimplePostFormTo(pageToPostToUrl
)); |
| 215 enableJavaScriptOnUiThread(mAwContents); | 215 enableJavaScriptOnUiThread(mAwContents); |
| 216 | 216 |
| 217 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 217 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 218 loadUrlAsync(mAwContents, pageWithFormUrl); | 218 loadUrlAsync(mAwContents, pageWithFormUrl); |
| 219 mShouldInterceptRequestHelper.waitForCallback(callCount); | 219 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 220 assertEquals("GET", | 220 assertEquals("GET", |
| 221 mShouldInterceptRequestHelper.getRequestsForUrl(pageWithFormUrl)
.method); | 221 mShouldInterceptRequestHelper.getRequestsForUrl(pageWithFormUrl)
.getMethod()); |
| 222 | 222 |
| 223 callCount = mShouldInterceptRequestHelper.getCallCount(); | 223 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 224 JSUtils.clickOnLinkUsingJs(this, mAwContents, | 224 JSUtils.clickOnLinkUsingJs(this, mAwContents, |
| 225 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); | 225 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); |
| 226 mShouldInterceptRequestHelper.waitForCallback(callCount); | 226 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 227 assertEquals("POST", | 227 assertEquals("POST", |
| 228 mShouldInterceptRequestHelper.getRequestsForUrl(pageToPostToUrl)
.method); | 228 mShouldInterceptRequestHelper.getRequestsForUrl(pageToPostToUrl)
.getMethod()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 @SmallTest | 231 @SmallTest |
| 232 @Feature({"AndroidWebView"}) | 232 @Feature({"AndroidWebView"}) |
| 233 public void testCalledWithCorrectHasUserGestureParam() throws Throwable { | 233 public void testCalledWithCorrectHasUserGestureParam() throws Throwable { |
| 234 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 234 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 235 final String pageWithLinkUrl = addPageToTestServer(mWebServer, "/page_wi
th_link.html", | 235 final String pageWithLinkUrl = addPageToTestServer(mWebServer, "/page_wi
th_link.html", |
| 236 CommonResources.makeHtmlPageWithSimpleLinkTo(aboutPageUrl)); | 236 CommonResources.makeHtmlPageWithSimpleLinkTo(aboutPageUrl)); |
| 237 enableJavaScriptOnUiThread(mAwContents); | 237 enableJavaScriptOnUiThread(mAwContents); |
| 238 | 238 |
| 239 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 239 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 240 loadUrlAsync(mAwContents, pageWithLinkUrl); | 240 loadUrlAsync(mAwContents, pageWithLinkUrl); |
| 241 mShouldInterceptRequestHelper.waitForCallback(callCount); | 241 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 242 assertEquals(false, | 242 assertEquals(false, |
| 243 mShouldInterceptRequestHelper.getRequestsForUrl(pageWithLinkUrl)
.hasUserGesture); | 243 mShouldInterceptRequestHelper.getRequestsForUrl(pageWithLinkUrl)
.hasGesture()); |
| 244 | 244 |
| 245 // TODO(mkosiba): Remove this once we have a real API to wait for the pa
ge to load and | 245 // TODO(mkosiba): Remove this once we have a real API to wait for the pa
ge to load and |
| 246 // display. | 246 // display. |
| 247 // http://crbug.com/364612 | 247 // http://crbug.com/364612 |
| 248 // | 248 // |
| 249 // The code here is waiting for the "link" (which is a full-screen blue
div) to appear on | 249 // The code here is waiting for the "link" (which is a full-screen blue
div) to appear on |
| 250 // screen. | 250 // screen. |
| 251 pollOnUiThread(new Callable<Boolean>() { | 251 pollOnUiThread(new Callable<Boolean>() { |
| 252 @Override | 252 @Override |
| 253 public Boolean call() throws Exception { | 253 public Boolean call() throws Exception { |
| 254 Bitmap bitmap = GraphicsTestUtils.drawAwContents(mAwContents, 2,
2, | 254 Bitmap bitmap = GraphicsTestUtils.drawAwContents(mAwContents, 2,
2, |
| 255 -(float) mTestContainerView.getWidth() / 2, | 255 -(float) mTestContainerView.getWidth() / 2, |
| 256 -(float) mTestContainerView.getHeight() / 2); | 256 -(float) mTestContainerView.getHeight() / 2); |
| 257 return bitmap.getPixel(0, 0) == Color.BLUE; | 257 return bitmap.getPixel(0, 0) == Color.BLUE; |
| 258 } | 258 } |
| 259 }); | 259 }); |
| 260 callCount = mShouldInterceptRequestHelper.getCallCount(); | 260 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 261 AwTestTouchUtils.simulateTouchCenterOfView(mTestContainerView); | 261 AwTestTouchUtils.simulateTouchCenterOfView(mTestContainerView); |
| 262 mShouldInterceptRequestHelper.waitForCallback(callCount); | 262 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 263 assertEquals(true, | 263 assertEquals( |
| 264 mShouldInterceptRequestHelper.getRequestsForUrl(aboutPageUrl).ha
sUserGesture); | 264 true, mShouldInterceptRequestHelper.getRequestsForUrl(aboutPageU
rl).hasGesture()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 @SmallTest | 267 @SmallTest |
| 268 @Feature({"AndroidWebView"}) | 268 @Feature({"AndroidWebView"}) |
| 269 public void testCalledWithCorrectHeadersParam() throws Throwable { | 269 public void testCalledWithCorrectHeadersParam() throws Throwable { |
| 270 final String headerName = "X-Test-Header-Name"; | 270 final String headerName = "X-Test-Header-Name"; |
| 271 final String headerValue = "TestHeaderValue"; | 271 final String headerValue = "TestHeaderValue"; |
| 272 final String syncGetUrl = addPageToTestServer(mWebServer, "/intercept_me
", | 272 final String syncGetUrl = addPageToTestServer(mWebServer, "/intercept_me
", |
| 273 CommonResources.ABOUT_HTML); | 273 CommonResources.ABOUT_HTML); |
| 274 final String mainPageUrl = addPageToTestServer(mWebServer, "/main", | 274 final String mainPageUrl = addPageToTestServer(mWebServer, "/main", |
| 275 CommonResources.makeHtmlPageFrom("", | 275 CommonResources.makeHtmlPageFrom("", |
| 276 "<script>" | 276 "<script>" |
| 277 + " var xhr = new XMLHttpRequest();" | 277 + " var xhr = new XMLHttpRequest();" |
| 278 + " xhr.open('GET', '" + syncGetUrl + "', false);" | 278 + " xhr.open('GET', '" + syncGetUrl + "', false);" |
| 279 + " xhr.setRequestHeader('" + headerName + "', '" + headerValue
+ "'); " | 279 + " xhr.setRequestHeader('" + headerName + "', '" + headerValue
+ "'); " |
| 280 + " xhr.send(null);" | 280 + " xhr.send(null);" |
| 281 + "</script>")); | 281 + "</script>")); |
| 282 enableJavaScriptOnUiThread(mAwContents); | 282 enableJavaScriptOnUiThread(mAwContents); |
| 283 | 283 |
| 284 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 284 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 285 loadUrlAsync(mAwContents, mainPageUrl); | 285 loadUrlAsync(mAwContents, mainPageUrl); |
| 286 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); | 286 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
| 287 | 287 |
| 288 Map<String, String> headers = | 288 Map<String, String> headers = |
| 289 mShouldInterceptRequestHelper.getRequestsForUrl(syncGetUrl).requ
estHeaders; | 289 mShouldInterceptRequestHelper.getRequestsForUrl(syncGetUrl).getR
equestHeaders(); |
| 290 assertTrue(headers.containsKey(headerName)); | 290 assertTrue(headers.containsKey(headerName)); |
| 291 assertEquals(headerValue, headers.get(headerName)); | 291 assertEquals(headerValue, headers.get(headerName)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 @SmallTest | 294 @SmallTest |
| 295 @Feature({"AndroidWebView"}) | 295 @Feature({"AndroidWebView"}) |
| 296 public void testOnLoadResourceCalledWithCorrectUrl() throws Throwable { | 296 public void testOnLoadResourceCalledWithCorrectUrl() throws Throwable { |
| 297 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 297 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 298 final TestAwContentsClient.OnLoadResourceHelper onLoadResourceHelper = | 298 final TestAwContentsClient.OnLoadResourceHelper onLoadResourceHelper = |
| 299 mContentsClient.getOnLoadResourceHelper(); | 299 mContentsClient.getOnLoadResourceHelper(); |
| 300 | 300 |
| 301 int callCount = onLoadResourceHelper.getCallCount(); | 301 int callCount = onLoadResourceHelper.getCallCount(); |
| 302 | 302 |
| 303 loadUrlAsync(mAwContents, aboutPageUrl); | 303 loadUrlAsync(mAwContents, aboutPageUrl); |
| 304 | 304 |
| 305 onLoadResourceHelper.waitForCallback(callCount); | 305 onLoadResourceHelper.waitForCallback(callCount); |
| 306 assertEquals(aboutPageUrl, onLoadResourceHelper.getUrl()); | 306 assertEquals(aboutPageUrl, onLoadResourceHelper.getUrl()); |
| 307 } | 307 } |
| 308 | 308 |
| 309 @SmallTest | 309 @SmallTest |
| 310 @Feature({"AndroidWebView"}) | 310 @Feature({"AndroidWebView"}) |
| 311 public void testDoesNotCrashOnInvalidData() throws Throwable { | 311 public void testDoesNotCrashOnInvalidData() throws Throwable { |
| 312 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 312 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 313 | 313 |
| 314 mShouldInterceptRequestHelper.setReturnValue( | 314 mShouldInterceptRequestHelper.setReturnValue( |
| 315 new AwWebResourceResponse("text/html", "UTF-8", null)); | 315 new WebResourceResponse("text/html", "UTF-8", null)); |
| 316 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 316 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 317 loadUrlAsync(mAwContents, aboutPageUrl); | 317 loadUrlAsync(mAwContents, aboutPageUrl); |
| 318 mShouldInterceptRequestHelper.waitForCallback(callCount); | 318 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 319 | 319 |
| 320 mShouldInterceptRequestHelper.setReturnValue( | 320 mShouldInterceptRequestHelper.setReturnValue( |
| 321 new AwWebResourceResponse(null, null, new ByteArrayInputStream(n
ew byte[0]))); | 321 new WebResourceResponse(null, null, new ByteArrayInputStream(new
byte[0]))); |
| 322 callCount = mShouldInterceptRequestHelper.getCallCount(); | 322 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 323 loadUrlAsync(mAwContents, aboutPageUrl); | 323 loadUrlAsync(mAwContents, aboutPageUrl); |
| 324 mShouldInterceptRequestHelper.waitForCallback(callCount); | 324 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 325 | 325 |
| 326 mShouldInterceptRequestHelper.setReturnValue( | 326 mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse(nul
l, null, null)); |
| 327 new AwWebResourceResponse(null, null, null)); | |
| 328 callCount = mShouldInterceptRequestHelper.getCallCount(); | 327 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 329 loadUrlAsync(mAwContents, aboutPageUrl); | 328 loadUrlAsync(mAwContents, aboutPageUrl); |
| 330 mShouldInterceptRequestHelper.waitForCallback(callCount); | 329 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 331 } | 330 } |
| 332 | 331 |
| 333 private static class EmptyInputStream extends InputStream { | 332 private static class EmptyInputStream extends InputStream { |
| 334 @Override | 333 @Override |
| 335 public int available() { | 334 public int available() { |
| 336 return 0; | 335 return 0; |
| 337 } | 336 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 358 return 0; | 357 return 0; |
| 359 } | 358 } |
| 360 } | 359 } |
| 361 | 360 |
| 362 @SmallTest | 361 @SmallTest |
| 363 @Feature({"AndroidWebView"}) | 362 @Feature({"AndroidWebView"}) |
| 364 public void testDoesNotCrashOnEmptyStream() throws Throwable { | 363 public void testDoesNotCrashOnEmptyStream() throws Throwable { |
| 365 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 364 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 366 | 365 |
| 367 mShouldInterceptRequestHelper.setReturnValue( | 366 mShouldInterceptRequestHelper.setReturnValue( |
| 368 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); | 367 new WebResourceResponse("text/html", "UTF-8", new EmptyInputStre
am())); |
| 369 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); | 368 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); |
| 370 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); | 369 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); |
| 371 | 370 |
| 372 loadUrlAsync(mAwContents, aboutPageUrl); | 371 loadUrlAsync(mAwContents, aboutPageUrl); |
| 373 | 372 |
| 374 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); | 373 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); |
| 375 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); | 374 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); |
| 376 } | 375 } |
| 377 | 376 |
| 378 private static class ThrowingInputStream extends EmptyInputStream { | 377 private static class ThrowingInputStream extends EmptyInputStream { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 401 return n; | 400 return n; |
| 402 } | 401 } |
| 403 } | 402 } |
| 404 | 403 |
| 405 @SmallTest | 404 @SmallTest |
| 406 @Feature({"AndroidWebView"}) | 405 @Feature({"AndroidWebView"}) |
| 407 public void testDoesNotCrashOnThrowingStream() throws Throwable { | 406 public void testDoesNotCrashOnThrowingStream() throws Throwable { |
| 408 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 407 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 409 | 408 |
| 410 mShouldInterceptRequestHelper.setReturnValue( | 409 mShouldInterceptRequestHelper.setReturnValue( |
| 411 new AwWebResourceResponse("text/html", "UTF-8", new ThrowingInpu
tStream())); | 410 new WebResourceResponse("text/html", "UTF-8", new ThrowingInputS
tream())); |
| 412 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); | 411 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); |
| 413 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); | 412 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); |
| 414 | 413 |
| 415 loadUrlAsync(mAwContents, aboutPageUrl); | 414 loadUrlAsync(mAwContents, aboutPageUrl); |
| 416 | 415 |
| 417 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); | 416 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); |
| 418 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); | 417 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); |
| 419 } | 418 } |
| 420 | 419 |
| 421 private static class SlowAwWebResourceResponse extends AwWebResourceResponse
{ | 420 private static class SlowAwWebResourceResponse extends WebResourceResponse { |
| 422 private CallbackHelper mReadStartedCallbackHelper = new CallbackHelper()
; | 421 private CallbackHelper mReadStartedCallbackHelper = new CallbackHelper()
; |
| 423 private CountDownLatch mLatch = new CountDownLatch(1); | 422 private CountDownLatch mLatch = new CountDownLatch(1); |
| 424 | 423 |
| 425 public SlowAwWebResourceResponse(String mimeType, String encoding, Input
Stream data) { | 424 public SlowAwWebResourceResponse(String mimeType, String encoding, Input
Stream data) { |
| 426 super(mimeType, encoding, data); | 425 super(mimeType, encoding, data); |
| 427 } | 426 } |
| 428 | 427 |
| 429 @Override | 428 @Override |
| 430 public InputStream getData() { | 429 public InputStream getData() { |
| 431 mReadStartedCallbackHelper.notifyCalled(); | 430 mReadStartedCallbackHelper.notifyCalled(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 + " console.info('xhr.status = ' + xhr.status);" | 493 + " console.info('xhr.status = ' + xhr.status);" |
| 495 + " console.info('xhr.statusText = ' + xhr.statusText);" | 494 + " console.info('xhr.statusText = ' + xhr.statusText);" |
| 496 + " return '[' + xhr.status + '][' + xhr.statusText + ']';" | 495 + " return '[' + xhr.status + '][' + xhr.statusText + ']';" |
| 497 + "})();"; | 496 + "})();"; |
| 498 enableJavaScriptOnUiThread(mAwContents); | 497 enableJavaScriptOnUiThread(mAwContents); |
| 499 | 498 |
| 500 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 499 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 501 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 500 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
| 502 | 501 |
| 503 mShouldInterceptRequestHelper.setReturnValue( | 502 mShouldInterceptRequestHelper.setReturnValue( |
| 504 new AwWebResourceResponse("text/html", "UTF-8", null)); | 503 new WebResourceResponse("text/html", "UTF-8", null)); |
| 505 assertEquals("\"[404][Not Found]\"", | 504 assertEquals("\"[404][Not Found]\"", |
| 506 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 505 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
| 507 | 506 |
| 508 mShouldInterceptRequestHelper.setReturnValue( | 507 mShouldInterceptRequestHelper.setReturnValue( |
| 509 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); | 508 new WebResourceResponse("text/html", "UTF-8", new EmptyInputStre
am())); |
| 510 assertEquals("\"[200][OK]\"", | 509 assertEquals("\"[200][OK]\"", |
| 511 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 510 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
| 512 | 511 |
| 513 mShouldInterceptRequestHelper.setReturnValue( | 512 mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse("te
xt/html", "UTF-8", |
| 514 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream(), | 513 TEAPOT_STATUS_CODE, TEAPOT_RESPONSE_PHRASE, new HashMap<String,
String>(), |
| 515 TEAPOT_STATUS_CODE, TEAPOT_RESPONSE_PHRASE, new HashMap<
String, String>())); | 514 new EmptyInputStream())); |
| 516 assertEquals("\"[" + TEAPOT_STATUS_CODE + "][" + TEAPOT_RESPONSE_PHRASE
+ "]\"", | 515 assertEquals("\"[" + TEAPOT_STATUS_CODE + "][" + TEAPOT_RESPONSE_PHRASE
+ "]\"", |
| 517 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 516 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
| 518 } | 517 } |
| 519 | 518 |
| 520 private String getHeaderValue(AwContents awContents, TestAwContentsClient co
ntentsClient, | 519 private String getHeaderValue(AwContents awContents, TestAwContentsClient co
ntentsClient, |
| 521 String url, String headerName) throws Exception { | 520 String url, String headerName) throws Exception { |
| 522 final String syncGetJs = | 521 final String syncGetJs = |
| 523 "(function() {" | 522 "(function() {" |
| 524 + " var xhr = new XMLHttpRequest();" | 523 + " var xhr = new XMLHttpRequest();" |
| 525 + " xhr.open('GET', '" + url + "', false);" | 524 + " xhr.open('GET', '" + url + "', false);" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 546 final String clientResponseHeaderValue = "shouldInterceptRequest"; | 545 final String clientResponseHeaderValue = "shouldInterceptRequest"; |
| 547 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); | 546 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
| 548 enableJavaScriptOnUiThread(mAwContents); | 547 enableJavaScriptOnUiThread(mAwContents); |
| 549 | 548 |
| 550 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 549 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 551 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 550 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
| 552 | 551 |
| 553 // The response header is set regardless of whether the embedder has pro
vided a | 552 // The response header is set regardless of whether the embedder has pro
vided a |
| 554 // valid resource stream. | 553 // valid resource stream. |
| 555 mShouldInterceptRequestHelper.setReturnValue( | 554 mShouldInterceptRequestHelper.setReturnValue( |
| 556 new AwWebResourceResponse("text/html", "UTF-8", null)); | 555 new WebResourceResponse("text/html", "UTF-8", null)); |
| 557 assertEquals(clientResponseHeaderValue, | 556 assertEquals(clientResponseHeaderValue, |
| 558 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); | 557 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
| 559 mShouldInterceptRequestHelper.setReturnValue( | 558 mShouldInterceptRequestHelper.setReturnValue( |
| 560 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); | 559 new WebResourceResponse("text/html", "UTF-8", new EmptyInputStre
am())); |
| 561 assertEquals(clientResponseHeaderValue, | 560 assertEquals(clientResponseHeaderValue, |
| 562 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); | 561 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
| 563 | 562 |
| 564 } | 563 } |
| 565 | 564 |
| 566 @SmallTest | 565 @SmallTest |
| 567 @Feature({"AndroidWebView"}) | 566 @Feature({"AndroidWebView"}) |
| 568 public void testHttpResponseHeader() throws Throwable { | 567 public void testHttpResponseHeader() throws Throwable { |
| 569 final String clientResponseHeaderName = "X-Test-Header-Name"; | 568 final String clientResponseHeaderName = "X-Test-Header-Name"; |
| 570 final String clientResponseHeaderValue = "TestHeaderValue"; | 569 final String clientResponseHeaderValue = "TestHeaderValue"; |
| 571 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); | 570 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
| 572 final Map<String, String> headers = new HashMap<String, String>(); | 571 final Map<String, String> headers = new HashMap<String, String>(); |
| 573 headers.put(clientResponseHeaderName, clientResponseHeaderValue); | 572 headers.put(clientResponseHeaderName, clientResponseHeaderValue); |
| 574 enableJavaScriptOnUiThread(mAwContents); | 573 enableJavaScriptOnUiThread(mAwContents); |
| 575 | 574 |
| 576 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 575 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 577 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 576 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
| 578 | 577 |
| 579 mShouldInterceptRequestHelper.setReturnValue( | 578 mShouldInterceptRequestHelper.setReturnValue( |
| 580 new AwWebResourceResponse("text/html", "UTF-8", null, 0, null, h
eaders)); | 579 new WebResourceResponse("text/html", "UTF-8", 0, null, headers,
null)); |
| 581 assertEquals(clientResponseHeaderValue, | 580 assertEquals(clientResponseHeaderValue, |
| 582 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); | 581 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
| 583 } | 582 } |
| 584 | 583 |
| 585 @SmallTest | 584 @SmallTest |
| 586 @Feature({"AndroidWebView"}) | 585 @Feature({"AndroidWebView"}) |
| 587 public void testNullHttpResponseHeaders() throws Throwable { | 586 public void testNullHttpResponseHeaders() throws Throwable { |
| 588 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); | 587 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
| 589 enableJavaScriptOnUiThread(mAwContents); | 588 enableJavaScriptOnUiThread(mAwContents); |
| 590 | 589 |
| 591 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 590 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 592 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 591 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
| 593 | 592 |
| 594 mShouldInterceptRequestHelper.setReturnValue( | 593 mShouldInterceptRequestHelper.setReturnValue( |
| 595 new AwWebResourceResponse("text/html", "UTF-8", null, 0, null, n
ull)); | 594 new WebResourceResponse("text/html", "UTF-8", 0, null, null, nul
l)); |
| 596 assertEquals(null, getHeaderValue(mAwContents, mContentsClient, syncGetU
rl, "Some-Header")); | 595 assertEquals(null, getHeaderValue(mAwContents, mContentsClient, syncGetU
rl, "Some-Header")); |
| 597 } | 596 } |
| 598 | 597 |
| 599 private String makePageWithTitle(String title) { | 598 private String makePageWithTitle(String title) { |
| 600 return CommonResources.makeHtmlPageFrom("<title>" + title + "</title>", | 599 return CommonResources.makeHtmlPageFrom("<title>" + title + "</title>", |
| 601 "<div> The title is: " + title + " </div>"); | 600 "<div> The title is: " + title + " </div>"); |
| 602 } | 601 } |
| 603 | 602 |
| 604 @SmallTest | 603 @SmallTest |
| 605 @Feature({"AndroidWebView"}) | 604 @Feature({"AndroidWebView"}) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 632 assertEquals(aboutPageUrl, mContentsClient.getOnPageStartedHelper().getU
rl()); | 631 assertEquals(aboutPageUrl, mContentsClient.getOnPageStartedHelper().getU
rl()); |
| 633 } | 632 } |
| 634 | 633 |
| 635 @SmallTest | 634 @SmallTest |
| 636 @Feature({"AndroidWebView"}) | 635 @Feature({"AndroidWebView"}) |
| 637 public void testNullInputStreamCausesErrorForMainFrame() throws Throwable { | 636 public void testNullInputStreamCausesErrorForMainFrame() throws Throwable { |
| 638 final OnReceivedErrorHelper onReceivedErrorHelper = | 637 final OnReceivedErrorHelper onReceivedErrorHelper = |
| 639 mContentsClient.getOnReceivedErrorHelper(); | 638 mContentsClient.getOnReceivedErrorHelper(); |
| 640 | 639 |
| 641 mShouldInterceptRequestHelper.setReturnValue( | 640 mShouldInterceptRequestHelper.setReturnValue( |
| 642 new AwWebResourceResponse("text/html", "UTF-8", null)); | 641 new WebResourceResponse("text/html", "UTF-8", null)); |
| 643 | 642 |
| 644 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 643 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 645 final int callCount = onReceivedErrorHelper.getCallCount(); | 644 final int callCount = onReceivedErrorHelper.getCallCount(); |
| 646 loadUrlAsync(mAwContents, aboutPageUrl); | 645 loadUrlAsync(mAwContents, aboutPageUrl); |
| 647 onReceivedErrorHelper.waitForCallback(callCount); | 646 onReceivedErrorHelper.waitForCallback(callCount); |
| 648 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); | 647 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); |
| 649 } | 648 } |
| 650 | 649 |
| 651 @SmallTest | 650 @SmallTest |
| 652 @Feature({"AndroidWebView"}) | 651 @Feature({"AndroidWebView"}) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 663 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); | 662 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
| 664 | 663 |
| 665 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); | 664 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
| 666 assertTrue(mShouldInterceptRequestHelper.getUrls().get(1).endsWith( | 665 assertTrue(mShouldInterceptRequestHelper.getUrls().get(1).endsWith( |
| 667 CommonResources.FAVICON_FILENAME)); | 666 CommonResources.FAVICON_FILENAME)); |
| 668 } | 667 } |
| 669 | 668 |
| 670 @SmallTest | 669 @SmallTest |
| 671 @Feature({"AndroidWebView"}) | 670 @Feature({"AndroidWebView"}) |
| 672 public void testOnReceivedErrorCallback() throws Throwable { | 671 public void testOnReceivedErrorCallback() throws Throwable { |
| 673 mShouldInterceptRequestHelper.setReturnValue(new AwWebResourceResponse(n
ull, null, null)); | 672 mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse(nul
l, null, null)); |
| 674 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 673 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
| 675 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); | 674 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); |
| 676 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo
://bar"); | 675 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo
://bar"); |
| 677 onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1)
; | 676 onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1)
; |
| 678 } | 677 } |
| 679 | 678 |
| 680 @SmallTest | 679 @SmallTest |
| 681 @Feature({"AndroidWebView"}) | 680 @Feature({"AndroidWebView"}) |
| 682 public void testNoOnReceivedErrorCallback() throws Throwable { | 681 public void testNoOnReceivedErrorCallback() throws Throwable { |
| 683 final String imagePath = "/" + CommonResources.FAVICON_FILENAME; | 682 final String imagePath = "/" + CommonResources.FAVICON_FILENAME; |
| 684 final String imageUrl = mWebServer.setResponseBase64(imagePath, | 683 final String imageUrl = mWebServer.setResponseBase64(imagePath, |
| 685 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePng
Headers(true)); | 684 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePng
Headers(true)); |
| 686 final String pageWithImage = | 685 final String pageWithImage = |
| 687 addPageToTestServer(mWebServer, "/page_with_image.html", | 686 addPageToTestServer(mWebServer, "/page_with_image.html", |
| 688 CommonResources.getOnImageLoadedHtml(CommonResources.FAV
ICON_FILENAME)); | 687 CommonResources.getOnImageLoadedHtml(CommonResources.FAV
ICON_FILENAME)); |
| 689 mShouldInterceptRequestHelper.setReturnValueForUrl( | 688 mShouldInterceptRequestHelper.setReturnValueForUrl( |
| 690 imageUrl, new AwWebResourceResponse(null, null, null)); | 689 imageUrl, new WebResourceResponse(null, null, null)); |
| 691 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 690 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
| 692 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); | 691 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); |
| 693 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithImage); | 692 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithImage); |
| 694 assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCa
llCount()); | 693 assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCa
llCount()); |
| 695 } | 694 } |
| 696 | 695 |
| 697 @SmallTest | 696 @SmallTest |
| 698 @Feature({"AndroidWebView"}) | 697 @Feature({"AndroidWebView"}) |
| 699 public void testCalledForIframe() throws Throwable { | 698 public void testCalledForIframe() throws Throwable { |
| 700 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 699 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 getInstrumentation().getTargetContext(), contentResourceName); | 799 getInstrumentation().getTargetContext(), contentResourceName); |
| 801 assertEquals(1, contentRequestCount); | 800 assertEquals(1, contentRequestCount); |
| 802 } | 801 } |
| 803 | 802 |
| 804 @SmallTest | 803 @SmallTest |
| 805 @Feature({"AndroidWebView"}) | 804 @Feature({"AndroidWebView"}) |
| 806 public void testCalledForNonexistentContentUrl() throws Throwable { | 805 public void testCalledForNonexistentContentUrl() throws Throwable { |
| 807 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo"
); | 806 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo"
); |
| 808 } | 807 } |
| 809 } | 808 } |
| OLD | NEW |