OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.os.Bundle; | 7 import android.os.Bundle; |
8 import android.os.SystemClock; | 8 import android.os.SystemClock; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 import android.util.Pair; | 10 import android.util.Pair; |
11 import android.view.MotionEvent; | 11 import android.view.MotionEvent; |
12 import android.util.Log; | 12 import android.util.Log; |
13 | 13 |
| 14 import org.chromium.android_webview.AwContents; |
14 import org.chromium.android_webview.test.util.TestWebServer; | 15 import org.chromium.android_webview.test.util.TestWebServer; |
15 import org.chromium.base.test.util.DisabledTest; | 16 import org.chromium.base.test.util.DisabledTest; |
16 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
17 import org.chromium.content.browser.ContentViewCore; | |
18 import org.chromium.content.browser.test.util.CallbackHelper; | 18 import org.chromium.content.browser.test.util.CallbackHelper; |
19 import org.chromium.content.browser.test.util.Criteria; | 19 import org.chromium.content.browser.test.util.Criteria; |
20 import org.chromium.content.browser.test.util.CriteriaHelper; | 20 import org.chromium.content.browser.test.util.CriteriaHelper; |
21 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; | 21 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; |
22 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
StartedHelper; | 22 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
StartedHelper; |
23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; | 23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece
ivedErrorHelper; |
24 | 24 |
25 import java.net.URLEncoder; | 25 import java.net.URLEncoder; |
26 import java.util.ArrayList; | 26 import java.util.ArrayList; |
27 import java.util.List; | 27 import java.util.List; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 public TestAwContentsClient() { | 85 public TestAwContentsClient() { |
86 super(); | 86 super(); |
87 mShouldIgnoreNavigationHelper = new ShouldIgnoreNavigationHelper(); | 87 mShouldIgnoreNavigationHelper = new ShouldIgnoreNavigationHelper(); |
88 } | 88 } |
89 | 89 |
90 public ShouldIgnoreNavigationHelper getShouldIgnoreNavigationHelper() { | 90 public ShouldIgnoreNavigationHelper getShouldIgnoreNavigationHelper() { |
91 return mShouldIgnoreNavigationHelper; | 91 return mShouldIgnoreNavigationHelper; |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 private void clickOnLinkUsingJs(final ContentViewCore contentViewCore, | 95 private void clickOnLinkUsingJs(final AwContents awContents, |
96 final TestAwContentsClient contentsClient) throws Throwable { | 96 final TestAwContentsClient contentsClient) throws Throwable { |
97 enableJavaScriptOnUiThread(contentViewCore); | 97 enableJavaScriptOnUiThread(awContents); |
98 | 98 |
99 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 99 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
100 @Override | 100 @Override |
101 public boolean isSatisfied() { | 101 public boolean isSatisfied() { |
102 try { | 102 try { |
103 String linkIsNotNull = executeJavaScriptAndWaitForResult(con
tentViewCore, | 103 String linkIsNotNull = executeJavaScriptAndWaitForResult(awC
ontents, |
104 contentsClient, "document.getElementById('link') != null
"); | 104 contentsClient, "document.getElementById('link') != null
"); |
105 return linkIsNotNull.equals("true"); | 105 return linkIsNotNull.equals("true"); |
106 } catch (Throwable t) { | 106 } catch (Throwable t) { |
107 t.printStackTrace(); | 107 t.printStackTrace(); |
108 fail("Failed to check if DOM is loaded: " + t.toString()); | 108 fail("Failed to check if DOM is loaded: " + t.toString()); |
109 return false; | 109 return false; |
110 } | 110 } |
111 } | 111 } |
112 }, WAIT_TIMEOUT_SECONDS * 1000, CHECK_INTERVAL)); | 112 }, WAIT_TIMEOUT_SECONDS * 1000, CHECK_INTERVAL)); |
113 | 113 |
114 runTestOnUiThread(new Runnable() { | 114 runTestOnUiThread(new Runnable() { |
115 @Override | 115 @Override |
116 public void run() { | 116 public void run() { |
117 contentViewCore.evaluateJavaScript( | 117 awContents.getContentViewCore().evaluateJavaScript( |
118 "var evObj = document.createEvent('Events'); " + | 118 "var evObj = document.createEvent('Events'); " + |
119 "evObj.initEvent('click', true, false); " + | 119 "evObj.initEvent('click', true, false); " + |
120 "document.getElementById('link').dispatchEvent(evObj);" + | 120 "document.getElementById('link').dispatchEvent(evObj);" + |
121 "console.log('element with id link clicked');"); | 121 "console.log('element with id link clicked');"); |
122 } | 122 } |
123 }); | 123 }); |
124 } | 124 } |
125 | 125 |
126 // Since this value is read on the UI thread, it's simpler to set it there t
oo. | 126 // Since this value is read on the UI thread, it's simpler to set it there t
oo. |
127 void setShouldIgnoreNavigationReturnValueOnUiThread( | 127 void setShouldIgnoreNavigationReturnValueOnUiThread( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 202 } |
203 | 203 |
204 /** | 204 /** |
205 * @SmallTest | 205 * @SmallTest |
206 * @Feature({"Android-WebView", "Navigation"}) | 206 * @Feature({"Android-WebView", "Navigation"}) |
207 * BUG=154558 | 207 * BUG=154558 |
208 */ | 208 */ |
209 @DisabledTest | 209 @DisabledTest |
210 public void testShouldIgnoreNavigationNotCalledOnLoadUrl() throws Throwable
{ | 210 public void testShouldIgnoreNavigationNotCalledOnLoadUrl() throws Throwable
{ |
211 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 211 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
212 final ContentViewCore contentViewCore = | 212 final AwTestContainerView testContainerView = |
213 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 213 createAwTestContainerViewOnMainSync(contentsClient); |
| 214 final AwContents awContents = testContainerView.getAwContents(); |
214 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 215 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
215 contentsClient.getShouldIgnoreNavigationHelper(); | 216 contentsClient.getShouldIgnoreNavigationHelper(); |
216 | 217 |
217 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 218 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
218 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); | 219 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); |
219 | 220 |
220 assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); | 221 assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); |
221 } | 222 } |
222 | 223 |
223 /** | 224 /** |
224 * @SmallTest | 225 * @SmallTest |
225 * @Feature({"Android-WebView", "Navigation"}) | 226 * @Feature({"Android-WebView", "Navigation"}) |
226 * BUG=154558 | 227 * BUG=154558 |
227 */ | 228 */ |
228 @DisabledTest | 229 @DisabledTest |
229 public void testShouldIgnoreNavigationCantBlockLoads() throws Throwable { | 230 public void testShouldIgnoreNavigationCantBlockLoads() throws Throwable { |
230 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 231 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
231 final ContentViewCore contentViewCore = | 232 final AwTestContainerView testContainerView = |
232 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 233 createAwTestContainerViewOnMainSync(contentsClient); |
| 234 final AwContents awContents = testContainerView.getAwContents(); |
233 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 235 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
234 contentsClient.getShouldIgnoreNavigationHelper(); | 236 contentsClient.getShouldIgnoreNavigationHelper(); |
235 | 237 |
236 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); | 238 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); |
237 | 239 |
238 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 240 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
239 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); | 241 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); |
240 | 242 |
241 assertEquals("Title", getTitleOnUiThread(contentViewCore)); | 243 assertEquals("Title", getTitleOnUiThread(awContents)); |
242 } | 244 } |
243 | 245 |
244 /** | 246 /** |
245 * @SmallTest | 247 * @SmallTest |
246 * @Feature({"Android-WebView", "Navigation"}) | 248 * @Feature({"Android-WebView", "Navigation"}) |
247 * BUG=154292 | 249 * BUG=154292 |
248 */ | 250 */ |
249 @DisabledTest | 251 @DisabledTest |
250 public void testShouldIgnoreNavigationCalledBeforeOnPageStarted() throws Thr
owable { | 252 public void testShouldIgnoreNavigationCalledBeforeOnPageStarted() throws Thr
owable { |
251 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 253 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
252 final ContentViewCore contentViewCore = | 254 final AwTestContainerView testContainerView = |
253 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 255 createAwTestContainerViewOnMainSync(contentsClient); |
| 256 final AwContents awContents = testContainerView.getAwContents(); |
254 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 257 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
255 contentsClient.getShouldIgnoreNavigationHelper(); | 258 contentsClient.getShouldIgnoreNavigationHelper(); |
256 OnPageStartedHelper onPageStartedHelper = contentsClient.getOnPageStarte
dHelper(); | 259 OnPageStartedHelper onPageStartedHelper = contentsClient.getOnPageStarte
dHelper(); |
257 | 260 |
258 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 261 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
259 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); | 262 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); |
260 | 263 |
261 final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper
.getCallCount(); | 264 final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper
.getCallCount(); |
262 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); | 265 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); |
263 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); | 266 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); |
264 clickOnLinkUsingJs(contentViewCore, contentsClient); | 267 clickOnLinkUsingJs(awContents, contentsClient); |
265 | 268 |
266 shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallC
ount); | 269 shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallC
ount); |
267 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount())
; | 270 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount())
; |
268 } | 271 } |
269 | 272 |
270 | 273 |
271 /** | 274 /** |
272 * @SmallTest | 275 * @SmallTest |
273 * @Feature({"Android-WebView", "Navigation"}) | 276 * @Feature({"Android-WebView", "Navigation"}) |
274 * BUG=154292 | 277 * BUG=154292 |
275 */ | 278 */ |
276 @DisabledTest | 279 @DisabledTest |
277 public void testShouldIgnoreNavigationDoesNotCauseOnReceivedError() throws T
hrowable { | 280 public void testShouldIgnoreNavigationDoesNotCauseOnReceivedError() throws T
hrowable { |
278 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 281 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
279 final ContentViewCore contentViewCore = | 282 final AwTestContainerView testContainerView = |
280 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 283 createAwTestContainerViewOnMainSync(contentsClient); |
| 284 final AwContents awContents = testContainerView.getAwContents(); |
281 final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavi
gationHelper = | 285 final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavi
gationHelper = |
282 contentsClient.getShouldIgnoreNavigationHelper(); | 286 contentsClient.getShouldIgnoreNavigationHelper(); |
283 OnReceivedErrorHelper onReceivedErrorHelper = contentsClient.getOnReceiv
edErrorHelper(); | 287 OnReceivedErrorHelper onReceivedErrorHelper = contentsClient.getOnReceiv
edErrorHelper(); |
284 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(
); | 288 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(
); |
285 | 289 |
286 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 290 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
287 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); | 291 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); |
288 | 292 |
289 final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper
.getCallCount(); | 293 final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper
.getCallCount(); |
290 | 294 |
291 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); | 295 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, true); |
292 | 296 |
293 clickOnLinkUsingJs(contentViewCore, contentsClient); | 297 clickOnLinkUsingJs(awContents, contentsClient); |
294 | 298 |
295 shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallC
ount); | 299 shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallC
ount); |
296 | 300 |
297 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, false); | 301 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHel
per, false); |
298 | 302 |
299 // After we load this URL we're certain that any in-flight callbacks for
the previous | 303 // After we load this URL we're certain that any in-flight callbacks for
the previous |
300 // navigation have been delivered. | 304 // navigation have been delivered. |
301 loadUrlSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), A
BOUT_BLANK_URL); | 305 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), ABOUT_
BLANK_URL); |
302 | 306 |
303 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun
t()); | 307 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun
t()); |
304 } | 308 } |
305 | 309 |
306 | 310 |
307 @SmallTest | 311 @SmallTest |
308 @Feature({"Android-WebView", "Navigation"}) | 312 @Feature({"Android-WebView", "Navigation"}) |
309 public void testShouldIgnoreNavigationCalledWhenLinkClicked() throws Throwab
le { | 313 public void testShouldIgnoreNavigationCalledWhenLinkClicked() throws Throwab
le { |
310 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 314 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
311 final ContentViewCore contentViewCore = | 315 final AwTestContainerView testContainerView = |
312 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 316 createAwTestContainerViewOnMainSync(contentsClient); |
| 317 final AwContents awContents = testContainerView.getAwContents(); |
313 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 318 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
314 contentsClient.getShouldIgnoreNavigationHelper(); | 319 contentsClient.getShouldIgnoreNavigationHelper(); |
315 | 320 |
316 // We can't go to about:blank from here because we'd get a cross-origin
error. | 321 // We can't go to about:blank from here because we'd get a cross-origin
error. |
317 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 322 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
318 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); | 323 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); |
319 | 324 |
320 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 325 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
321 | 326 |
322 clickOnLinkUsingJs(contentViewCore, contentsClient); | 327 clickOnLinkUsingJs(awContents, contentsClient); |
323 | 328 |
324 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 329 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
325 } | 330 } |
326 | 331 |
327 | 332 |
328 @SmallTest | 333 @SmallTest |
329 @Feature({"Android-WebView", "Navigation"}) | 334 @Feature({"Android-WebView", "Navigation"}) |
330 public void testShouldIgnoreNavigationCalledWhenSelfLinkClicked() throws Thr
owable { | 335 public void testShouldIgnoreNavigationCalledWhenSelfLinkClicked() throws Thr
owable { |
331 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 336 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
332 final ContentViewCore contentViewCore = | 337 final AwTestContainerView testContainerView = |
333 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 338 createAwTestContainerViewOnMainSync(contentsClient); |
| 339 final AwContents awContents = testContainerView.getAwContents(); |
334 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 340 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
335 contentsClient.getShouldIgnoreNavigationHelper(); | 341 contentsClient.getShouldIgnoreNavigationHelper(); |
336 | 342 |
337 TestWebServer webServer = null; | 343 TestWebServer webServer = null; |
338 try { | 344 try { |
339 // Set up the HTML page. | 345 // Set up the HTML page. |
340 webServer = new TestWebServer(false); | 346 webServer = new TestWebServer(false); |
341 final String httpPath = "/page_with_link_to_self.html"; | 347 final String httpPath = "/page_with_link_to_self.html"; |
342 final String httpPathOnServer = webServer.getResponseUrl(httpPath); | 348 final String httpPathOnServer = webServer.getResponseUrl(httpPath); |
343 addPageToTestServer(webServer, httpPath, | 349 addPageToTestServer(webServer, httpPath, |
344 getHtmlForPageWithSimpleLinkTo(httpPathOnServer)); | 350 getHtmlForPageWithSimpleLinkTo(httpPathOnServer)); |
345 | 351 |
346 loadUrlSync(contentViewCore, contentsClient.getOnPageFinishedHelper(
), | 352 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), |
347 httpPathOnServer); | 353 httpPathOnServer); |
348 | 354 |
349 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 355 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
350 | 356 |
351 clickOnLinkUsingJs(contentViewCore, contentsClient); | 357 clickOnLinkUsingJs(awContents, contentsClient); |
352 | 358 |
353 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 359 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
354 assertEquals(httpPathOnServer, | 360 assertEquals(httpPathOnServer, |
355 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl())
; | 361 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl())
; |
356 } finally { | 362 } finally { |
357 if (webServer != null) webServer.shutdown(); | 363 if (webServer != null) webServer.shutdown(); |
358 } | 364 } |
359 } | 365 } |
360 | 366 |
361 @SmallTest | 367 @SmallTest |
362 @Feature({"Android-WebView", "Navigation"}) | 368 @Feature({"Android-WebView", "Navigation"}) |
363 public void testShouldIgnoreNavigationCalledWhenNavigatingFromJavaScriptUsin
gAssign() | 369 public void testShouldIgnoreNavigationCalledWhenNavigatingFromJavaScriptUsin
gAssign() |
364 throws Throwable { | 370 throws Throwable { |
365 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 371 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
366 final ContentViewCore contentViewCore = | 372 final AwTestContainerView testContainerView = |
367 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 373 createAwTestContainerViewOnMainSync(contentsClient); |
368 enableJavaScriptOnUiThread(contentViewCore); | 374 final AwContents awContents = testContainerView.getAwContents(); |
| 375 enableJavaScriptOnUiThread(awContents); |
369 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 376 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
370 contentsClient.getShouldIgnoreNavigationHelper(); | 377 contentsClient.getShouldIgnoreNavigationHelper(); |
371 | 378 |
372 TestWebServer webServer = null; | 379 TestWebServer webServer = null; |
373 try { | 380 try { |
374 // Set up the HTML page. | 381 // Set up the HTML page. |
375 webServer = new TestWebServer(false); | 382 webServer = new TestWebServer(false); |
376 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; | 383 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; |
377 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper
(), | 384 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
378 getHtmlForPageWithJsAssignLinkTo(redirectTargetUrl), "text/h
tml", false); | 385 getHtmlForPageWithJsAssignLinkTo(redirectTargetUrl), "text/h
tml", false); |
379 | 386 |
380 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 387 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
381 | 388 |
382 clickOnLinkUsingJs(contentViewCore, contentsClient); | 389 clickOnLinkUsingJs(awContents, contentsClient); |
383 | 390 |
384 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 391 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
385 } finally { | 392 } finally { |
386 if (webServer != null) webServer.shutdown(); | 393 if (webServer != null) webServer.shutdown(); |
387 } | 394 } |
388 } | 395 } |
389 | 396 |
390 @SmallTest | 397 @SmallTest |
391 @Feature({"Android-WebView", "Navigation"}) | 398 @Feature({"Android-WebView", "Navigation"}) |
392 public void testShouldIgnoreNavigationCalledWhenNavigatingFromJavaScriptUsin
gReplace() | 399 public void testShouldIgnoreNavigationCalledWhenNavigatingFromJavaScriptUsin
gReplace() |
393 throws Throwable { | 400 throws Throwable { |
394 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 401 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
395 final ContentViewCore contentViewCore = | 402 final AwTestContainerView testContainerView = |
396 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 403 createAwTestContainerViewOnMainSync(contentsClient); |
397 enableJavaScriptOnUiThread(contentViewCore); | 404 final AwContents awContents = testContainerView.getAwContents(); |
| 405 enableJavaScriptOnUiThread(awContents); |
398 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 406 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
399 contentsClient.getShouldIgnoreNavigationHelper(); | 407 contentsClient.getShouldIgnoreNavigationHelper(); |
400 | 408 |
401 TestWebServer webServer = null; | 409 TestWebServer webServer = null; |
402 try { | 410 try { |
403 // Set up the HTML page. | 411 // Set up the HTML page. |
404 webServer = new TestWebServer(false); | 412 webServer = new TestWebServer(false); |
405 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; | 413 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; |
406 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper
(), | 414 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
407 getHtmlForPageWithJsReplaceLinkTo(redirectTargetUrl), "text/
html", false); | 415 getHtmlForPageWithJsReplaceLinkTo(redirectTargetUrl), "text/
html", false); |
408 | 416 |
409 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 417 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
410 clickOnLinkUsingJs(contentViewCore, contentsClient); | 418 clickOnLinkUsingJs(awContents, contentsClient); |
411 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 419 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
412 } finally { | 420 } finally { |
413 if (webServer != null) webServer.shutdown(); | 421 if (webServer != null) webServer.shutdown(); |
414 } | 422 } |
415 } | 423 } |
416 | 424 |
417 @SmallTest | 425 @SmallTest |
418 @Feature({"Android-WebView", "Navigation"}) | 426 @Feature({"Android-WebView", "Navigation"}) |
419 public void testShouldIgnoreNavigationPassesCorrectUrl() throws Throwable { | 427 public void testShouldIgnoreNavigationPassesCorrectUrl() throws Throwable { |
420 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 428 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
421 final ContentViewCore contentViewCore = | 429 final AwTestContainerView testContainerView = |
422 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 430 createAwTestContainerViewOnMainSync(contentsClient); |
| 431 final AwContents awContents = testContainerView.getAwContents(); |
423 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 432 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
424 contentsClient.getShouldIgnoreNavigationHelper(); | 433 contentsClient.getShouldIgnoreNavigationHelper(); |
425 | 434 |
426 TestWebServer webServer = null; | 435 TestWebServer webServer = null; |
427 try { | 436 try { |
428 // Set up the HTML page. | 437 // Set up the HTML page. |
429 webServer = new TestWebServer(false); | 438 webServer = new TestWebServer(false); |
430 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; | 439 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; |
431 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper
(), | 440 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
432 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/htm
l", false); | 441 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/htm
l", false); |
433 | 442 |
434 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 443 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
435 clickOnLinkUsingJs(contentViewCore, contentsClient); | 444 clickOnLinkUsingJs(awContents, contentsClient); |
436 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 445 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
437 assertEquals(redirectTargetUrl, | 446 assertEquals(redirectTargetUrl, |
438 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl())
; | 447 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl())
; |
439 } finally { | 448 } finally { |
440 if (webServer != null) webServer.shutdown(); | 449 if (webServer != null) webServer.shutdown(); |
441 } | 450 } |
442 } | 451 } |
443 | 452 |
444 @SmallTest | 453 @SmallTest |
445 @Feature({"Android-WebView", "Navigation"}) | 454 @Feature({"Android-WebView", "Navigation"}) |
446 public void testShouldIgnoreNavigationCanOverrideLoading() throws Throwable
{ | 455 public void testShouldIgnoreNavigationCanOverrideLoading() throws Throwable
{ |
447 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 456 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
448 final ContentViewCore contentViewCore = | 457 final AwTestContainerView testContainerView = |
449 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 458 createAwTestContainerViewOnMainSync(contentsClient); |
| 459 final AwContents awContents = testContainerView.getAwContents(); |
450 final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavi
gationHelper = | 460 final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavi
gationHelper = |
451 contentsClient.getShouldIgnoreNavigationHelper(); | 461 contentsClient.getShouldIgnoreNavigationHelper(); |
452 | 462 |
453 TestWebServer webServer = null; | 463 TestWebServer webServer = null; |
454 try { | 464 try { |
455 // Set up the HTML page. | 465 // Set up the HTML page. |
456 webServer = new TestWebServer(false); | 466 webServer = new TestWebServer(false); |
457 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; | 467 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; |
458 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper
(), | 468 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
459 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/htm
l", false); | 469 getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/htm
l", false); |
460 | 470 |
461 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigatio
nHelper, true); | 471 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigatio
nHelper, true); |
462 | 472 |
463 OnPageFinishedHelper onPageFinishedHelper = contentsClient.getOnPage
FinishedHelper(); | 473 OnPageFinishedHelper onPageFinishedHelper = contentsClient.getOnPage
FinishedHelper(); |
464 int onPageFinishedCountBeforeClickingOnLink = onPageFinishedHelper.g
etCallCount(); | 474 int onPageFinishedCountBeforeClickingOnLink = onPageFinishedHelper.g
etCallCount(); |
465 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 475 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
466 clickOnLinkUsingJs(contentViewCore, contentsClient); | 476 clickOnLinkUsingJs(awContents, contentsClient); |
467 // Some time around here true should be returned from the shouldIgno
reNavigation | 477 // Some time around here true should be returned from the shouldIgno
reNavigation |
468 // callback causing the navigation caused by calling clickOnLinkUsin
gJs to be ignored. | 478 // callback causing the navigation caused by calling clickOnLinkUsin
gJs to be ignored. |
469 // We validate this by indirectly checking that an onPageFinished ca
llback was not | 479 // We validate this by indirectly checking that an onPageFinished ca
llback was not |
470 // issued after this point. | 480 // issued after this point. |
471 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 481 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
472 | 482 |
473 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigatio
nHelper, false); | 483 setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigatio
nHelper, false); |
474 | 484 |
475 final String synchronizationUrl = ABOUT_BLANK_URL; | 485 final String synchronizationUrl = ABOUT_BLANK_URL; |
476 loadUrlSync(contentViewCore, onPageFinishedHelper, synchronizationUr
l); | 486 loadUrlSync(awContents, onPageFinishedHelper, synchronizationUrl); |
477 | 487 |
478 assertEquals(synchronizationUrl, onPageFinishedHelper.getUrl()); | 488 assertEquals(synchronizationUrl, onPageFinishedHelper.getUrl()); |
479 assertEquals(onPageFinishedHelper.getCallCount(), | 489 assertEquals(onPageFinishedHelper.getCallCount(), |
480 onPageFinishedCountBeforeClickingOnLink + 1); | 490 onPageFinishedCountBeforeClickingOnLink + 1); |
481 } finally { | 491 } finally { |
482 if (webServer != null) webServer.shutdown(); | 492 if (webServer != null) webServer.shutdown(); |
483 } | 493 } |
484 } | 494 } |
485 | 495 |
486 @SmallTest | 496 @SmallTest |
487 @Feature({"Android-WebView", "Navigation"}) | 497 @Feature({"Android-WebView", "Navigation"}) |
488 public void testShouldIgnoreNavigationCalledForDataUrl() throws Throwable { | 498 public void testShouldIgnoreNavigationCalledForDataUrl() throws Throwable { |
489 final String dataUrl = | 499 final String dataUrl = |
490 "data:text/html;base64," + | 500 "data:text/html;base64," + |
491 "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" + | 501 "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" + |
492 "L2hlYWQ+PC9odG1sPg=="; | 502 "L2hlYWQ+PC9odG1sPg=="; |
493 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 503 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
494 final ContentViewCore contentViewCore = | 504 final AwTestContainerView testContainerView = |
495 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 505 createAwTestContainerViewOnMainSync(contentsClient); |
| 506 final AwContents awContents = testContainerView.getAwContents(); |
496 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 507 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
497 contentsClient.getShouldIgnoreNavigationHelper(); | 508 contentsClient.getShouldIgnoreNavigationHelper(); |
498 loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 509 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), |
499 getHtmlForPageWithSimpleLinkTo(dataUrl), "text/html", false); | 510 getHtmlForPageWithSimpleLinkTo(dataUrl), "text/html", false); |
500 | 511 |
501 int callCount = shouldIgnoreNavigationHelper.getCallCount(); | 512 int callCount = shouldIgnoreNavigationHelper.getCallCount(); |
502 clickOnLinkUsingJs(contentViewCore, contentsClient); | 513 clickOnLinkUsingJs(awContents, contentsClient); |
503 | 514 |
504 shouldIgnoreNavigationHelper.waitForCallback(callCount); | 515 shouldIgnoreNavigationHelper.waitForCallback(callCount); |
505 assertTrue("Expected URL that starts with 'data:' but got: <" + | 516 assertTrue("Expected URL that starts with 'data:' but got: <" + |
506 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl() +
"> instead.", | 517 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl() +
"> instead.", |
507 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl().s
tartsWith( | 518 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl().s
tartsWith( |
508 "data:")); | 519 "data:")); |
509 } | 520 } |
510 | 521 |
511 // The +1 comes from the fact that we call shouldIgnoreNavigation for URLs t
hat were passed | 522 // The +1 comes from the fact that we call shouldIgnoreNavigation for URLs t
hat were passed |
512 // to the .loadUrl method. | 523 // to the .loadUrl method. |
513 // See BUG=154558. | 524 // See BUG=154558. |
514 private int adjustForBug154558(int callCount) { | 525 private int adjustForBug154558(int callCount) { |
515 return callCount + 1; | 526 return callCount + 1; |
516 } | 527 } |
517 | 528 |
518 /** | 529 /** |
519 * Worker method for the various redirect tests. | 530 * Worker method for the various redirect tests. |
520 * | 531 * |
521 * Calling this will first load the redirect URL built from redirectFilePath
, query and | 532 * Calling this will first load the redirect URL built from redirectFilePath
, query and |
522 * locationFilePath and assert that we get a override callback for the desti
nation. | 533 * locationFilePath and assert that we get a override callback for the desti
nation. |
523 * The second part of the test loads a page that contains a link which point
s at the redirect | 534 * The second part of the test loads a page that contains a link which point
s at the redirect |
524 * URL. We expect two callbacks - one for the redirect link and another for
the destination. | 535 * URL. We expect two callbacks - one for the redirect link and another for
the destination. |
525 */ | 536 */ |
526 private void doTestShouldIgnoreNavigationCalledOnRedirect(TestWebServer webS
erver, | 537 private void doTestShouldIgnoreNavigationCalledOnRedirect(TestWebServer webS
erver, |
527 String redirectUrl, String redirectTarget) throws Throwable { | 538 String redirectUrl, String redirectTarget) throws Throwable { |
528 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 539 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
529 final ContentViewCore contentViewCore = | 540 final AwTestContainerView testContainerView = |
530 createAwTestContainerViewOnMainSync(contentsClient).getContentViewCo
re(); | 541 createAwTestContainerViewOnMainSync(contentsClient); |
| 542 final AwContents awContents = testContainerView.getAwContents(); |
531 final String pageWithLinkToRedirectUrl = addPageToTestServer(webServer, | 543 final String pageWithLinkToRedirectUrl = addPageToTestServer(webServer, |
532 "/page_with_link_to_redirect.html", | 544 "/page_with_link_to_redirect.html", |
533 getHtmlForPageWithSimpleLinkTo(redirectUrl)); | 545 getHtmlForPageWithSimpleLinkTo(redirectUrl)); |
534 enableJavaScriptOnUiThread(contentViewCore); | 546 enableJavaScriptOnUiThread(awContents); |
535 | 547 |
536 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = | 548 TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigation
Helper = |
537 contentsClient.getShouldIgnoreNavigationHelper(); | 549 contentsClient.getShouldIgnoreNavigationHelper(); |
538 int directLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); | 550 int directLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); |
539 loadUrlSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), r
edirectUrl); | 551 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), redire
ctUrl); |
540 | 552 |
541 shouldIgnoreNavigationHelper.waitForCallback(directLoadCallCount, adjust
ForBug154558(1)); | 553 shouldIgnoreNavigationHelper.waitForCallback(directLoadCallCount, adjust
ForBug154558(1)); |
542 assertEquals(redirectTarget, | 554 assertEquals(redirectTarget, |
543 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); | 555 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); |
544 | 556 |
545 // There is a slight difference between navigations caused by calling lo
ad and navigations | 557 // There is a slight difference between navigations caused by calling lo
ad and navigations |
546 // caused by clicking on a link: | 558 // caused by clicking on a link: |
547 // * when using load the navigation is treated as if it came from the U
RL bar (has the | 559 // * when using load the navigation is treated as if it came from the U
RL bar (has the |
548 // navigation type TYPED and doesn't have the has_user_gesture flag) | 560 // navigation type TYPED and doesn't have the has_user_gesture flag) |
549 // * when clicking on a link the navigation has the LINK type and has_u
ser_gesture is | 561 // * when clicking on a link the navigation has the LINK type and has_u
ser_gesture is |
550 // true. | 562 // true. |
551 // Both of these should yield the same result which is what we're verify
ing here. | 563 // Both of these should yield the same result which is what we're verify
ing here. |
552 int indirectLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); | 564 int indirectLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); |
553 loadUrlSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), | 565 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), |
554 pageWithLinkToRedirectUrl); | 566 pageWithLinkToRedirectUrl); |
555 | 567 |
556 // We waitForCallback here because we call shouldIgnoreNavigation for UR
Ls that were passed | 568 // We waitForCallback here because we call shouldIgnoreNavigation for UR
Ls that were passed |
557 // to the .loadUrl method. See BUG=154558. | 569 // to the .loadUrl method. See BUG=154558. |
558 // Do this when the bug is fixed: | 570 // Do this when the bug is fixed: |
559 // assertEquals(indirectLoadCallCount, shouldIgnoreNavigationHelper.getC
allCount()); | 571 // assertEquals(indirectLoadCallCount, shouldIgnoreNavigationHelper.getC
allCount()); |
560 shouldIgnoreNavigationHelper.waitForCallback(indirectLoadCallCount, 1); | 572 shouldIgnoreNavigationHelper.waitForCallback(indirectLoadCallCount, 1); |
561 | 573 |
562 clickOnLinkUsingJs(contentViewCore, contentsClient); | 574 clickOnLinkUsingJs(awContents, contentsClient); |
563 | 575 |
564 shouldIgnoreNavigationHelper.waitForCallback(indirectLoadCallCount, adju
stForBug154558(2)); | 576 shouldIgnoreNavigationHelper.waitForCallback(indirectLoadCallCount, adju
stForBug154558(2)); |
565 | 577 |
566 assertEquals(redirectTarget, | 578 assertEquals(redirectTarget, |
567 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); | 579 shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); |
568 assertEquals(redirectUrl, | 580 assertEquals(redirectUrl, |
569 shouldIgnoreNavigationHelper.getPreviousShouldIgnoreNavigationUr
l()); | 581 shouldIgnoreNavigationHelper.getPreviousShouldIgnoreNavigationUr
l()); |
570 } | 582 } |
571 | 583 |
572 @SmallTest | 584 @SmallTest |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; | 681 final String redirectTargetUrl = createRedirectTargetPage(webServer)
; |
670 final String redirectUrl = addPageToTestServer(webServer, "/js_delay
ed_replace.html", | 682 final String redirectUrl = addPageToTestServer(webServer, "/js_delay
ed_replace.html", |
671 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Replace",
100)); | 683 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Replace",
100)); |
672 doTestShouldIgnoreNavigationCalledOnRedirect(webServer, redirectUrl, | 684 doTestShouldIgnoreNavigationCalledOnRedirect(webServer, redirectUrl, |
673 redirectTargetUrl); | 685 redirectTargetUrl); |
674 } finally { | 686 } finally { |
675 if (webServer != null) webServer.shutdown(); | 687 if (webServer != null) webServer.shutdown(); |
676 } | 688 } |
677 } | 689 } |
678 } | 690 } |
OLD | NEW |