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.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 import android.util.Pair; | 8 import android.util.Pair; |
9 | 9 |
10 import org.chromium.android_webview.AwContents; | 10 import org.chromium.android_webview.AwContents; |
11 import org.chromium.android_webview.InterceptedRequestData; | 11 import org.chromium.android_webview.AwContentsClient.ShouldInterceptRequestParam
s; |
| 12 import org.chromium.android_webview.AwWebResourceResponse; |
12 import org.chromium.android_webview.test.util.CommonResources; | 13 import org.chromium.android_webview.test.util.CommonResources; |
| 14 import org.chromium.android_webview.test.util.JSUtils; |
13 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
14 import org.chromium.base.test.util.TestFileUtil; | 16 import org.chromium.base.test.util.TestFileUtil; |
15 import org.chromium.content.browser.test.util.CallbackHelper; | 17 import org.chromium.content.browser.test.util.CallbackHelper; |
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; | 18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; |
17 import org.chromium.net.test.util.TestWebServer; | 19 import org.chromium.net.test.util.TestWebServer; |
18 | 20 |
19 import java.io.ByteArrayInputStream; | 21 import java.io.ByteArrayInputStream; |
20 import java.io.IOException; | 22 import java.io.IOException; |
21 import java.io.InputStream; | 23 import java.io.InputStream; |
22 import java.util.ArrayList; | 24 import java.util.ArrayList; |
| 25 import java.util.HashMap; |
23 import java.util.List; | 26 import java.util.List; |
| 27 import java.util.Map; |
24 import java.util.concurrent.Callable; | 28 import java.util.concurrent.Callable; |
25 import java.util.concurrent.ConcurrentHashMap; | 29 import java.util.concurrent.ConcurrentHashMap; |
26 import java.util.concurrent.CountDownLatch; | 30 import java.util.concurrent.CountDownLatch; |
27 | 31 |
28 /** | 32 /** |
29 * Tests for the WebViewClient.shouldInterceptRequest() method. | 33 * Tests for the WebViewClient.shouldInterceptRequest() method. |
30 */ | 34 */ |
31 public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { | 35 public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
32 | 36 |
33 private static class TestAwContentsClient | 37 private static class TestAwContentsClient |
34 extends org.chromium.android_webview.test.TestAwContentsClient { | 38 extends org.chromium.android_webview.test.TestAwContentsClient { |
35 | 39 |
36 public static class ShouldInterceptRequestHelper extends CallbackHelper
{ | 40 public static class ShouldInterceptRequestHelper extends CallbackHelper
{ |
37 private List<String> mShouldInterceptRequestUrls = new ArrayList<Str
ing>(); | 41 private List<String> mShouldInterceptRequestUrls = new ArrayList<Str
ing>(); |
38 private ConcurrentHashMap<String, InterceptedRequestData> mReturnVal
uesByUrls | 42 private ConcurrentHashMap<String, AwWebResourceResponse> mReturnValu
esByUrls |
39 = new ConcurrentHashMap<String, InterceptedRequestData>(); | 43 = new ConcurrentHashMap<String, AwWebResourceResponse>(); |
| 44 private ConcurrentHashMap<String, ShouldInterceptRequestParams> mPar
amsByUrls |
| 45 = new ConcurrentHashMap<String, ShouldInterceptRequestParams>(); |
40 // This is read from the IO thread, so needs to be marked volatile. | 46 // This is read from the IO thread, so needs to be marked volatile. |
41 private volatile InterceptedRequestData mShouldInterceptRequestRetur
nValue = null; | 47 private volatile AwWebResourceResponse mShouldInterceptRequestReturn
Value = null; |
42 void setReturnValue(InterceptedRequestData value) { | 48 void setReturnValue(AwWebResourceResponse value) { |
43 mShouldInterceptRequestReturnValue = value; | 49 mShouldInterceptRequestReturnValue = value; |
44 } | 50 } |
45 void setReturnValueForUrl(String url, InterceptedRequestData value)
{ | 51 void setReturnValueForUrl(String url, AwWebResourceResponse value) { |
46 mReturnValuesByUrls.put(url, value); | 52 mReturnValuesByUrls.put(url, value); |
47 } | 53 } |
48 public List<String> getUrls() { | 54 public List<String> getUrls() { |
49 assert getCallCount() > 0; | 55 assert getCallCount() > 0; |
50 return mShouldInterceptRequestUrls; | 56 return mShouldInterceptRequestUrls; |
51 } | 57 } |
52 public InterceptedRequestData getReturnValue(String url) { | 58 public AwWebResourceResponse getReturnValue(String url) { |
53 InterceptedRequestData value = mReturnValuesByUrls.get(url); | 59 AwWebResourceResponse value = mReturnValuesByUrls.get(url); |
54 if (value != null) return value; | 60 if (value != null) return value; |
55 return mShouldInterceptRequestReturnValue; | 61 return mShouldInterceptRequestReturnValue; |
56 } | 62 } |
57 public void notifyCalled(String url) { | 63 public ShouldInterceptRequestParams getParamsForUrl(String url) { |
58 mShouldInterceptRequestUrls.add(url); | 64 assert getCallCount() > 0; |
| 65 assert mParamsByUrls.containsKey(url); |
| 66 return mParamsByUrls.get(url); |
| 67 } |
| 68 public void notifyCalled(ShouldInterceptRequestParams params) { |
| 69 mShouldInterceptRequestUrls.add(params.url); |
| 70 mParamsByUrls.put(params.url, params); |
59 notifyCalled(); | 71 notifyCalled(); |
60 } | 72 } |
61 } | 73 } |
62 | 74 |
63 public static class OnLoadResourceHelper extends CallbackHelper { | 75 public static class OnLoadResourceHelper extends CallbackHelper { |
64 private String mUrl; | 76 private String mUrl; |
65 | 77 |
66 public String getUrl() { | 78 public String getUrl() { |
67 assert getCallCount() > 0; | 79 assert getCallCount() > 0; |
68 return mUrl; | 80 return mUrl; |
69 } | 81 } |
70 | 82 |
71 public void notifyCalled(String url) { | 83 public void notifyCalled(String url) { |
72 mUrl = url; | 84 mUrl = url; |
73 notifyCalled(); | 85 notifyCalled(); |
74 } | 86 } |
75 } | 87 } |
76 | 88 |
77 @Override | 89 @Override |
78 public InterceptedRequestData shouldInterceptRequest(String url) { | 90 public AwWebResourceResponse shouldInterceptRequest(ShouldInterceptReque
stParams params) { |
79 InterceptedRequestData returnValue = mShouldInterceptRequestHelper.g
etReturnValue(url); | 91 AwWebResourceResponse returnValue = |
80 mShouldInterceptRequestHelper.notifyCalled(url); | 92 mShouldInterceptRequestHelper.getReturnValue(params.url); |
| 93 mShouldInterceptRequestHelper.notifyCalled(params); |
81 return returnValue; | 94 return returnValue; |
82 } | 95 } |
83 | 96 |
84 @Override | 97 @Override |
85 public void onLoadResource(String url) { | 98 public void onLoadResource(String url) { |
86 super.onLoadResource(url); | 99 super.onLoadResource(url); |
87 mOnLoadResourceHelper.notifyCalled(url); | 100 mOnLoadResourceHelper.notifyCalled(url); |
88 } | 101 } |
89 | 102 |
90 private ShouldInterceptRequestHelper mShouldInterceptRequestHelper; | 103 private ShouldInterceptRequestHelper mShouldInterceptRequestHelper; |
91 private OnLoadResourceHelper mOnLoadResourceHelper; | 104 private OnLoadResourceHelper mOnLoadResourceHelper; |
92 | 105 |
93 public TestAwContentsClient() { | 106 public TestAwContentsClient() { |
94 mShouldInterceptRequestHelper = new ShouldInterceptRequestHelper(); | 107 mShouldInterceptRequestHelper = new ShouldInterceptRequestHelper(); |
95 mOnLoadResourceHelper = new OnLoadResourceHelper(); | 108 mOnLoadResourceHelper = new OnLoadResourceHelper(); |
96 } | 109 } |
97 | 110 |
98 public ShouldInterceptRequestHelper getShouldInterceptRequestHelper() { | 111 public ShouldInterceptRequestHelper getShouldInterceptRequestHelper() { |
99 return mShouldInterceptRequestHelper; | 112 return mShouldInterceptRequestHelper; |
100 } | 113 } |
101 | 114 |
102 public OnLoadResourceHelper getOnLoadResourceHelper() { | 115 public OnLoadResourceHelper getOnLoadResourceHelper() { |
103 return mOnLoadResourceHelper; | 116 return mOnLoadResourceHelper; |
104 } | 117 } |
105 } | 118 } |
106 | 119 |
| 120 final int teapotStatusCode = 418; |
| 121 final String teapotResponsePhrase = "I'm a teapot"; |
| 122 |
107 private String addPageToTestServer(TestWebServer webServer, String httpPath,
String html) { | 123 private String addPageToTestServer(TestWebServer webServer, String httpPath,
String html) { |
108 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>
(); | 124 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>
(); |
109 headers.add(Pair.create("Content-Type", "text/html")); | 125 headers.add(Pair.create("Content-Type", "text/html")); |
110 headers.add(Pair.create("Cache-Control", "no-store")); | 126 headers.add(Pair.create("Cache-Control", "no-store")); |
111 return webServer.setResponse(httpPath, html, headers); | 127 return webServer.setResponse(httpPath, html, headers); |
112 } | 128 } |
113 | 129 |
114 private String addAboutPageToTestServer(TestWebServer webServer) { | 130 private String addAboutPageToTestServer(TestWebServer webServer) { |
115 return addPageToTestServer(webServer, "/" + CommonResources.ABOUT_FILENA
ME, | 131 return addPageToTestServer(webServer, "/" + CommonResources.ABOUT_FILENA
ME, |
116 CommonResources.ABOUT_HTML); | 132 CommonResources.ABOUT_HTML); |
117 } | 133 } |
118 | 134 |
119 private InterceptedRequestData stringToInterceptedRequestData(String input)
throws Throwable { | 135 private AwWebResourceResponse stringToAwWebResourceResponse(String input) th
rows Throwable { |
120 final String mimeType = "text/html"; | 136 final String mimeType = "text/html"; |
121 final String encoding = "UTF-8"; | 137 final String encoding = "UTF-8"; |
122 | 138 |
123 return new InterceptedRequestData( | 139 return new AwWebResourceResponse( |
124 mimeType, encoding, new ByteArrayInputStream(input.getBytes(enco
ding))); | 140 mimeType, encoding, new ByteArrayInputStream(input.getBytes(enco
ding))); |
125 } | 141 } |
126 | 142 |
127 private TestWebServer mWebServer; | 143 private TestWebServer mWebServer; |
128 private TestAwContentsClient mContentsClient; | 144 private TestAwContentsClient mContentsClient; |
129 private AwTestContainerView mTestContainerView; | 145 private AwTestContainerView mTestContainerView; |
130 private AwContents mAwContents; | 146 private AwContents mAwContents; |
131 private TestAwContentsClient.ShouldInterceptRequestHelper mShouldInterceptRe
questHelper; | 147 private TestAwContentsClient.ShouldInterceptRequestHelper mShouldInterceptRe
questHelper; |
132 | 148 |
133 @Override | 149 @Override |
134 protected void setUp() throws Exception { | 150 protected void setUp() throws Exception { |
135 super.setUp(); | 151 super.setUp(); |
136 | 152 |
137 mContentsClient = new TestAwContentsClient(); | 153 mContentsClient = new TestAwContentsClient(); |
138 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient
); | 154 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient
); |
139 mAwContents = mTestContainerView.getAwContents(); | 155 mAwContents = mTestContainerView.getAwContents(); |
140 mShouldInterceptRequestHelper = mContentsClient.getShouldInterceptReques
tHelper(); | 156 mShouldInterceptRequestHelper = mContentsClient.getShouldInterceptReques
tHelper(); |
141 | 157 |
142 mWebServer = new TestWebServer(false); | 158 mWebServer = new TestWebServer(false); |
143 } | 159 } |
144 | 160 |
145 @Override | 161 @Override |
146 protected void tearDown() throws Exception { | 162 protected void tearDown() throws Exception { |
147 mWebServer.shutdown(); | 163 mWebServer.shutdown(); |
148 super.tearDown(); | 164 super.tearDown(); |
149 } | 165 } |
150 | 166 |
151 @SmallTest | 167 @SmallTest |
152 @Feature({"AndroidWebView"}) | 168 @Feature({"AndroidWebView"}) |
153 public void testCalledWithCorrectUrl() throws Throwable { | 169 public void testCalledWithCorrectUrlParam() throws Throwable { |
154 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 170 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
155 | 171 |
156 int callCount = mShouldInterceptRequestHelper.getCallCount(); | |
157 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); | 172 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); |
158 | 173 |
| 174 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
159 loadUrlAsync(mAwContents, aboutPageUrl); | 175 loadUrlAsync(mAwContents, aboutPageUrl); |
160 | |
161 mShouldInterceptRequestHelper.waitForCallback(callCount); | 176 mShouldInterceptRequestHelper.waitForCallback(callCount); |
162 assertEquals(1, mShouldInterceptRequestHelper.getUrls().size()); | 177 assertEquals(1, mShouldInterceptRequestHelper.getUrls().size()); |
163 assertEquals(aboutPageUrl, | 178 assertEquals(aboutPageUrl, |
164 mShouldInterceptRequestHelper.getUrls().get(0)); | 179 mShouldInterceptRequestHelper.getUrls().get(0)); |
165 | 180 |
166 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); | 181 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); |
167 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); | 182 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); |
168 } | 183 } |
169 | 184 |
170 @SmallTest | 185 @SmallTest |
171 @Feature({"AndroidWebView"}) | 186 @Feature({"AndroidWebView"}) |
| 187 public void testCalledWithCorrectIsMainFrameParam() throws Throwable { |
| 188 final String subframeUrl = addAboutPageToTestServer(mWebServer); |
| 189 final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/page_
with_iframe.html", |
| 190 CommonResources.makeHtmlPageFrom("", |
| 191 "<iframe src=\"" + subframeUrl + "\"/>")); |
| 192 |
| 193 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 194 loadUrlAsync(mAwContents, pageWithIframeUrl); |
| 195 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
| 196 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
| 197 assertEquals(false, |
| 198 mShouldInterceptRequestHelper.getParamsForUrl(subframeUrl).isMai
nFrame); |
| 199 assertEquals(true, |
| 200 mShouldInterceptRequestHelper.getParamsForUrl(pageWithIframeUrl)
.isMainFrame); |
| 201 } |
| 202 |
| 203 @SmallTest |
| 204 @Feature({"AndroidWebView"}) |
| 205 public void testCalledWithCorrectMethodParam() throws Throwable { |
| 206 final String pageToPostToUrl = addAboutPageToTestServer(mWebServer); |
| 207 final String pageWithFormUrl = addPageToTestServer(mWebServer, "/page_wi
th_form.html", |
| 208 CommonResources.makeHtmlPageWithSimplePostFormTo(pageToPostToUrl
)); |
| 209 enableJavaScriptOnUiThread(mAwContents); |
| 210 |
| 211 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 212 loadUrlAsync(mAwContents, pageWithFormUrl); |
| 213 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 214 assertEquals("GET", |
| 215 mShouldInterceptRequestHelper.getParamsForUrl(pageWithFormUrl).m
ethod); |
| 216 |
| 217 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 218 JSUtils.clickOnLinkUsingJs(this, mAwContents, |
| 219 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); |
| 220 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 221 assertEquals("POST", |
| 222 mShouldInterceptRequestHelper.getParamsForUrl(pageToPostToUrl).m
ethod); |
| 223 } |
| 224 |
| 225 @SmallTest |
| 226 @Feature({"AndroidWebView"}) |
| 227 public void testCalledWithCorrectHasUserGestureParam() throws Throwable { |
| 228 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 229 final String pageWithLinkUrl = addPageToTestServer(mWebServer, "/page_wi
th_link.html", |
| 230 CommonResources.makeHtmlPageWithSimpleLinkTo(aboutPageUrl)); |
| 231 enableJavaScriptOnUiThread(mAwContents); |
| 232 |
| 233 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 234 loadUrlAsync(mAwContents, pageWithLinkUrl); |
| 235 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 236 assertEquals(false, |
| 237 mShouldInterceptRequestHelper.getParamsForUrl(pageWithLinkUrl).h
asUserGesture); |
| 238 |
| 239 callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 240 JSUtils.clickOnLinkUsingJs(this, mAwContents, |
| 241 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); |
| 242 mShouldInterceptRequestHelper.waitForCallback(callCount); |
| 243 assertEquals(true, |
| 244 mShouldInterceptRequestHelper.getParamsForUrl(aboutPageUrl).hasU
serGesture); |
| 245 } |
| 246 |
| 247 @SmallTest |
| 248 @Feature({"AndroidWebView"}) |
| 249 public void testCalledWithCorrectHeadersParam() throws Throwable { |
| 250 final String headerName = "X-Test-Header-Name"; |
| 251 final String headerValue = "TestHeaderValue"; |
| 252 final String syncGetUrl = addPageToTestServer(mWebServer, "/intercept_me
", |
| 253 CommonResources.ABOUT_HTML); |
| 254 final String mainPageUrl = addPageToTestServer(mWebServer, "/main", |
| 255 CommonResources.makeHtmlPageFrom("", |
| 256 "<script>" + |
| 257 " var xhr = new XMLHttpRequest();" + |
| 258 " xhr.open('GET', '" + syncGetUrl + "', false);" + |
| 259 " xhr.setRequestHeader('" + headerName + "', '" + headerValue +
"'); " + |
| 260 " xhr.send(null);" + |
| 261 "</script>")); |
| 262 enableJavaScriptOnUiThread(mAwContents); |
| 263 |
| 264 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
| 265 loadUrlAsync(mAwContents, mainPageUrl); |
| 266 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
| 267 |
| 268 Map<String, String> headers = |
| 269 mShouldInterceptRequestHelper.getParamsForUrl(syncGetUrl).requestHea
ders; |
| 270 assertTrue(headers.containsKey(headerName)); |
| 271 assertEquals(headerValue, headers.get(headerName)); |
| 272 } |
| 273 |
| 274 @SmallTest |
| 275 @Feature({"AndroidWebView"}) |
172 public void testOnLoadResourceCalledWithCorrectUrl() throws Throwable { | 276 public void testOnLoadResourceCalledWithCorrectUrl() throws Throwable { |
173 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 277 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
174 final TestAwContentsClient.OnLoadResourceHelper onLoadResourceHelper = | 278 final TestAwContentsClient.OnLoadResourceHelper onLoadResourceHelper = |
175 mContentsClient.getOnLoadResourceHelper(); | 279 mContentsClient.getOnLoadResourceHelper(); |
176 | 280 |
177 int callCount = onLoadResourceHelper.getCallCount(); | 281 int callCount = onLoadResourceHelper.getCallCount(); |
178 | 282 |
179 loadUrlAsync(mAwContents, aboutPageUrl); | 283 loadUrlAsync(mAwContents, aboutPageUrl); |
180 | 284 |
181 onLoadResourceHelper.waitForCallback(callCount); | 285 onLoadResourceHelper.waitForCallback(callCount); |
182 assertEquals(aboutPageUrl, onLoadResourceHelper.getUrl()); | 286 assertEquals(aboutPageUrl, onLoadResourceHelper.getUrl()); |
183 } | 287 } |
184 | 288 |
185 @SmallTest | 289 @SmallTest |
186 @Feature({"AndroidWebView"}) | 290 @Feature({"AndroidWebView"}) |
187 public void testDoesNotCrashOnInvalidData() throws Throwable { | 291 public void testDoesNotCrashOnInvalidData() throws Throwable { |
188 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 292 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
189 | 293 |
190 mShouldInterceptRequestHelper.setReturnValue( | 294 mShouldInterceptRequestHelper.setReturnValue( |
191 new InterceptedRequestData("text/html", "UTF-8", null)); | 295 new AwWebResourceResponse("text/html", "UTF-8", null)); |
192 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 296 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
193 loadUrlAsync(mAwContents, aboutPageUrl); | 297 loadUrlAsync(mAwContents, aboutPageUrl); |
194 mShouldInterceptRequestHelper.waitForCallback(callCount); | 298 mShouldInterceptRequestHelper.waitForCallback(callCount); |
195 | 299 |
196 mShouldInterceptRequestHelper.setReturnValue( | 300 mShouldInterceptRequestHelper.setReturnValue( |
197 new InterceptedRequestData(null, null, new ByteArrayInputStream(
new byte[0]))); | 301 new AwWebResourceResponse(null, null, new ByteArrayInputStream(n
ew byte[0]))); |
198 callCount = mShouldInterceptRequestHelper.getCallCount(); | 302 callCount = mShouldInterceptRequestHelper.getCallCount(); |
199 loadUrlAsync(mAwContents, aboutPageUrl); | 303 loadUrlAsync(mAwContents, aboutPageUrl); |
200 mShouldInterceptRequestHelper.waitForCallback(callCount); | 304 mShouldInterceptRequestHelper.waitForCallback(callCount); |
201 | 305 |
202 mShouldInterceptRequestHelper.setReturnValue( | 306 mShouldInterceptRequestHelper.setReturnValue( |
203 new InterceptedRequestData(null, null, null)); | 307 new AwWebResourceResponse(null, null, null)); |
204 callCount = mShouldInterceptRequestHelper.getCallCount(); | 308 callCount = mShouldInterceptRequestHelper.getCallCount(); |
205 loadUrlAsync(mAwContents, aboutPageUrl); | 309 loadUrlAsync(mAwContents, aboutPageUrl); |
206 mShouldInterceptRequestHelper.waitForCallback(callCount); | 310 mShouldInterceptRequestHelper.waitForCallback(callCount); |
207 } | 311 } |
208 | 312 |
209 private static class EmptyInputStream extends InputStream { | 313 private static class EmptyInputStream extends InputStream { |
210 @Override | 314 @Override |
211 public int available() { | 315 public int available() { |
212 return 0; | 316 return 0; |
213 } | 317 } |
(...skipping 20 matching lines...) Expand all Loading... |
234 return 0; | 338 return 0; |
235 } | 339 } |
236 } | 340 } |
237 | 341 |
238 @SmallTest | 342 @SmallTest |
239 @Feature({"AndroidWebView"}) | 343 @Feature({"AndroidWebView"}) |
240 public void testDoesNotCrashOnEmptyStream() throws Throwable { | 344 public void testDoesNotCrashOnEmptyStream() throws Throwable { |
241 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 345 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
242 | 346 |
243 mShouldInterceptRequestHelper.setReturnValue( | 347 mShouldInterceptRequestHelper.setReturnValue( |
244 new InterceptedRequestData("text/html", "UTF-8", new EmptyInputS
tream())); | 348 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); |
245 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); | 349 int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getC
allCount(); |
246 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); | 350 int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().
getCallCount(); |
247 | 351 |
248 loadUrlAsync(mAwContents, aboutPageUrl); | 352 loadUrlAsync(mAwContents, aboutPageUrl); |
249 | 353 |
250 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); | 354 mShouldInterceptRequestHelper.waitForCallback(shouldInterceptRequestCall
Count); |
251 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); | 355 mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinished
CallCount); |
252 } | 356 } |
253 | 357 |
254 private static class SlowInterceptedRequestData extends InterceptedRequestDa
ta { | 358 private static class SlowAwWebResourceResponse extends AwWebResourceResponse
{ |
255 private CallbackHelper mReadStartedCallbackHelper = new CallbackHelper()
; | 359 private CallbackHelper mReadStartedCallbackHelper = new CallbackHelper()
; |
256 private CountDownLatch mLatch = new CountDownLatch(1); | 360 private CountDownLatch mLatch = new CountDownLatch(1); |
257 | 361 |
258 public SlowInterceptedRequestData(String mimeType, String encoding, Inpu
tStream data) { | 362 public SlowAwWebResourceResponse(String mimeType, String encoding, Input
Stream data) { |
259 super(mimeType, encoding, data); | 363 super(mimeType, encoding, data); |
260 } | 364 } |
261 | 365 |
262 @Override | 366 @Override |
263 public InputStream getData() { | 367 public InputStream getData() { |
264 mReadStartedCallbackHelper.notifyCalled(); | 368 mReadStartedCallbackHelper.notifyCalled(); |
265 try { | 369 try { |
266 mLatch.await(); | 370 mLatch.await(); |
267 } catch (InterruptedException e) { | 371 } catch (InterruptedException e) { |
268 // ignore | 372 // ignore |
269 } | 373 } |
270 return super.getData(); | 374 return super.getData(); |
271 } | 375 } |
272 | 376 |
273 public void unblockReads() { | 377 public void unblockReads() { |
274 mLatch.countDown(); | 378 mLatch.countDown(); |
275 } | 379 } |
276 | 380 |
277 public CallbackHelper getReadStartedCallbackHelper() { | 381 public CallbackHelper getReadStartedCallbackHelper() { |
278 return mReadStartedCallbackHelper; | 382 return mReadStartedCallbackHelper; |
279 } | 383 } |
280 } | 384 } |
281 | 385 |
282 @SmallTest | 386 @SmallTest |
283 @Feature({"AndroidWebView"}) | 387 @Feature({"AndroidWebView"}) |
284 public void testDoesNotCrashOnSlowStream() throws Throwable { | 388 public void testDoesNotCrashOnSlowStream() throws Throwable { |
285 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 389 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
286 final String aboutPageData = makePageWithTitle("some title"); | 390 final String aboutPageData = makePageWithTitle("some title"); |
287 final String encoding = "UTF-8"; | 391 final String encoding = "UTF-8"; |
288 final SlowInterceptedRequestData slowInterceptedRequestData = | 392 final SlowAwWebResourceResponse slowAwWebResourceResponse = |
289 new SlowInterceptedRequestData("text/html", encoding, | 393 new SlowAwWebResourceResponse("text/html", encoding, |
290 new ByteArrayInputStream(aboutPageData.getBytes(encoding))); | 394 new ByteArrayInputStream(aboutPageData.getBytes(encoding))); |
291 | 395 |
292 mShouldInterceptRequestHelper.setReturnValue(slowInterceptedRequestData)
; | 396 mShouldInterceptRequestHelper.setReturnValue(slowAwWebResourceResponse); |
293 int callCount = slowInterceptedRequestData.getReadStartedCallbackHelper(
).getCallCount(); | 397 int callCount = slowAwWebResourceResponse.getReadStartedCallbackHelper()
.getCallCount(); |
294 loadUrlAsync(mAwContents, aboutPageUrl); | 398 loadUrlAsync(mAwContents, aboutPageUrl); |
295 slowInterceptedRequestData.getReadStartedCallbackHelper().waitForCallbac
k(callCount); | 399 slowAwWebResourceResponse.getReadStartedCallbackHelper().waitForCallback
(callCount); |
296 | 400 |
297 // Now the AwContents is "stuck" waiting for the SlowInputStream to fini
sh reading so we | 401 // Now the AwContents is "stuck" waiting for the SlowInputStream to fini
sh reading so we |
298 // delete it to make sure that the dangling 'read' task doesn't cause a
crash. Unfortunately | 402 // delete it to make sure that the dangling 'read' task doesn't cause a
crash. Unfortunately |
299 // this will not always lead to a crash but it should happen often enoug
h for us to notice. | 403 // this will not always lead to a crash but it should happen often enoug
h for us to notice. |
300 | 404 |
301 runTestOnUiThread(new Runnable() { | 405 runTestOnUiThread(new Runnable() { |
302 @Override | 406 @Override |
303 public void run() { | 407 public void run() { |
304 getActivity().removeAllViews(); | 408 getActivity().removeAllViews(); |
305 } | 409 } |
306 }); | 410 }); |
307 destroyAwContentsOnMainSync(mAwContents); | 411 destroyAwContentsOnMainSync(mAwContents); |
308 pollOnUiThread(new Callable<Boolean>() { | 412 pollOnUiThread(new Callable<Boolean>() { |
309 @Override | 413 @Override |
310 public Boolean call() { | 414 public Boolean call() { |
311 return AwContents.getNativeInstanceCount() == 0; | 415 return AwContents.getNativeInstanceCount() == 0; |
312 } | 416 } |
313 }); | 417 }); |
314 | 418 |
315 slowInterceptedRequestData.unblockReads(); | 419 slowAwWebResourceResponse.unblockReads(); |
316 } | 420 } |
317 | 421 |
318 @SmallTest | 422 @SmallTest |
319 @Feature({"AndroidWebView"}) | 423 @Feature({"AndroidWebView"}) |
320 public void testHttpStatusField() throws Throwable { | 424 public void testHttpStatusCodeAndText() throws Throwable { |
321 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); | 425 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
322 final String syncGetJs = | 426 final String syncGetJs = |
323 "(function() {" + | 427 "(function() {" + |
324 " var xhr = new XMLHttpRequest();" + | 428 " var xhr = new XMLHttpRequest();" + |
325 " xhr.open('GET', '" + syncGetUrl + "', false);" + | 429 " xhr.open('GET', '" + syncGetUrl + "', false);" + |
326 " xhr.send(null);" + | 430 " xhr.send(null);" + |
327 " console.info('xhr.status = ' + xhr.status);" + | 431 " console.info('xhr.status = ' + xhr.status);" + |
328 " return xhr.status;" + | 432 " console.info('xhr.statusText = ' + xhr.statusText);" + |
| 433 " return '[' + xhr.status + '][' + xhr.statusText + ']';" + |
329 "})();"; | 434 "})();"; |
330 enableJavaScriptOnUiThread(mAwContents); | 435 enableJavaScriptOnUiThread(mAwContents); |
331 | 436 |
332 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 437 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
333 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 438 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
334 | 439 |
335 mShouldInterceptRequestHelper.setReturnValue( | 440 mShouldInterceptRequestHelper.setReturnValue( |
336 new InterceptedRequestData("text/html", "UTF-8", null)); | 441 new AwWebResourceResponse("text/html", "UTF-8", null)); |
337 assertEquals("404", | 442 assertEquals("\"[404][Not Found]\"", |
338 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 443 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
339 | 444 |
340 mShouldInterceptRequestHelper.setReturnValue( | 445 mShouldInterceptRequestHelper.setReturnValue( |
341 new InterceptedRequestData("text/html", "UTF-8", new EmptyInputS
tream())); | 446 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); |
342 assertEquals("200", | 447 assertEquals("\"[200][OK]\"", |
343 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 448 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
| 449 |
| 450 mShouldInterceptRequestHelper.setReturnValue( |
| 451 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream(), |
| 452 teapotStatusCode, teapotResponsePhrase, new HashMap<String,
String>())); |
| 453 assertEquals("\"[" + teapotStatusCode + "][" + teapotResponsePhrase + "]
\"", |
| 454 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); |
| 455 } |
| 456 |
| 457 private String getHeaderValue(AwContents awContents, TestAwContentsClient co
ntentsClient, |
| 458 String url, String headerName) throws Exception { |
| 459 final String syncGetJs = |
| 460 "(function() {" + |
| 461 " var xhr = new XMLHttpRequest();" + |
| 462 " xhr.open('GET', '" + url + "', false);" + |
| 463 " xhr.send(null);" + |
| 464 " console.info(xhr.getAllResponseHeaders());" + |
| 465 " return xhr.getResponseHeader('" + headerName + "');" + |
| 466 "})();"; |
| 467 String header = executeJavaScriptAndWaitForResult(awContents, contentsCl
ient, syncGetJs); |
| 468 // JSON stringification applied by executeJavaScriptAndWaitForResult add
s quotes |
| 469 // around returned strings. |
| 470 assertTrue(header.length() > 2); |
| 471 assertEquals('"', header.charAt(0)); |
| 472 assertEquals('"', header.charAt(header.length() - 1)); |
| 473 return header.substring(1, header.length() - 1); |
344 } | 474 } |
345 | 475 |
346 @SmallTest | 476 @SmallTest |
347 @Feature({"AndroidWebView"}) | 477 @Feature({"AndroidWebView"}) |
348 public void testHttpResponseClientHeader() throws Throwable { | 478 public void testHttpResponseClientViaHeader() throws Throwable { |
349 final String clientResponseHeaderName = "Client-Via"; | 479 final String clientResponseHeaderName = "Client-Via"; |
350 // JSON stringification applied by executeJavaScriptAndWaitForResult add
s quotes | 480 final String clientResponseHeaderValue = "shouldInterceptRequest"; |
351 // around returned strings. | |
352 final String clientResponseHeaderValue = "\"shouldInterceptRequest\""; | |
353 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); | 481 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
354 final String syncGetJs = | |
355 "(function() {" + | |
356 " var xhr = new XMLHttpRequest();" + | |
357 " xhr.open('GET', '" + syncGetUrl + "', false);" + | |
358 " xhr.send(null);" + | |
359 " console.info(xhr.getAllResponseHeaders());" + | |
360 " return xhr.getResponseHeader('" + clientResponseHeaderName + "');
" + | |
361 "})();"; | |
362 enableJavaScriptOnUiThread(mAwContents); | 482 enableJavaScriptOnUiThread(mAwContents); |
363 | 483 |
364 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 484 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
365 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 485 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
366 | 486 |
367 // The response header is set regardless of whether the embedder has pro
vided a | 487 // The response header is set regardless of whether the embedder has pro
vided a |
368 // valid resource stream. | 488 // valid resource stream. |
369 mShouldInterceptRequestHelper.setReturnValue( | 489 mShouldInterceptRequestHelper.setReturnValue( |
370 new InterceptedRequestData("text/html", "UTF-8", null)); | 490 new AwWebResourceResponse("text/html", "UTF-8", null)); |
371 assertEquals(clientResponseHeaderValue, | 491 assertEquals(clientResponseHeaderValue, |
372 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 492 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
373 mShouldInterceptRequestHelper.setReturnValue( | 493 mShouldInterceptRequestHelper.setReturnValue( |
374 new InterceptedRequestData("text/html", "UTF-8", new EmptyInputS
tream())); | 494 new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputSt
ream())); |
375 assertEquals(clientResponseHeaderValue, | 495 assertEquals(clientResponseHeaderValue, |
376 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
syncGetJs)); | 496 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
| 497 |
377 } | 498 } |
378 | 499 |
| 500 @SmallTest |
| 501 @Feature({"AndroidWebView"}) |
| 502 public void testHttpResponseHeader() throws Throwable { |
| 503 final String clientResponseHeaderName = "X-Test-Header-Name"; |
| 504 final String clientResponseHeaderValue = "TestHeaderValue"; |
| 505 final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me"); |
| 506 final Map<String, String> headers = new HashMap<String, String>(); |
| 507 headers.put(clientResponseHeaderName, clientResponseHeaderValue); |
| 508 enableJavaScriptOnUiThread(mAwContents); |
| 509 |
| 510 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
| 511 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
| 512 |
| 513 mShouldInterceptRequestHelper.setReturnValue( |
| 514 new AwWebResourceResponse("text/html", "UTF-8", null, 0, null, h
eaders)); |
| 515 assertEquals(clientResponseHeaderValue, |
| 516 getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientR
esponseHeaderName)); |
| 517 } |
379 | 518 |
380 private String makePageWithTitle(String title) { | 519 private String makePageWithTitle(String title) { |
381 return CommonResources.makeHtmlPageFrom("<title>" + title + "</title>", | 520 return CommonResources.makeHtmlPageFrom("<title>" + title + "</title>", |
382 "<div> The title is: " + title + " </div>"); | 521 "<div> The title is: " + title + " </div>"); |
383 } | 522 } |
384 | 523 |
385 @SmallTest | 524 @SmallTest |
386 @Feature({"AndroidWebView"}) | 525 @Feature({"AndroidWebView"}) |
387 public void testCanInterceptMainFrame() throws Throwable { | 526 public void testCanInterceptMainFrame() throws Throwable { |
388 final String expectedTitle = "testShouldInterceptRequestCanInterceptMain
Frame"; | 527 final String expectedTitle = "testShouldInterceptRequestCanInterceptMain
Frame"; |
389 final String expectedPage = makePageWithTitle(expectedTitle); | 528 final String expectedPage = makePageWithTitle(expectedTitle); |
390 | 529 |
391 mShouldInterceptRequestHelper.setReturnValue( | 530 mShouldInterceptRequestHelper.setReturnValue( |
392 stringToInterceptedRequestData(expectedPage)); | 531 stringToAwWebResourceResponse(expectedPage)); |
393 | 532 |
394 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 533 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
395 | 534 |
396 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 535 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
397 | 536 |
398 assertEquals(expectedTitle, getTitleOnUiThread(mAwContents)); | 537 assertEquals(expectedTitle, getTitleOnUiThread(mAwContents)); |
399 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); | 538 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); |
400 } | 539 } |
401 | 540 |
402 @SmallTest | 541 @SmallTest |
403 @Feature({"AndroidWebView"}) | 542 @Feature({"AndroidWebView"}) |
404 public void testDoesNotChangeReportedUrl() throws Throwable { | 543 public void testDoesNotChangeReportedUrl() throws Throwable { |
405 mShouldInterceptRequestHelper.setReturnValue( | 544 mShouldInterceptRequestHelper.setReturnValue( |
406 stringToInterceptedRequestData(makePageWithTitle("some title")))
; | 545 stringToAwWebResourceResponse(makePageWithTitle("some title"))); |
407 | 546 |
408 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 547 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
409 | 548 |
410 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); | 549 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), abou
tPageUrl); |
411 | 550 |
412 assertEquals(aboutPageUrl, mContentsClient.getOnPageFinishedHelper().get
Url()); | 551 assertEquals(aboutPageUrl, mContentsClient.getOnPageFinishedHelper().get
Url()); |
413 assertEquals(aboutPageUrl, mContentsClient.getOnPageStartedHelper().getU
rl()); | 552 assertEquals(aboutPageUrl, mContentsClient.getOnPageStartedHelper().getU
rl()); |
414 } | 553 } |
415 | 554 |
416 @SmallTest | 555 @SmallTest |
417 @Feature({"AndroidWebView"}) | 556 @Feature({"AndroidWebView"}) |
418 public void testNullInputStreamCausesErrorForMainFrame() throws Throwable { | 557 public void testNullInputStreamCausesErrorForMainFrame() throws Throwable { |
419 final OnReceivedErrorHelper onReceivedErrorHelper = | 558 final OnReceivedErrorHelper onReceivedErrorHelper = |
420 mContentsClient.getOnReceivedErrorHelper(); | 559 mContentsClient.getOnReceivedErrorHelper(); |
421 | 560 |
422 mShouldInterceptRequestHelper.setReturnValue( | 561 mShouldInterceptRequestHelper.setReturnValue( |
423 new InterceptedRequestData("text/html", "UTF-8", null)); | 562 new AwWebResourceResponse("text/html", "UTF-8", null)); |
424 | 563 |
425 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 564 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
426 final int callCount = onReceivedErrorHelper.getCallCount(); | 565 final int callCount = onReceivedErrorHelper.getCallCount(); |
427 loadUrlAsync(mAwContents, aboutPageUrl); | 566 loadUrlAsync(mAwContents, aboutPageUrl); |
428 onReceivedErrorHelper.waitForCallback(callCount); | 567 onReceivedErrorHelper.waitForCallback(callCount); |
429 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); | 568 assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_F
ILENAME)); |
430 } | 569 } |
431 | 570 |
432 @SmallTest | 571 @SmallTest |
433 @Feature({"AndroidWebView"}) | 572 @Feature({"AndroidWebView"}) |
(...skipping 10 matching lines...) Expand all Loading... |
444 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); | 583 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
445 | 584 |
446 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); | 585 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
447 assertTrue(mShouldInterceptRequestHelper.getUrls().get(1).endsWith( | 586 assertTrue(mShouldInterceptRequestHelper.getUrls().get(1).endsWith( |
448 CommonResources.FAVICON_FILENAME)); | 587 CommonResources.FAVICON_FILENAME)); |
449 } | 588 } |
450 | 589 |
451 @SmallTest | 590 @SmallTest |
452 @Feature({"AndroidWebView"}) | 591 @Feature({"AndroidWebView"}) |
453 public void testOnReceivedErrorCallback() throws Throwable { | 592 public void testOnReceivedErrorCallback() throws Throwable { |
454 mShouldInterceptRequestHelper.setReturnValue(new InterceptedRequestData(
null, null, null)); | 593 mShouldInterceptRequestHelper.setReturnValue(new AwWebResourceResponse(n
ull, null, null)); |
455 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 594 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
456 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); | 595 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); |
457 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo
://bar"); | 596 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo
://bar"); |
458 onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1)
; | 597 onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1)
; |
459 } | 598 } |
460 | 599 |
461 @SmallTest | 600 @SmallTest |
462 @Feature({"AndroidWebView"}) | 601 @Feature({"AndroidWebView"}) |
463 public void testNoOnReceivedErrorCallback() throws Throwable { | 602 public void testNoOnReceivedErrorCallback() throws Throwable { |
464 final String imagePath = "/" + CommonResources.FAVICON_FILENAME; | 603 final String imagePath = "/" + CommonResources.FAVICON_FILENAME; |
465 final String imageUrl = mWebServer.setResponseBase64(imagePath, | 604 final String imageUrl = mWebServer.setResponseBase64(imagePath, |
466 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePng
Headers(true)); | 605 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePng
Headers(true)); |
467 final String pageWithImage = | 606 final String pageWithImage = |
468 addPageToTestServer(mWebServer, "/page_with_image.html", | 607 addPageToTestServer(mWebServer, "/page_with_image.html", |
469 CommonResources.getOnImageLoadedHtml(CommonResources.FAV
ICON_FILENAME)); | 608 CommonResources.getOnImageLoadedHtml(CommonResources.FAV
ICON_FILENAME)); |
470 mShouldInterceptRequestHelper.setReturnValueForUrl( | 609 mShouldInterceptRequestHelper.setReturnValueForUrl( |
471 imageUrl, new InterceptedRequestData(null, null, null)); | 610 imageUrl, new AwWebResourceResponse(null, null, null)); |
472 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 611 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
473 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); | 612 int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(
); |
474 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithImage); | 613 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithImage); |
475 assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCa
llCount()); | 614 assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCa
llCount()); |
476 } | 615 } |
477 | 616 |
478 @SmallTest | 617 @SmallTest |
479 @Feature({"AndroidWebView"}) | 618 @Feature({"AndroidWebView"}) |
480 public void testCalledForIframe() throws Throwable { | 619 public void testCalledForIframe() throws Throwable { |
481 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); | 620 final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
482 final String pageWithIframe = addPageToTestServer(mWebServer, "/page_wit
h_iframe.html", | 621 final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/page_
with_iframe.html", |
483 CommonResources.makeHtmlPageFrom("", | 622 CommonResources.makeHtmlPageFrom("", |
484 "<iframe src=\"" + aboutPageUrl + "\"/>")); | 623 "<iframe src=\"" + aboutPageUrl + "\"/>")); |
485 | 624 |
486 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 625 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
487 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithIframe); | 626 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), page
WithIframeUrl); |
488 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); | 627 mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
489 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); | 628 assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
490 assertEquals(aboutPageUrl, mShouldInterceptRequestHelper.getUrls().get(1
)); | 629 assertEquals(aboutPageUrl, mShouldInterceptRequestHelper.getUrls().get(1
)); |
491 } | 630 } |
492 | 631 |
493 private void calledForUrlTemplate(final String url) throws Exception { | 632 private void calledForUrlTemplate(final String url) throws Exception { |
494 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 633 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
495 int onPageStartedCallCount = mContentsClient.getOnPageStartedHelper().ge
tCallCount(); | 634 int onPageStartedCallCount = mContentsClient.getOnPageStartedHelper().ge
tCallCount(); |
496 loadUrlAsync(mAwContents, url); | 635 loadUrlAsync(mAwContents, url); |
497 mShouldInterceptRequestHelper.waitForCallback(callCount); | 636 mShouldInterceptRequestHelper.waitForCallback(callCount); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 getInstrumentation().getTargetContext(), contentResourceName); | 720 getInstrumentation().getTargetContext(), contentResourceName); |
582 assertEquals(1, contentRequestCount); | 721 assertEquals(1, contentRequestCount); |
583 } | 722 } |
584 | 723 |
585 @SmallTest | 724 @SmallTest |
586 @Feature({"AndroidWebView"}) | 725 @Feature({"AndroidWebView"}) |
587 public void testCalledForNonexistentContentUrl() throws Throwable { | 726 public void testCalledForNonexistentContentUrl() throws Throwable { |
588 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo"
); | 727 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo"
); |
589 } | 728 } |
590 } | 729 } |
OLD | NEW |