Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java

Issue 284123004: [android_webview] Add more params to request intercepting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix accidentally broken test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOver rideHelper, 57 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOver rideHelper,
58 final boolean value) throws Throwable { 58 final boolean value) throws Throwable {
59 runTestOnUiThread(new Runnable() { 59 runTestOnUiThread(new Runnable() {
60 @Override 60 @Override
61 public void run() { 61 public void run() {
62 shouldOverrideHelper.setShouldOverrideUrlLoadingReturnValue(valu e); 62 shouldOverrideHelper.setShouldOverrideUrlLoadingReturnValue(valu e);
63 } 63 }
64 }); 64 });
65 } 65 }
66 66
67 private String makeHtmlPageFrom(String headers, String body) { 67 private String getTestPageCommonHeaders() {
68 return CommonResources.makeHtmlPageFrom("<title>" + TITLE + "</title> " + headers, body); 68 return "<title>" + TITLE + "</title> ";
69 } 69 }
70 70
71 private String getHtmlForPageWithSimpleLinkTo(String destination) { 71 private String makeHtmlPageFrom(String headers, String body) {
72 return makeHtmlPageFrom("", 72 return CommonResources.makeHtmlPageFrom(getTestPageCommonHeaders() + hea ders, body);
73 "<a href=\"" + destination + "\" id=\"link\">" +
74 "<img class=\"big\" />" +
75 "</a>");
76 } 73 }
77 74
78 private String getHtmlForPageWithJsAssignLinkTo(String url) { 75 private String getHtmlForPageWithJsAssignLinkTo(String url) {
79 return makeHtmlPageFrom("", 76 return makeHtmlPageFrom("",
80 "<img onclick=\"location.href='" + url + "'\" class=\"big\" id=\ "link\" />"); 77 "<img onclick=\"location.href='" + url + "'\" class=\"big\" id=\ "link\" />");
81 } 78 }
82 79
83 private String getHtmlForPageWithJsReplaceLinkTo(String url) { 80 private String getHtmlForPageWithJsReplaceLinkTo(String url) {
84 return makeHtmlPageFrom("", 81 return makeHtmlPageFrom("",
85 "<img onclick=\"location.replace('" + url + "');\" class=\"big\" id=\"link\" />"); 82 "<img onclick=\"location.replace('" + url + "');\" class=\"big\" id=\"link\" />");
(...skipping 11 matching lines...) Expand all
97 "location.href = '" + url + "';" + 94 "location.href = '" + url + "';" +
98 "} " + 95 "} " +
99 "function doRedirectReplace() {" + 96 "function doRedirectReplace() {" +
100 "location.replace('" + url + "');" + 97 "location.replace('" + url + "');" +
101 "} " + 98 "} " +
102 "</script>", 99 "</script>",
103 String.format("<iframe onLoad=\"setTimeout('doRedirect%s()', %d) ;\" />", 100 String.format("<iframe onLoad=\"setTimeout('doRedirect%s()', %d) ;\" />",
104 method, timeout)); 101 method, timeout));
105 } 102 }
106 103
107 private String getHtmlForPageWithSimplePostFormTo(String destination) {
108 return makeHtmlPageFrom("",
109 "<form action=\"" + destination + "\" method=\"post\">" +
110 "<input type=\"submit\" value=\"post\" id=\"link\">" +
111 "</form>");
112 }
113
114 private String addPageToTestServer(TestWebServer webServer, String httpPath, String html) { 104 private String addPageToTestServer(TestWebServer webServer, String httpPath, String html) {
115 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>> (); 105 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>> ();
116 headers.add(Pair.create("Content-Type", "text/html")); 106 headers.add(Pair.create("Content-Type", "text/html"));
117 headers.add(Pair.create("Cache-Control", "no-store")); 107 headers.add(Pair.create("Cache-Control", "no-store"));
118 return webServer.setResponse(httpPath, html, headers); 108 return webServer.setResponse(httpPath, html, headers);
119 } 109 }
120 110
121 private String createRedirectTargetPage(TestWebServer webServer) { 111 private String createRedirectTargetPage(TestWebServer webServer) {
122 return addPageToTestServer(webServer, REDIRECT_TARGET_PATH, 112 return addPageToTestServer(webServer, REDIRECT_TARGET_PATH,
123 makeHtmlPageFrom("", "<div>This is the end of the redirect chain </div>")); 113 makeHtmlPageFrom("", "<div>This is the end of the redirect chain </div>"));
124 } 114 }
125 115
126 @SmallTest 116 @SmallTest
127 @Feature({"AndroidWebView", "Navigation"}) 117 @Feature({"AndroidWebView", "Navigation"})
128 public void testNotCalledOnLoadUrl() throws Throwable { 118 public void testNotCalledOnLoadUrl() throws Throwable {
129 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 119 final TestAwContentsClient contentsClient = new TestAwContentsClient();
130 final AwTestContainerView testContainerView = 120 final AwTestContainerView testContainerView =
131 createAwTestContainerViewOnMainSync(contentsClient); 121 createAwTestContainerViewOnMainSync(contentsClient);
132 final AwContents awContents = testContainerView.getAwContents(); 122 final AwContents awContents = testContainerView.getAwContents();
133 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 123 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
134 contentsClient.getShouldOverrideUrlLoadingHelper(); 124 contentsClient.getShouldOverrideUrlLoadingHelper();
135 125
136 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 126 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
137 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); 127 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false);
138 128
139 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); 129 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount());
140 } 130 }
141 131
142 private void waitForNavigationRunnableAndAssertTitleChanged(AwContents awCon tents, 132 private void waitForNavigationRunnableAndAssertTitleChanged(AwContents awCon tents,
143 CallbackHelper onPageFinishedHelper, 133 CallbackHelper onPageFinishedHelper,
144 Runnable navigationRunnable) throws Exception { 134 Runnable navigationRunnable) throws Exception {
145 final int callCount = onPageFinishedHelper.getCallCount(); 135 final int callCount = onPageFinishedHelper.getCallCount();
146 final String oldTitle = getTitleOnUiThread(awContents); 136 final String oldTitle = getTitleOnUiThread(awContents);
147 getInstrumentation().runOnMainSync(navigationRunnable); 137 getInstrumentation().runOnMainSync(navigationRunnable);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 200 final TestAwContentsClient contentsClient = new TestAwContentsClient();
211 final AwTestContainerView testContainerView = 201 final AwTestContainerView testContainerView =
212 createAwTestContainerViewOnMainSync(contentsClient); 202 createAwTestContainerViewOnMainSync(contentsClient);
213 final AwContents awContents = testContainerView.getAwContents(); 203 final AwContents awContents = testContainerView.getAwContents();
214 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 204 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
215 contentsClient.getShouldOverrideUrlLoadingHelper(); 205 contentsClient.getShouldOverrideUrlLoadingHelper();
216 206
217 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true); 207 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true);
218 208
219 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 209 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
220 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); 210 CommonResources.makeHtmlPageWithSimpleLinkTo(getTestPageCommonHe aders(),
211 DATA_URL), "text/html", false);
221 212
222 assertEquals(TITLE, getTitleOnUiThread(awContents)); 213 assertEquals(TITLE, getTitleOnUiThread(awContents));
223 } 214 }
224 215
225 @SmallTest 216 @SmallTest
226 @Feature({"AndroidWebView", "Navigation"}) 217 @Feature({"AndroidWebView", "Navigation"})
227 public void testCalledBeforeOnPageStarted() throws Throwable { 218 public void testCalledBeforeOnPageStarted() throws Throwable {
228 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 219 final TestAwContentsClient contentsClient = new TestAwContentsClient();
229 final AwTestContainerView testContainerView = 220 final AwTestContainerView testContainerView =
230 createAwTestContainerViewOnMainSync(contentsClient); 221 createAwTestContainerViewOnMainSync(contentsClient);
231 final AwContents awContents = testContainerView.getAwContents(); 222 final AwContents awContents = testContainerView.getAwContents();
232 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 223 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
233 contentsClient.getShouldOverrideUrlLoadingHelper(); 224 contentsClient.getShouldOverrideUrlLoadingHelper();
234 OnPageStartedHelper onPageStartedHelper = contentsClient.getOnPageStarte dHelper(); 225 OnPageStartedHelper onPageStartedHelper = contentsClient.getOnPageStarte dHelper();
235 226
236 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 227 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
237 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); 228 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false);
238 229
239 final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHe lper.getCallCount(); 230 final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHe lper.getCallCount();
240 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); 231 final int onPageStartedCallCount = onPageStartedHelper.getCallCount();
241 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true); 232 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true);
242 clickOnLinkUsingJs(awContents, contentsClient); 233 clickOnLinkUsingJs(awContents, contentsClient);
243 234
244 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount); 235 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount);
245 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount()) ; 236 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount()) ;
246 } 237 }
247 238
248 239
249 @SmallTest 240 @SmallTest
250 @Feature({"AndroidWebView", "Navigation"}) 241 @Feature({"AndroidWebView", "Navigation"})
251 public void testDoesNotCauseOnReceivedError() throws Throwable { 242 public void testDoesNotCauseOnReceivedError() throws Throwable {
252 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 243 final TestAwContentsClient contentsClient = new TestAwContentsClient();
253 final AwTestContainerView testContainerView = 244 final AwTestContainerView testContainerView =
254 createAwTestContainerViewOnMainSync(contentsClient); 245 createAwTestContainerViewOnMainSync(contentsClient);
255 final AwContents awContents = testContainerView.getAwContents(); 246 final AwContents awContents = testContainerView.getAwContents();
256 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper = 247 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper =
257 contentsClient.getShouldOverrideUrlLoadingHelper(); 248 contentsClient.getShouldOverrideUrlLoadingHelper();
258 OnReceivedErrorHelper onReceivedErrorHelper = contentsClient.getOnReceiv edErrorHelper(); 249 OnReceivedErrorHelper onReceivedErrorHelper = contentsClient.getOnReceiv edErrorHelper();
259 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount( ); 250 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount( );
260 251
261 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 252 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
262 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); 253 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false);
263 254
264 final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHe lper.getCallCount(); 255 final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHe lper.getCallCount();
265 256
266 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true); 257 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true);
267 258
268 clickOnLinkUsingJs(awContents, contentsClient); 259 clickOnLinkUsingJs(awContents, contentsClient);
269 260
270 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount); 261 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount);
271 262
272 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, false); 263 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, false);
(...skipping 21 matching lines...) Expand all
294 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 285 final TestAwContentsClient contentsClient = new TestAwContentsClient();
295 final AwTestContainerView testContainerView = 286 final AwTestContainerView testContainerView =
296 createAwTestContainerViewOnMainSync(contentsClient); 287 createAwTestContainerViewOnMainSync(contentsClient);
297 final AwContents awContents = testContainerView.getAwContents(); 288 final AwContents awContents = testContainerView.getAwContents();
298 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper = 289 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper =
299 contentsClient.getShouldOverrideUrlLoadingHelper(); 290 contentsClient.getShouldOverrideUrlLoadingHelper();
300 291
301 final String anchorLinkPath = "/anchor_link.html"; 292 final String anchorLinkPath = "/anchor_link.html";
302 final String anchorLinkUrl = mWebServer.getResponseUrl(anchorLinkPath); 293 final String anchorLinkUrl = mWebServer.getResponseUrl(anchorLinkPath);
303 addPageToTestServer(mWebServer, anchorLinkPath, 294 addPageToTestServer(mWebServer, anchorLinkPath,
304 getHtmlForPageWithSimpleLinkTo(anchorLinkUrl + "#anchor")); 295 CommonResources.makeHtmlPageWithSimpleLinkTo(anchorLinkUrl + "#a nchor"));
305 296
306 if (useLoadData) { 297 if (useLoadData) {
307 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 298 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
308 getHtmlForPageWithSimpleLinkTo("#anchor"), "text/html", fals e); 299 CommonResources.makeHtmlPageWithSimpleLinkTo("#anchor"), "te xt/html", false);
309 } else { 300 } else {
310 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), an chorLinkUrl); 301 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), an chorLinkUrl);
311 } 302 }
312 303
313 final int shouldOverrideUrlLoadingCallCount = 304 final int shouldOverrideUrlLoadingCallCount =
314 shouldOverrideUrlLoadingHelper.getCallCount(); 305 shouldOverrideUrlLoadingHelper.getCallCount();
315 306
316 clickOnLinkUsingJs(awContents, contentsClient); 307 clickOnLinkUsingJs(awContents, contentsClient);
317 308
318 // After we load this URL we're certain that any in-flight callbacks for the previous 309 // After we load this URL we're certain that any in-flight callbacks for the previous
319 // navigation have been delivered. 310 // navigation have been delivered.
320 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), ABOUT_ BLANK_URL); 311 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), ABOUT_ BLANK_URL);
321 312
322 assertEquals(shouldOverrideUrlLoadingCallCount, 313 assertEquals(shouldOverrideUrlLoadingCallCount,
323 shouldOverrideUrlLoadingHelper.getCallCount()); 314 shouldOverrideUrlLoadingHelper.getCallCount());
324 } 315 }
325 316
326 @SmallTest 317 @SmallTest
327 @Feature({"AndroidWebView", "Navigation"}) 318 @Feature({"AndroidWebView", "Navigation"})
328 public void testCalledWhenLinkClicked() throws Throwable { 319 public void testCalledWhenLinkClicked() throws Throwable {
329 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 320 final TestAwContentsClient contentsClient = new TestAwContentsClient();
330 final AwTestContainerView testContainerView = 321 final AwTestContainerView testContainerView =
331 createAwTestContainerViewOnMainSync(contentsClient); 322 createAwTestContainerViewOnMainSync(contentsClient);
332 final AwContents awContents = testContainerView.getAwContents(); 323 final AwContents awContents = testContainerView.getAwContents();
333 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 324 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
334 contentsClient.getShouldOverrideUrlLoadingHelper(); 325 contentsClient.getShouldOverrideUrlLoadingHelper();
335 326
336 // We can't go to about:blank from here because we'd get a cross-origin error. 327 // We can't go to about:blank from here because we'd get a cross-origin error.
337 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 328 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
338 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); 329 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false);
339 330
340 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 331 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
341 332
342 clickOnLinkUsingJs(awContents, contentsClient); 333 clickOnLinkUsingJs(awContents, contentsClient);
343 334
344 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 335 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
345 } 336 }
346 337
347 @SmallTest 338 @SmallTest
348 @Feature({"AndroidWebView", "Navigation"}) 339 @Feature({"AndroidWebView", "Navigation"})
349 public void testCalledWhenTopLevelAboutBlankNavigation() throws Throwable { 340 public void testCalledWhenTopLevelAboutBlankNavigation() throws Throwable {
350 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 341 final TestAwContentsClient contentsClient = new TestAwContentsClient();
351 final AwTestContainerView testContainerView = 342 final AwTestContainerView testContainerView =
352 createAwTestContainerViewOnMainSync(contentsClient); 343 createAwTestContainerViewOnMainSync(contentsClient);
353 final AwContents awContents = testContainerView.getAwContents(); 344 final AwContents awContents = testContainerView.getAwContents();
354 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 345 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
355 contentsClient.getShouldOverrideUrlLoadingHelper(); 346 contentsClient.getShouldOverrideUrlLoadingHelper();
356 347
357 final String httpPath = "/page_with_about_blank_navigation"; 348 final String httpPath = "/page_with_about_blank_navigation";
358 final String httpPathOnServer = mWebServer.getResponseUrl(httpPath); 349 final String httpPathOnServer = mWebServer.getResponseUrl(httpPath);
359 addPageToTestServer(mWebServer, httpPath, 350 addPageToTestServer(mWebServer, httpPath,
360 getHtmlForPageWithSimpleLinkTo(ABOUT_BLANK_URL)); 351 CommonResources.makeHtmlPageWithSimpleLinkTo(ABOUT_BLANK_URL));
361 352
362 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), 353 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
363 httpPathOnServer); 354 httpPathOnServer);
364 355
365 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 356 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
366 357
367 clickOnLinkUsingJs(awContents, contentsClient); 358 clickOnLinkUsingJs(awContents, contentsClient);
368 359
369 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 360 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
370 assertEquals(ABOUT_BLANK_URL, 361 assertEquals(ABOUT_BLANK_URL,
371 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ; 362 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ;
372 } 363 }
373 364
374 @SmallTest 365 @SmallTest
375 @Feature({"AndroidWebView", "Navigation"}) 366 @Feature({"AndroidWebView", "Navigation"})
376 public void testCalledWhenSelfLinkClicked() throws Throwable { 367 public void testCalledWhenSelfLinkClicked() throws Throwable {
377 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 368 final TestAwContentsClient contentsClient = new TestAwContentsClient();
378 final AwTestContainerView testContainerView = 369 final AwTestContainerView testContainerView =
379 createAwTestContainerViewOnMainSync(contentsClient); 370 createAwTestContainerViewOnMainSync(contentsClient);
380 final AwContents awContents = testContainerView.getAwContents(); 371 final AwContents awContents = testContainerView.getAwContents();
381 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 372 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
382 contentsClient.getShouldOverrideUrlLoadingHelper(); 373 contentsClient.getShouldOverrideUrlLoadingHelper();
383 374
384 final String httpPath = "/page_with_link_to_self.html"; 375 final String httpPath = "/page_with_link_to_self.html";
385 final String httpPathOnServer = mWebServer.getResponseUrl(httpPath); 376 final String httpPathOnServer = mWebServer.getResponseUrl(httpPath);
386 addPageToTestServer(mWebServer, httpPath, 377 addPageToTestServer(mWebServer, httpPath,
387 getHtmlForPageWithSimpleLinkTo(httpPathOnServer)); 378 CommonResources.makeHtmlPageWithSimpleLinkTo(httpPathOnServer));
388 379
389 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), 380 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
390 httpPathOnServer); 381 httpPathOnServer);
391 382
392 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 383 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
393 384
394 clickOnLinkUsingJs(awContents, contentsClient); 385 clickOnLinkUsingJs(awContents, contentsClient);
395 386
396 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 387 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
397 assertEquals(httpPathOnServer, 388 assertEquals(httpPathOnServer,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 public void testPassesCorrectUrl() throws Throwable { 438 public void testPassesCorrectUrl() throws Throwable {
448 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 439 final TestAwContentsClient contentsClient = new TestAwContentsClient();
449 final AwTestContainerView testContainerView = 440 final AwTestContainerView testContainerView =
450 createAwTestContainerViewOnMainSync(contentsClient); 441 createAwTestContainerViewOnMainSync(contentsClient);
451 final AwContents awContents = testContainerView.getAwContents(); 442 final AwContents awContents = testContainerView.getAwContents();
452 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 443 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
453 contentsClient.getShouldOverrideUrlLoadingHelper(); 444 contentsClient.getShouldOverrideUrlLoadingHelper();
454 445
455 final String redirectTargetUrl = createRedirectTargetPage(mWebServer); 446 final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
456 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 447 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
457 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/html", false); 448 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl), "text/html",
449 false);
458 450
459 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 451 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
460 clickOnLinkUsingJs(awContents, contentsClient); 452 clickOnLinkUsingJs(awContents, contentsClient);
461 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 453 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
462 assertEquals(redirectTargetUrl, 454 assertEquals(redirectTargetUrl,
463 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ; 455 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ;
464 } 456 }
465 457
466 @SmallTest 458 @SmallTest
467 @Feature({"AndroidWebView", "Navigation"}) 459 @Feature({"AndroidWebView", "Navigation"})
468 public void testCanIgnoreLoading() throws Throwable { 460 public void testCanIgnoreLoading() throws Throwable {
469 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 461 final TestAwContentsClient contentsClient = new TestAwContentsClient();
470 final AwTestContainerView testContainerView = 462 final AwTestContainerView testContainerView =
471 createAwTestContainerViewOnMainSync(contentsClient); 463 createAwTestContainerViewOnMainSync(contentsClient);
472 final AwContents awContents = testContainerView.getAwContents(); 464 final AwContents awContents = testContainerView.getAwContents();
473 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper = 465 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper =
474 contentsClient.getShouldOverrideUrlLoadingHelper(); 466 contentsClient.getShouldOverrideUrlLoadingHelper();
475 467
476 final String redirectTargetUrl = createRedirectTargetPage(mWebServer); 468 final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
477 final String pageWithLinkToIgnorePath = "/page_with_link_to_ignore.html" ; 469 final String pageWithLinkToIgnorePath = "/page_with_link_to_ignore.html" ;
478 final String pageWithLinkToIgnoreUrl = addPageToTestServer(mWebServer, 470 final String pageWithLinkToIgnoreUrl = addPageToTestServer(mWebServer,
479 pageWithLinkToIgnorePath, 471 pageWithLinkToIgnorePath,
480 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl)); 472 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl)) ;
481 final String synchronizationPath = "/sync.html"; 473 final String synchronizationPath = "/sync.html";
482 final String synchronizationUrl = addPageToTestServer(mWebServer, 474 final String synchronizationUrl = addPageToTestServer(mWebServer,
483 synchronizationPath, 475 synchronizationPath,
484 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl)); 476 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl)) ;
485 477
486 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), 478 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
487 pageWithLinkToIgnoreUrl); 479 pageWithLinkToIgnoreUrl);
488 480
489 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true); 481 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true);
490 482
491 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 483 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
492 clickOnLinkUsingJs(awContents, contentsClient); 484 clickOnLinkUsingJs(awContents, contentsClient);
493 // Some time around here true should be returned from the shouldOverride UrlLoading 485 // Some time around here true should be returned from the shouldOverride UrlLoading
494 // callback causing the navigation caused by calling clickOnLinkUsingJs to be ignored. 486 // callback causing the navigation caused by calling clickOnLinkUsingJs to be ignored.
(...skipping 16 matching lines...) Expand all
511 "data:text/html;base64," + 503 "data:text/html;base64," +
512 "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" + 504 "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" +
513 "L2hlYWQ+PC9odG1sPg=="; 505 "L2hlYWQ+PC9odG1sPg==";
514 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 506 final TestAwContentsClient contentsClient = new TestAwContentsClient();
515 final AwTestContainerView testContainerView = 507 final AwTestContainerView testContainerView =
516 createAwTestContainerViewOnMainSync(contentsClient); 508 createAwTestContainerViewOnMainSync(contentsClient);
517 final AwContents awContents = testContainerView.getAwContents(); 509 final AwContents awContents = testContainerView.getAwContents();
518 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 510 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
519 contentsClient.getShouldOverrideUrlLoadingHelper(); 511 contentsClient.getShouldOverrideUrlLoadingHelper();
520 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 512 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
521 getHtmlForPageWithSimpleLinkTo(dataUrl), "text/html", false); 513 CommonResources.makeHtmlPageWithSimpleLinkTo(dataUrl), "text/htm l", false);
522 514
523 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 515 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
524 clickOnLinkUsingJs(awContents, contentsClient); 516 clickOnLinkUsingJs(awContents, contentsClient);
525 517
526 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 518 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
527 assertTrue("Expected URL that starts with 'data:' but got: <" + 519 assertTrue("Expected URL that starts with 'data:' but got: <" +
528 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl () + "> instead.", 520 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl () + "> instead.",
529 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl ().startsWith( 521 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl ().startsWith(
530 "data:")); 522 "data:"));
531 } 523 }
532 524
533 @SmallTest 525 @SmallTest
534 @Feature({"AndroidWebView", "Navigation"}) 526 @Feature({"AndroidWebView", "Navigation"})
535 public void testCalledForUnsupportedSchemes() throws Throwable { 527 public void testCalledForUnsupportedSchemes() throws Throwable {
536 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 528 final TestAwContentsClient contentsClient = new TestAwContentsClient();
537 final AwTestContainerView testContainerView = 529 final AwTestContainerView testContainerView =
538 createAwTestContainerViewOnMainSync(contentsClient); 530 createAwTestContainerViewOnMainSync(contentsClient);
539 final AwContents awContents = testContainerView.getAwContents(); 531 final AwContents awContents = testContainerView.getAwContents();
540 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 532 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
541 contentsClient.getShouldOverrideUrlLoadingHelper(); 533 contentsClient.getShouldOverrideUrlLoadingHelper();
542 final String unsupportedSchemeUrl = "foobar://resource/1"; 534 final String unsupportedSchemeUrl = "foobar://resource/1";
543 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), 535 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
544 getHtmlForPageWithSimpleLinkTo(unsupportedSchemeUrl), "text/html ", false); 536 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUr l), "text/html",
537 false);
545 538
546 int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); 539 int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
547 clickOnLinkUsingJs(awContents, contentsClient); 540 clickOnLinkUsingJs(awContents, contentsClient);
548 541
549 shouldOverrideUrlLoadingHelper.waitForCallback(callCount); 542 shouldOverrideUrlLoadingHelper.waitForCallback(callCount);
550 assertEquals(unsupportedSchemeUrl, 543 assertEquals(unsupportedSchemeUrl,
551 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ; 544 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ;
552 } 545 }
553 546
554 @SmallTest 547 @SmallTest
555 @Feature({"AndroidWebView", "Navigation"}) 548 @Feature({"AndroidWebView", "Navigation"})
556 public void testNotCalledForPostNavigations() throws Throwable { 549 public void testNotCalledForPostNavigations() throws Throwable {
557 // The reason POST requests are excluded is BUG 155250. 550 // The reason POST requests are excluded is BUG 155250.
558 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 551 final TestAwContentsClient contentsClient = new TestAwContentsClient();
559 final AwTestContainerView testContainerView = 552 final AwTestContainerView testContainerView =
560 createAwTestContainerViewOnMainSync(contentsClient); 553 createAwTestContainerViewOnMainSync(contentsClient);
561 final AwContents awContents = testContainerView.getAwContents(); 554 final AwContents awContents = testContainerView.getAwContents();
562 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper = 555 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper =
563 contentsClient.getShouldOverrideUrlLoadingHelper(); 556 contentsClient.getShouldOverrideUrlLoadingHelper();
564 557
565 final String redirectTargetUrl = createRedirectTargetPage(mWebServer); 558 final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
566 final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_p ost_link.html", 559 final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_p ost_link.html",
567 getHtmlForPageWithSimplePostFormTo(redirectTargetUrl)); 560 CommonResources.makeHtmlPageWithSimplePostFormTo(redirectTargetU rl));
568 561
569 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), postLi nkUrl); 562 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), postLi nkUrl);
570 563
571 final int shouldOverrideUrlLoadingCallCount = 564 final int shouldOverrideUrlLoadingCallCount =
572 shouldOverrideUrlLoadingHelper.getCallCount(); 565 shouldOverrideUrlLoadingHelper.getCallCount();
573 566
574 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); 567 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
575 clickOnLinkUsingJs(awContents, contentsClient); 568 clickOnLinkUsingJs(awContents, contentsClient);
576 569
577 // Wait for the target URL to be fetched from the server. 570 // Wait for the target URL to be fetched from the server.
(...skipping 18 matching lines...) Expand all
596 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 589 final TestAwContentsClient contentsClient = new TestAwContentsClient();
597 final AwTestContainerView testContainerView = 590 final AwTestContainerView testContainerView =
598 createAwTestContainerViewOnMainSync(contentsClient); 591 createAwTestContainerViewOnMainSync(contentsClient);
599 final AwContents awContents = testContainerView.getAwContents(); 592 final AwContents awContents = testContainerView.getAwContents();
600 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper = 593 final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverride UrlLoadingHelper =
601 contentsClient.getShouldOverrideUrlLoadingHelper(); 594 contentsClient.getShouldOverrideUrlLoadingHelper();
602 595
603 final String redirectTargetUrl = createRedirectTargetPage(mWebServer); 596 final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
604 final String postToGetRedirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl); 597 final String postToGetRedirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl);
605 final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_p ost_link.html", 598 final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_p ost_link.html",
606 getHtmlForPageWithSimplePostFormTo(postToGetRedirectUrl)); 599 CommonResources.makeHtmlPageWithSimplePostFormTo(postToGetRedire ctUrl));
607 600
608 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), postLi nkUrl); 601 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), postLi nkUrl);
609 602
610 final int shouldOverrideUrlLoadingCallCount = 603 final int shouldOverrideUrlLoadingCallCount =
611 shouldOverrideUrlLoadingHelper.getCallCount(); 604 shouldOverrideUrlLoadingHelper.getCallCount();
612 605
613 clickOnLinkUsingJs(awContents, contentsClient); 606 clickOnLinkUsingJs(awContents, contentsClient);
614 607
615 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount); 608 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount);
616 609
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 * URL. We expect two callbacks - one for the redirect link and another for the destination. 688 * URL. We expect two callbacks - one for the redirect link and another for the destination.
696 */ 689 */
697 private void doTestCalledOnRedirect(TestWebServer webServer, 690 private void doTestCalledOnRedirect(TestWebServer webServer,
698 String redirectUrl, String redirectTarget) throws Throwable { 691 String redirectUrl, String redirectTarget) throws Throwable {
699 final TestAwContentsClient contentsClient = new TestAwContentsClient(); 692 final TestAwContentsClient contentsClient = new TestAwContentsClient();
700 final AwTestContainerView testContainerView = 693 final AwTestContainerView testContainerView =
701 createAwTestContainerViewOnMainSync(contentsClient); 694 createAwTestContainerViewOnMainSync(contentsClient);
702 final AwContents awContents = testContainerView.getAwContents(); 695 final AwContents awContents = testContainerView.getAwContents();
703 final String pageWithLinkToRedirectUrl = addPageToTestServer(webServer, 696 final String pageWithLinkToRedirectUrl = addPageToTestServer(webServer,
704 "/page_with_link_to_redirect.html", 697 "/page_with_link_to_redirect.html",
705 getHtmlForPageWithSimpleLinkTo(redirectUrl)); 698 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectUrl));
706 enableJavaScriptOnUiThread(awContents); 699 enableJavaScriptOnUiThread(awContents);
707 700
708 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 701 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
709 contentsClient.getShouldOverrideUrlLoadingHelper(); 702 contentsClient.getShouldOverrideUrlLoadingHelper();
710 int directLoadCallCount = shouldOverrideUrlLoadingHelper.getCallCount(); 703 int directLoadCallCount = shouldOverrideUrlLoadingHelper.getCallCount();
711 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), redire ctUrl); 704 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), redire ctUrl);
712 705
713 shouldOverrideUrlLoadingHelper.waitForCallback(directLoadCallCount, 1); 706 shouldOverrideUrlLoadingHelper.waitForCallback(directLoadCallCount, 1);
714 assertEquals(redirectTarget, 707 assertEquals(redirectTarget,
715 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ; 708 shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()) ;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = 799 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper =
807 contentsClient.getShouldOverrideUrlLoadingHelper(); 800 contentsClient.getShouldOverrideUrlLoadingHelper();
808 801
809 // Do a double navigagtion, the second being an effective no-op, in quic k succession (i.e. 802 // Do a double navigagtion, the second being an effective no-op, in quic k succession (i.e.
810 // without yielding the main thread inbetween). 803 // without yielding the main thread inbetween).
811 int currentCallCount = contentsClient.getOnPageFinishedHelper().getCallC ount(); 804 int currentCallCount = contentsClient.getOnPageFinishedHelper().getCallC ount();
812 getInstrumentation().runOnMainSync(new Runnable() { 805 getInstrumentation().runOnMainSync(new Runnable() {
813 @Override 806 @Override
814 public void run() { 807 public void run() {
815 awContents.loadUrl(LoadUrlParams.createLoadDataParams( 808 awContents.loadUrl(LoadUrlParams.createLoadDataParams(
816 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", f alse)); 809 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html",
810 false));
817 awContents.loadUrl(new LoadUrlParams(jsUrl)); 811 awContents.loadUrl(new LoadUrlParams(jsUrl));
818 } 812 }
819 }); 813 });
820 contentsClient.getOnPageFinishedHelper().waitForCallback(currentCallCoun t, 1, 814 contentsClient.getOnPageFinishedHelper().waitForCallback(currentCallCoun t, 1,
821 WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); 815 WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
822 816
823 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); 817 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount());
824 } 818 }
825 } 819 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698