Ejemplo n.º 1
0
 @UiThreadTest
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testRefererUrl_extraHeadersValidReferrer() {
   Context context = getInstrumentation().getTargetContext();
   String validReferer = "android-app://package/http/url";
   Bundle bundle = new Bundle();
   bundle.putString("Referer", validReferer);
   Intent headersIntent = new Intent(Intent.ACTION_VIEW);
   headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
   assertNull(IntentHandler.getReferrerUrl(headersIntent, context));
   assertEquals(
       "Referer: " + validReferer, IntentHandler.getExtraHeadersFromIntent(headersIntent, false));
 }
Ejemplo n.º 2
0
  @UiThreadTest
  @SmallTest
  @Feature({"Android-AppBase"})
  public void testRefererUrl_extraReferrer() {
    // Check that EXTRA_REFERRER is not accepted with a random URL.
    Context context = getInstrumentation().getTargetContext();
    Intent foreignIntent = new Intent(Intent.ACTION_VIEW);
    foreignIntent.putExtra(Intent.EXTRA_REFERRER, GOOGLE_URL);
    assertNull(IntentHandler.getReferrerUrl(foreignIntent, context));
    assertNull(IntentHandler.getExtraHeadersFromIntent(foreignIntent, true));

    // Check that EXTRA_REFERRER with android-app URL works.
    final String appUrl = "android-app://com.application/http/www.application.com";
    Intent appIntent = new Intent(Intent.ACTION_VIEW);
    appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl));
    assertEquals(appUrl, IntentHandler.getReferrerUrl(appIntent, context));
    assertNull(IntentHandler.getExtraHeadersFromIntent(appIntent, false));

    // Check that EXTRA_REFERRER_NAME with android-app works.
    Intent nameIntent = new Intent(Intent.ACTION_VIEW);
    nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl);
    assertEquals(appUrl, IntentHandler.getReferrerUrl(nameIntent, context));
    assertNull(IntentHandler.getExtraHeadersFromIntent(nameIntent, false));
  }