public void testShouldOverrideUrlLoading_OnPageStarted() {
   try {
     OnPageStartedHelper onPageStartedHelper = mTestHelperBridge.getOnPageStartedHelper();
     ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper =
         mTestHelperBridge.getShouldOverrideUrlLoadingHelper();
     loadDataSync(
         null, CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
     final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
     final int onPageStartedCallCount = onPageStartedHelper.getCallCount();
     mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingReturnValue(true);
     clickOnElementId("link", null);
     mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
     assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount());
   } catch (Exception e) {
     assertTrue(false);
     e.printStackTrace();
   } catch (Throwable e) {
     assertTrue(false);
     e.printStackTrace();
   }
 }
  @SmallTest
  @Feature({"AndroidWebView", "Navigation"})
  public void testCalledBeforeOnPageStarted() throws Throwable {
    standardSetup();
    OnPageStartedHelper onPageStartedHelper = mContentsClient.getOnPageStartedHelper();

    loadDataSync(
        mAwContents,
        mContentsClient.getOnPageFinishedHelper(),
        CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL),
        "text/html",
        false);

    final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
    final int onPageStartedCallCount = onPageStartedHelper.getCallCount();
    setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
    clickOnLinkUsingJs();

    mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
    assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount());
  }
  /** Test that the progress bar only traverses the page a single time per navigation. */
  @Feature({"Android-Toolbar"})
  @MediumTest
  @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
  public void testToolbarTraversesScreenOnce() throws InterruptedException, TimeoutException {

    EmbeddedTestServer testServer =
        EmbeddedTestServer.createAndStartFileServer(
            getInstrumentation().getContext(), Environment.getExternalStorageDirectory());

    final WebContents webContents = getActivity().getActivityTab().getWebContents();

    TestWebContentsObserver observer = new TestWebContentsObserver(webContents);
    // Start and stop load events are carefully tracked; there should be two start-stop pairs
    // that do not overlap.
    OnPageStartedHelper startHelper = observer.getOnPageStartedHelper();
    OnPageFinishedHelper finishHelper = observer.getOnPageFinishedHelper();

    ToolbarProgressBar progressBar = (ToolbarProgressBar) getActivity().findViewById(R.id.progress);

    // Reset progress bar start count in case anything else triggered it.
    progressBar.resetStartCountForTesting();

    // Ensure no load events have occured yet.
    assertEquals(0, startHelper.getCallCount());
    assertEquals(0, finishHelper.getCallCount());

    loadUrl(testServer.getURL(TEST_PAGE));

    // Wait for the initial page to be loaded if it hasn't already.
    if (finishHelper.getCallCount() == 0) {
      finishHelper.waitForCallback(finishHelper.getCallCount(), 1);
    }

    // Exactly one start load and one finish load event should have occured.
    assertEquals(1, startHelper.getCallCount());
    assertEquals(1, finishHelper.getCallCount());

    // Load content in the iframe of the test page to trigger another load.
    JavaScriptUtils.executeJavaScript(webContents, "loadIframeInPage();");

    // A load start will be triggered.
    startHelper.waitForCallback(startHelper.getCallCount(), 1);
    assertEquals(2, startHelper.getCallCount());

    // Wait for the iframe to finish loading.
    finishHelper.waitForCallback(finishHelper.getCallCount(), 1);
    assertEquals(2, finishHelper.getCallCount());

    // Though the page triggered two load events, the progress bar should have only appeared a
    // single time.
    assertEquals(1, progressBar.getStartCountForTesting());
  }
 @Override
 public void onPageStarted(String url) {
   mOnPageStartedHelper.notifyCalled(url);
 }