@SmallTest
  public void testCanExternalAppHandleUrl() {
    mDelegate.setCanResolveActivity(true);
    assertTrue(mUrlHandler.canExternalAppHandleUrl("some_app://some_app.com/"));

    mDelegate.setCanResolveActivity(false);
    assertTrue(mUrlHandler.canExternalAppHandleUrl("wtai://wp/mc;0123456789"));
    assertTrue(
        mUrlHandler.canExternalAppHandleUrl(
            "intent:/#Intent;scheme=no_app;package=com.no_app;end"));
    assertFalse(mUrlHandler.canExternalAppHandleUrl("no_app://no_app.com/"));
  }
 @SmallTest
 public void testCreatesIntentsToOpenInNewTab() {
   mUrlHandler = new ExternalNavigationHandler(mDelegate);
   ExternalNavigationParams params =
       new ExternalNavigationParams.Builder("http://m.youtube.com", false)
           .setOpenInNewTab(true)
           .build();
   OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(params);
   assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, result);
   assertTrue(mDelegate.startActivityIntent != null);
   assertTrue(mDelegate.startActivityIntent.getBooleanExtra(Browser.EXTRA_CREATE_NEW_TAB, false));
 }
  public void check(
      String url,
      String referrerUrl,
      boolean isIncognito,
      int pageTransition,
      int isRedirect,
      boolean chromeAppInForegroundRequired,
      boolean isBackgroundTabNavigation,
      TabRedirectHandler redirectHandler,
      OverrideUrlLoadingResult expectedOverrideResult,
      int otherExpectation) {
    boolean expectStartIncognito = (otherExpectation & START_INCOGNITO) != 0;
    boolean expectStartActivity = (otherExpectation & START_ACTIVITY) != 0;
    boolean expectSaneIntent = (otherExpectation & INTENT_SANITIZATION_EXCEPTION) == 0;

    mDelegate.reset();

    ExternalNavigationParams params =
        new ExternalNavigationParams.Builder(
                url, isIncognito, referrerUrl, pageTransition, isRedirect == REDIRECT)
            .setApplicationMustBeInForeground(chromeAppInForegroundRequired)
            .setRedirectHandler(redirectHandler)
            .setIsBackgroundTabNavigation(isBackgroundTabNavigation)
            .setIsMainFrame(true)
            .build();
    OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(params);
    boolean startActivityCalled = mDelegate.startActivityIntent != null;

    assertEquals(expectedOverrideResult, result);
    assertEquals(expectStartIncognito, mDelegate.startIncognitoIntentCalled);
    assertEquals(expectStartActivity, startActivityCalled);

    if (startActivityCalled && expectSaneIntent) {
      checkIntentSanity(mDelegate.startActivityIntent, "Intent");
      if (mDelegate.startActivityIntent.getSelector() != null) {
        checkIntentSanity(mDelegate.startActivityIntent.getSelector(), "Intent's selector");
      }
    }
  }