@SmallTest @Feature({"AndroidWebView", "Navigation"}) public void testDoesNotCauseOnReceivedError() throws Throwable { standardSetup(); OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); loadDataSync( mAwContents, mContentsClient.getOnPageFinishedHelper(), CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false); final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount(); setShouldOverrideUrlLoadingReturnValueOnUiThread(true); clickOnLinkUsingJs(); mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); setShouldOverrideUrlLoadingReturnValueOnUiThread(false); // After we load this URL we're certain that any in-flight callbacks for the previous // navigation have been delivered. loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), ABOUT_BLANK_URL); assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCount()); }
@MediumTest @Feature({"AndroidWebView"}) public void testNoErrorOnFailedSubresourceLoad() throws Throwable { TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = mContentsClient.getOnPageFinishedHelper(); int currentCallCount = onPageFinishedHelper.getCallCount(); loadDataAsync( mAwContents, "<html><iframe src=\"http//invalid.url.co/\" /></html>", "text/html", false); onPageFinishedHelper.waitForCallback(currentCallCount); assertEquals(0, onReceivedErrorHelper.getCallCount()); }
@MediumTest @Feature({"AndroidWebView"}) public void testOnReceivedErrorOnInvalidScheme() throws Throwable { TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); String url = "foo://some/resource"; int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); loadUrlAsync(mAwContents, url); onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); assertEquals( ErrorCodeConversionHelper.ERROR_UNSUPPORTED_SCHEME, onReceivedErrorHelper.getErrorCode()); assertEquals(url, onReceivedErrorHelper.getFailingUrl()); assertNotNull(onReceivedErrorHelper.getDescription()); }
@MediumTest @Feature({"AndroidWebView"}) public void testNonExistentAssetUrl() throws Throwable { TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); try { final String url = "file:///android_asset/does_not_exist.html"; int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); useTestResourceContext(); loadUrlAsync(mAwContents, url); onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, onReceivedErrorHelper.getErrorCode()); assertEquals(url, onReceivedErrorHelper.getFailingUrl()); assertNotNull(onReceivedErrorHelper.getDescription()); } finally { resetResourceContext(); } }
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") @SmallTest @Feature({"AndroidWebView"}) public void testCallDestroyInCallback() throws Throwable { class DestroyInCallbackClient extends TestAwContentsClient { @Override public boolean shouldOverrideUrlLoading(AwContentsClient.AwWebResourceRequest request) { mAwContents.destroy(); return super.shouldOverrideUrlLoading(request); } } mContentsClient = new DestroyInCallbackClient(); setupWithProvidedContentsClient(mContentsClient); mShouldOverrideUrlLoadingHelper = mContentsClient.getShouldOverrideUrlLoadingHelper(); OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); loadDataSync( mAwContents, mContentsClient.getOnPageFinishedHelper(), CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false); int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount(); setShouldOverrideUrlLoadingReturnValueOnUiThread(true); clickOnLinkUsingJs(); mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); pollOnUiThread( new Callable<Boolean>() { @Override public Boolean call() { return AwContents.getNativeInstanceCount() == 0; } }); }
@MediumTest @Feature({"AndroidWebView"}) public void testOnReceivedErrorOnInvalidUrl() throws Throwable { TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); String url = "http://man.id.be.really.surprised.if.this.address.existed.blah/"; int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); loadUrlAsync(mAwContents, url); // TODO(boliu): This is spuriously timing out on build bots but cannot // be reproduced locally. Trying a longer timeout value to see if it is // due to value too slow or some other issue. See crbug.com/152033. onReceivedErrorHelper.waitForCallback( onReceivedErrorCallCount, 1 /* numberOfCallsToWaitFor */, 30 /* timeout */, TimeUnit.SECONDS); assertEquals(ErrorCodeConversionHelper.ERROR_HOST_LOOKUP, onReceivedErrorHelper.getErrorCode()); assertEquals(url, onReceivedErrorHelper.getFailingUrl()); assertNotNull(onReceivedErrorHelper.getDescription()); }