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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 assertEquals(TITLE, getTitleOnUiThread(mAwContents)); | 243 assertEquals(TITLE, getTitleOnUiThread(mAwContents)); |
244 } | 244 } |
245 | 245 |
246 @SmallTest | 246 @SmallTest |
247 @Feature({"AndroidWebView", "Navigation"}) | 247 @Feature({"AndroidWebView", "Navigation"}) |
248 public void testCalledBeforeOnPageStarted() throws Throwable { | 248 public void testCalledBeforeOnPageStarted() throws Throwable { |
249 standardSetup(); | 249 standardSetup(); |
250 OnPageStartedHelper onPageStartedHelper = mContentsClient.getOnPageStart
edHelper(); | 250 OnPageStartedHelper onPageStartedHelper = mContentsClient.getOnPageStart
edHelper(); |
251 | 251 |
252 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 252 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
253 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht
ml", false); | 253 CommonResources.makeHtmlPageWithSimpleLinkTo( |
| 254 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL), |
| 255 "text/html", false); |
254 | 256 |
255 final int shouldOverrideUrlLoadingCallCount = | 257 final int shouldOverrideUrlLoadingCallCount = |
256 mShouldOverrideUrlLoadingHelper.getCallCount(); | 258 mShouldOverrideUrlLoadingHelper.getCallCount(); |
257 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); | 259 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); |
258 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 260 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
259 clickOnLinkUsingJs(); | 261 clickOnLinkUsingJs(); |
260 | 262 |
261 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); | 263 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); |
262 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount())
; | 264 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount())
; |
263 } | 265 } |
264 | 266 |
265 | 267 |
266 @SmallTest | 268 @SmallTest |
267 @Feature({"AndroidWebView", "Navigation"}) | 269 @Feature({"AndroidWebView", "Navigation"}) |
268 public void testDoesNotCauseOnReceivedError() throws Throwable { | 270 public void testDoesNotCauseOnReceivedError() throws Throwable { |
269 standardSetup(); | 271 standardSetup(); |
270 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 272 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
271 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(
); | 273 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(
); |
272 | 274 |
273 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 275 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
274 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht
ml", false); | 276 CommonResources.makeHtmlPageWithSimpleLinkTo( |
| 277 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL), |
| 278 "text/html", false); |
275 | 279 |
276 final int shouldOverrideUrlLoadingCallCount = | 280 final int shouldOverrideUrlLoadingCallCount = |
277 mShouldOverrideUrlLoadingHelper.getCallCount(); | 281 mShouldOverrideUrlLoadingHelper.getCallCount(); |
278 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 282 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
279 clickOnLinkUsingJs(); | 283 clickOnLinkUsingJs(); |
280 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); | 284 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); |
281 setShouldOverrideUrlLoadingReturnValueOnUiThread(false); | 285 setShouldOverrideUrlLoadingReturnValueOnUiThread(false); |
282 | 286 |
283 // After we load this URL we're certain that any in-flight callbacks for
the previous | 287 // After we load this URL we're certain that any in-flight callbacks for
the previous |
284 // navigation have been delivered. | 288 // navigation have been delivered. |
285 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 289 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), DATA
_URL); |
286 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | |
287 | 290 |
288 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun
t()); | 291 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun
t()); |
289 } | 292 } |
290 | 293 |
291 @SmallTest | 294 @SmallTest |
292 @Feature({"AndroidWebView", "Navigation"}) | 295 @Feature({"AndroidWebView", "Navigation"}) |
293 public void testNotCalledForAnchorNavigations() throws Throwable { | 296 public void testNotCalledForAnchorNavigations() throws Throwable { |
294 doTestNotCalledForAnchorNavigations(false); | 297 doTestNotCalledForAnchorNavigations(false); |
295 } | 298 } |
296 | 299 |
(...skipping 30 matching lines...) Expand all Loading... |
327 | 330 |
328 assertEquals(shouldOverrideUrlLoadingCallCount, | 331 assertEquals(shouldOverrideUrlLoadingCallCount, |
329 mShouldOverrideUrlLoadingHelper.getCallCount()); | 332 mShouldOverrideUrlLoadingHelper.getCallCount()); |
330 } | 333 } |
331 | 334 |
332 @SmallTest | 335 @SmallTest |
333 @Feature({"AndroidWebView", "Navigation"}) | 336 @Feature({"AndroidWebView", "Navigation"}) |
334 public void testCalledWhenLinkClicked() throws Throwable { | 337 public void testCalledWhenLinkClicked() throws Throwable { |
335 standardSetup(); | 338 standardSetup(); |
336 | 339 |
337 // We can't go to about:blank from here because we'd get a cross-origin
error. | |
338 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 340 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
339 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht
ml", false); | 341 CommonResources.makeHtmlPageWithSimpleLinkTo( |
| 342 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL), |
| 343 "text/html", false); |
340 | 344 |
341 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | 345 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); |
342 | 346 |
343 clickOnLinkUsingJs(); | 347 clickOnLinkUsingJs(); |
344 | 348 |
345 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); | 349 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); |
346 assertEquals(DATA_URL, mShouldOverrideUrlLoadingHelper.getShouldOverride
UrlLoadingUrl()); | 350 assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, |
| 351 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()
); |
347 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); | 352 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); |
348 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); | 353 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); |
349 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); | 354 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); |
350 } | 355 } |
351 | 356 |
352 /* | 357 /* |
353 @SmallTest | 358 @SmallTest |
354 @Feature({"AndroidWebView", "Navigation"}) | 359 @Feature({"AndroidWebView", "Navigation"}) |
355 */ | 360 */ |
356 @DisabledTest(message = "crbug.com/462306") | 361 @DisabledTest(message = "crbug.com/462306") |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 491 |
487 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), sync
hronizationUrl); | 492 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), sync
hronizationUrl); |
488 | 493 |
489 assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath)); | 494 assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath)); |
490 assertEquals(1, mWebServer.getRequestCount(synchronizationPath)); | 495 assertEquals(1, mWebServer.getRequestCount(synchronizationPath)); |
491 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); | 496 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); |
492 } | 497 } |
493 | 498 |
494 @SmallTest | 499 @SmallTest |
495 @Feature({"AndroidWebView", "Navigation"}) | 500 @Feature({"AndroidWebView", "Navigation"}) |
496 public void testCalledForDataUrl() throws Throwable { | |
497 standardSetup(); | |
498 final String dataUrl = | |
499 "data:text/html;base64," | |
500 + "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90a
XRsZT48" | |
501 + "L2hlYWQ+PC9odG1sPg=="; | |
502 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | |
503 CommonResources.makeHtmlPageWithSimpleLinkTo(dataUrl), "text/htm
l", false); | |
504 | |
505 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | |
506 clickOnLinkUsingJs(); | |
507 | |
508 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); | |
509 assertTrue("Expected URL that starts with 'data:' but got: <" | |
510 + mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl
() + "> instead.", | |
511 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()
.startsWith( | |
512 "data:")); | |
513 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); | |
514 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); | |
515 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); | |
516 } | |
517 | |
518 @SmallTest | |
519 @Feature({"AndroidWebView", "Navigation"}) | |
520 public void testCalledForUnsupportedSchemes() throws Throwable { | 501 public void testCalledForUnsupportedSchemes() throws Throwable { |
521 standardSetup(); | 502 standardSetup(); |
522 final String unsupportedSchemeUrl = "foobar://resource/1"; | 503 final String unsupportedSchemeUrl = "foobar://resource/1"; |
523 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 504 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
524 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUr
l), "text/html", | 505 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUr
l), "text/html", |
525 false); | 506 false); |
526 | 507 |
527 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | 508 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); |
528 clickOnLinkUsingJs(); | 509 clickOnLinkUsingJs(); |
529 | 510 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 } | 826 } |
846 | 827 |
847 mContentsClient = new DestroyInCallbackClient(); | 828 mContentsClient = new DestroyInCallbackClient(); |
848 setupWithProvidedContentsClient(mContentsClient); | 829 setupWithProvidedContentsClient(mContentsClient); |
849 mShouldOverrideUrlLoadingHelper = mContentsClient.getShouldOverrideUrlLo
adingHelper(); | 830 mShouldOverrideUrlLoadingHelper = mContentsClient.getShouldOverrideUrlLo
adingHelper(); |
850 | 831 |
851 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); | 832 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei
vedErrorHelper(); |
852 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); | 833 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); |
853 | 834 |
854 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 835 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
855 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht
ml", false); | 836 CommonResources.makeHtmlPageWithSimpleLinkTo( |
| 837 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL), |
| 838 "text/html", false); |
856 | 839 |
857 int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.
getCallCount(); | 840 int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.
getCallCount(); |
858 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 841 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
859 clickOnLinkUsingJs(); | 842 clickOnLinkUsingJs(); |
860 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); | 843 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading
CallCount); |
861 | 844 |
862 pollUiThread(new Callable<Boolean>() { | 845 pollUiThread(new Callable<Boolean>() { |
863 @Override | 846 @Override |
864 public Boolean call() { | 847 public Boolean call() { |
865 return AwContents.getNativeInstanceCount() == 0; | 848 return AwContents.getNativeInstanceCount() == 0; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 doTestClickableContent(TEST_PHONE, TEST_PHONE_URI, false); | 1102 doTestClickableContent(TEST_PHONE, TEST_PHONE_URI, false); |
1120 } | 1103 } |
1121 | 1104 |
1122 @SmallTest | 1105 @SmallTest |
1123 @Feature({"AndroidWebView"}) | 1106 @Feature({"AndroidWebView"}) |
1124 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) | 1107 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) |
1125 public void testClickableAddressInIframe() throws Throwable { | 1108 public void testClickableAddressInIframe() throws Throwable { |
1126 doTestClickableContent(TEST_ADDRESS, TEST_ADDRESS_URI, false); | 1109 doTestClickableContent(TEST_ADDRESS, TEST_ADDRESS_URI, false); |
1127 } | 1110 } |
1128 } | 1111 } |
OLD | NEW |