Chromium Code Reviews| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 assertEquals(TITLE, getTitleOnUiThread(mAwContents)); | 236 assertEquals(TITLE, getTitleOnUiThread(mAwContents)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 @SmallTest | 239 @SmallTest |
| 240 @Feature({"AndroidWebView", "Navigation"}) | 240 @Feature({"AndroidWebView", "Navigation"}) |
| 241 public void testCalledBeforeOnPageStarted() throws Throwable { | 241 public void testCalledBeforeOnPageStarted() throws Throwable { |
| 242 standardSetup(); | 242 standardSetup(); |
| 243 OnPageStartedHelper onPageStartedHelper = mContentsClient.getOnPageStart edHelper(); | 243 OnPageStartedHelper onPageStartedHelper = mContentsClient.getOnPageStart edHelper(); |
| 244 | 244 |
| 245 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 245 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 246 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false); | 246 CommonResources.makeHtmlPageWithSimpleLinkTo(ABOUT_BLANK_URL), " text/html", false); |
| 247 | 247 |
| 248 final int shouldOverrideUrlLoadingCallCount = | 248 final int shouldOverrideUrlLoadingCallCount = |
| 249 mShouldOverrideUrlLoadingHelper.getCallCount(); | 249 mShouldOverrideUrlLoadingHelper.getCallCount(); |
| 250 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); | 250 final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); |
| 251 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 251 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
| 252 clickOnLinkUsingJs(); | 252 clickOnLinkUsingJs(); |
| 253 | 253 |
| 254 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); | 254 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); |
| 255 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount()) ; | 255 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount()) ; |
| 256 } | 256 } |
| 257 | 257 |
| 258 | 258 |
| 259 @SmallTest | 259 @SmallTest |
| 260 @Feature({"AndroidWebView", "Navigation"}) | 260 @Feature({"AndroidWebView", "Navigation"}) |
| 261 public void testDoesNotCauseOnReceivedError() throws Throwable { | 261 public void testDoesNotCauseOnReceivedError() throws Throwable { |
| 262 standardSetup(); | 262 standardSetup(); |
| 263 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei vedErrorHelper(); | 263 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei vedErrorHelper(); |
| 264 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount( ); | 264 final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount( ); |
| 265 | 265 |
| 266 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 266 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 267 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false); | 267 CommonResources.makeHtmlPageWithSimpleLinkTo(ABOUT_BLANK_URL), " text/html", false); |
| 268 | 268 |
| 269 final int shouldOverrideUrlLoadingCallCount = | 269 final int shouldOverrideUrlLoadingCallCount = |
| 270 mShouldOverrideUrlLoadingHelper.getCallCount(); | 270 mShouldOverrideUrlLoadingHelper.getCallCount(); |
| 271 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 271 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
| 272 clickOnLinkUsingJs(); | 272 clickOnLinkUsingJs(); |
| 273 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); | 273 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); |
| 274 setShouldOverrideUrlLoadingReturnValueOnUiThread(false); | 274 setShouldOverrideUrlLoadingReturnValueOnUiThread(false); |
| 275 | 275 |
| 276 // After we load this URL we're certain that any in-flight callbacks for the previous | 276 // After we load this URL we're certain that any in-flight callbacks for the previous |
| 277 // navigation have been delivered. | 277 // navigation have been delivered. |
| 278 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), ABOU T_BLANK_URL); | 278 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), DATA _URL); |
|
Torne
2017/04/05 15:28:38
Not sure I follow this; why does this change in th
meacer
2017/04/05 17:40:36
The URL in line 267 is navigated by a click, and t
Torne
2017/04/05 18:07:15
Thanks for the explanation; that looks right, we w
| |
| 279 | 279 |
| 280 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun t()); | 280 assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCoun t()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 @SmallTest | 283 @SmallTest |
| 284 @Feature({"AndroidWebView", "Navigation"}) | 284 @Feature({"AndroidWebView", "Navigation"}) |
| 285 public void testNotCalledForAnchorNavigations() throws Throwable { | 285 public void testNotCalledForAnchorNavigations() throws Throwable { |
| 286 doTestNotCalledForAnchorNavigations(false); | 286 doTestNotCalledForAnchorNavigations(false); |
| 287 } | 287 } |
| 288 | 288 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 318 | 318 |
| 319 assertEquals(shouldOverrideUrlLoadingCallCount, | 319 assertEquals(shouldOverrideUrlLoadingCallCount, |
| 320 mShouldOverrideUrlLoadingHelper.getCallCount()); | 320 mShouldOverrideUrlLoadingHelper.getCallCount()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 @SmallTest | 323 @SmallTest |
| 324 @Feature({"AndroidWebView", "Navigation"}) | 324 @Feature({"AndroidWebView", "Navigation"}) |
| 325 public void testCalledWhenLinkClicked() throws Throwable { | 325 public void testCalledWhenLinkClicked() throws Throwable { |
| 326 standardSetup(); | 326 standardSetup(); |
| 327 | 327 |
| 328 // We can't go to about:blank from here because we'd get a cross-origin error. | |
| 329 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 328 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 330 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false); | 329 CommonResources.makeHtmlPageWithSimpleLinkTo(ABOUT_BLANK_URL), " text/html", false); |
| 331 | 330 |
| 332 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | 331 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); |
| 333 | 332 |
| 334 clickOnLinkUsingJs(); | 333 clickOnLinkUsingJs(); |
| 335 | 334 |
| 336 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); | 335 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); |
| 337 assertEquals(DATA_URL, mShouldOverrideUrlLoadingHelper.getShouldOverride UrlLoadingUrl()); | 336 assertEquals( |
| 337 ABOUT_BLANK_URL, mShouldOverrideUrlLoadingHelper.getShouldOverri deUrlLoadingUrl()); | |
| 338 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); | 338 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); |
| 339 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); | 339 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); |
| 340 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); | 340 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); |
| 341 } | 341 } |
| 342 | 342 |
| 343 /* | 343 /* |
| 344 @SmallTest | 344 @SmallTest |
| 345 @Feature({"AndroidWebView", "Navigation"}) | 345 @Feature({"AndroidWebView", "Navigation"}) |
| 346 */ | 346 */ |
| 347 @DisabledTest(message = "crbug.com/462306") | 347 @DisabledTest(message = "crbug.com/462306") |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 476 |
| 477 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), sync hronizationUrl); | 477 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), sync hronizationUrl); |
| 478 | 478 |
| 479 assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath)); | 479 assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath)); |
| 480 assertEquals(1, mWebServer.getRequestCount(synchronizationPath)); | 480 assertEquals(1, mWebServer.getRequestCount(synchronizationPath)); |
| 481 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); | 481 assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); |
| 482 } | 482 } |
| 483 | 483 |
| 484 @SmallTest | 484 @SmallTest |
| 485 @Feature({"AndroidWebView", "Navigation"}) | 485 @Feature({"AndroidWebView", "Navigation"}) |
| 486 public void testCalledForDataUrl() throws Throwable { | |
| 487 standardSetup(); | |
| 488 final String dataUrl = | |
| 489 "data:text/html;base64," | |
| 490 + "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90a XRsZT48" | |
| 491 + "L2hlYWQ+PC9odG1sPg=="; | |
| 492 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | |
| 493 CommonResources.makeHtmlPageWithSimpleLinkTo(dataUrl), "text/htm l", false); | |
| 494 | |
| 495 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | |
| 496 clickOnLinkUsingJs(); | |
| 497 | |
| 498 mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); | |
| 499 assertTrue("Expected URL that starts with 'data:' but got: <" | |
| 500 + mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl () + "> instead.", | |
| 501 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl() .startsWith( | |
| 502 "data:")); | |
| 503 assertFalse(mShouldOverrideUrlLoadingHelper.isRedirect()); | |
| 504 assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); | |
| 505 assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); | |
| 506 } | |
| 507 | |
| 508 @SmallTest | |
| 509 @Feature({"AndroidWebView", "Navigation"}) | |
| 510 public void testCalledForUnsupportedSchemes() throws Throwable { | 486 public void testCalledForUnsupportedSchemes() throws Throwable { |
| 511 standardSetup(); | 487 standardSetup(); |
| 512 final String unsupportedSchemeUrl = "foobar://resource/1"; | 488 final String unsupportedSchemeUrl = "foobar://resource/1"; |
| 513 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 489 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 514 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUr l), "text/html", | 490 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUr l), "text/html", |
| 515 false); | 491 false); |
| 516 | 492 |
| 517 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); | 493 int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); |
| 518 clickOnLinkUsingJs(); | 494 clickOnLinkUsingJs(); |
| 519 | 495 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 } | 811 } |
| 836 | 812 |
| 837 mContentsClient = new DestroyInCallbackClient(); | 813 mContentsClient = new DestroyInCallbackClient(); |
| 838 setupWithProvidedContentsClient(mContentsClient); | 814 setupWithProvidedContentsClient(mContentsClient); |
| 839 mShouldOverrideUrlLoadingHelper = mContentsClient.getShouldOverrideUrlLo adingHelper(); | 815 mShouldOverrideUrlLoadingHelper = mContentsClient.getShouldOverrideUrlLo adingHelper(); |
| 840 | 816 |
| 841 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei vedErrorHelper(); | 817 OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnRecei vedErrorHelper(); |
| 842 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); | 818 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); |
| 843 | 819 |
| 844 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 820 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 845 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/ht ml", false); | 821 CommonResources.makeHtmlPageWithSimpleLinkTo(ABOUT_BLANK_URL), " text/html", false); |
| 846 | 822 |
| 847 int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper. getCallCount(); | 823 int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper. getCallCount(); |
| 848 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); | 824 setShouldOverrideUrlLoadingReturnValueOnUiThread(true); |
| 849 clickOnLinkUsingJs(); | 825 clickOnLinkUsingJs(); |
| 850 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); | 826 mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoading CallCount); |
| 851 | 827 |
| 852 pollUiThread(new Callable<Boolean>() { | 828 pollUiThread(new Callable<Boolean>() { |
| 853 @Override | 829 @Override |
| 854 public Boolean call() { | 830 public Boolean call() { |
| 855 return AwContents.getNativeInstanceCount() == 0; | 831 return AwContents.getNativeInstanceCount() == 0; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 doTestClickableContent(TEST_PHONE, TEST_PHONE_URI, false); | 1063 doTestClickableContent(TEST_PHONE, TEST_PHONE_URI, false); |
| 1088 } | 1064 } |
| 1089 | 1065 |
| 1090 @SmallTest | 1066 @SmallTest |
| 1091 @Feature({"AndroidWebView"}) | 1067 @Feature({"AndroidWebView"}) |
| 1092 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) | 1068 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) |
| 1093 public void testClickableAddressInIframe() throws Throwable { | 1069 public void testClickableAddressInIframe() throws Throwable { |
| 1094 doTestClickableContent(TEST_ADDRESS, TEST_ADDRESS_URI, false); | 1070 doTestClickableContent(TEST_ADDRESS, TEST_ADDRESS_URI, false); |
| 1095 } | 1071 } |
| 1096 } | 1072 } |
| OLD | NEW |