@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");
      }
    }
  }