@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());
  }
  public void testShouldOverrideUrlLoading_OnReceivedError() {
    try {
      String url = "file:///android_asset/does_not_exist.html";
      ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper =
          mTestHelperBridge.getShouldOverrideUrlLoadingHelper();
      OnReceivedErrorHelper onReceivedErrorHelper = mTestHelperBridge.getOnReceivedErrorHelper();
      int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
      int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
      mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingReturnValue(true);
      loadUrlSync(url);
      mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
      assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCount());

      onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
      shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
      mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingReturnValue(false);
      loadUrlSync(url);
      mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
      assertNotSame(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCount());
    } catch (Exception e) {
      assertTrue(false);
      e.printStackTrace();
    } catch (Throwable e) {
      assertTrue(false);
      e.printStackTrace();
    }
  }
 @SmallTest
 @Feature({"ShouldInterceptLoadRequest"})
 public void testOnReceivedErrorCallback() throws Throwable {
   final OnReceivedErrorHelper onReceivedErrorHelper =
       mTestHelperBridge.getOnReceivedErrorHelper();
   mShouldInterceptLoadRequestHelper.setReturnValue(new WebResourceResponse(null, null, null));
   int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount();
   loadUrlSync("foo://bar");
   onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1);
 }
  @SmallTest
  @Feature({"ShouldInterceptLoadRequest"})
  public void testNullInputStreamCausesErrorForMainFrame() throws Throwable {
    final OnReceivedErrorHelper onReceivedErrorHelper =
        mTestHelperBridge.getOnReceivedErrorHelper();
    mShouldInterceptLoadRequestHelper.setReturnValue(
        new WebResourceResponse("text/html", "UTF-8", null));

    final String aboutPageUrl = addAboutPageToTestServer(mWebServer);
    final int callCount = onReceivedErrorHelper.getCallCount();
    loadUrlAsync(aboutPageUrl);
    onReceivedErrorHelper.waitForCallback(callCount);
    assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_FILENAME));
  }
  @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;
          }
        });
  }
 @SmallTest
 @Feature({"ShouldInterceptLoadRequest"})
 public void testNoOnReceivedErrorCallback() throws Throwable {
   final String imagePath = "/" + CommonResources.FAVICON_FILENAME;
   final String imageUrl =
       mWebServer.setResponseBase64(
           imagePath,
           CommonResources.FAVICON_DATA_BASE64,
           CommonResources.getImagePngHeaders(true));
   final String pageWithImage =
       addPageToTestServer(
           mWebServer,
           "/page_with_image.html",
           CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME));
   final OnReceivedErrorHelper onReceivedErrorHelper =
       mTestHelperBridge.getOnReceivedErrorHelper();
   mShouldInterceptLoadRequestHelper.setReturnValueForUrl(
       imageUrl, new WebResourceResponse(null, null, null));
   int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount();
   loadUrlSync(pageWithImage);
   assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCallCount());
 }
 @Override
 public void onReceivedError(int errorCode, String description, String failingUrl) {
   mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl);
 }