Exemplo n.º 1
0
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testAddTimestampToIntent() {
   Intent intent = new Intent();
   assertEquals(-1, IntentHandler.getTimestampFromIntent(intent));
   // Check both before and after to make sure that the returned value is
   // really from {@link SystemClock#elapsedRealtime()}.
   long before = SystemClock.elapsedRealtime();
   IntentHandler.addTimestampToIntent(intent);
   long after = SystemClock.elapsedRealtime();
   assertTrue("Time should be increasing", before <= IntentHandler.getTimestampFromIntent(intent));
   assertTrue("Time should be increasing", IntentHandler.getTimestampFromIntent(intent) <= after);
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
0
 @UiThreadTest
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testRefererUrl_extraHeadersInclReferer() {
   // Check that invalid header specified in EXTRA_HEADERS isn't used.
   Context context = getInstrumentation().getTargetContext();
   Bundle bundle = new Bundle();
   bundle.putString("X-custom-header", "X-custom-value");
   bundle.putString("Referer", GOOGLE_URL);
   Intent headersIntent = new Intent(Intent.ACTION_VIEW);
   headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
   assertEquals(
       "X-custom-header: X-custom-value", IntentHandler.getExtraHeadersFromIntent(headersIntent));
   assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(headersIntent, context));
 }
Exemplo n.º 4
0
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testGeneratedReferrer() {
   Context context = getInstrumentation().getTargetContext();
   String packageName = context.getPackageName();
   String referrer = IntentHandler.constructValidReferrerForAuthority(packageName).getUrl();
   assertEquals("android-app://" + packageName, referrer);
 }
Exemplo n.º 5
0
  @Override
  public void setUp() throws Exception {
    super.setUp();

    CommandLine.init(null);
    loadNativeLibraryAndInitBrowserProcess();
    IntentHandler.setTestIntentsEnabled(false);
    mIntentHandler = new IntentHandler(null, null);
    mIntent = new Intent();
  }
Exemplo n.º 6
0
 @UiThreadTest
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testRefererUrl_extraHeadersOnlyReferer() {
   // Check that invalid header specified in EXTRA_HEADERS isn't used.
   Bundle bundle = new Bundle();
   bundle.putString("Referer", GOOGLE_URL);
   Intent headersIntent = new Intent(Intent.ACTION_VIEW);
   headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
   assertNull(IntentHandler.getExtraHeadersFromIntent(headersIntent, false));
 }
Exemplo n.º 7
0
  private void processUrls(String[] urls, boolean isValid) {
    Vector<String> failedTests = new Vector<String>();

    for (String url : urls) {
      mIntent.setData(Uri.parse(url));
      if (mIntentHandler.intentHasValidUrl(mIntent) != isValid) {
        failedTests.add(url);
      }
    }
    assertTrue(failedTests.toString(), failedTests.isEmpty());
  }
Exemplo n.º 8
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.getReferrerUrlIncludingExtraHeaders(foreignIntent, context));

    // 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.getReferrerUrlIncludingExtraHeaders(appIntent, context));

    // 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.getReferrerUrlIncludingExtraHeaders(nameIntent, context));
  }
Exemplo n.º 9
0
  @SmallTest
  @Feature({"Android-AppBase"})
  public void testRejectedGoogleChromeSchemeUrls() {
    Vector<String> failedTests = new Vector<String>();

    for (String url : REJECTED_GOOGLECHROME_URLS) {
      mIntent.setData(Uri.parse(url));
      if (IntentHandler.getUrlFromIntent(mIntent) != null) {
        failedTests.add(url);
      }
    }
    assertTrue(failedTests.toString(), failedTests.isEmpty());
  }
Exemplo n.º 10
0
 @UiThreadTest
 @MediumTest
 @Feature({"Android-AppBase"})
 public void testGetQueryFromVoiceSearchResultIntent_validVoiceQuery() {
   Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS);
   intent.putStringArrayListExtra(
       RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS,
       CollectionUtil.newArrayList(VOICE_SEARCH_QUERY));
   intent.putStringArrayListExtra(
       RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS,
       CollectionUtil.newArrayList(VOICE_SEARCH_QUERY_URL));
   String query = IntentHandler.getUrlFromVoiceSearchResult(intent);
   assertEquals(VOICE_SEARCH_QUERY_URL, query);
 }
Exemplo n.º 11
0
 @UiThreadTest
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testRefererUrl_extraHeadersInclRefererMultiple() {
   // Check that invalid header specified in EXTRA_HEADERS isn't used.
   Bundle bundle = new Bundle();
   bundle.putString("X-custom-header", "X-custom-value");
   bundle.putString("X-custom-header-2", "X-custom-value-2");
   bundle.putString("Referer", GOOGLE_URL);
   Intent headersIntent = new Intent(Intent.ACTION_VIEW);
   headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
   assertEquals(
       "X-custom-header-2: X-custom-value-2\nX-custom-header: X-custom-value",
       IntentHandler.getExtraHeadersFromIntent(headersIntent, false));
 }
Exemplo n.º 12
0
 @UiThreadTest
 @MediumTest
 @Feature({"Android-AppBase"})
 public void testGetQueryFromVoiceSearchResultIntent_validUrlQuery() {
   Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS);
   intent.putStringArrayListExtra(
       RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS,
       CollectionUtil.newArrayList(VOICE_URL_QUERY));
   intent.putStringArrayListExtra(
       RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS,
       CollectionUtil.newArrayList(VOICE_URL_QUERY_URL));
   String query = IntentHandler.getUrlFromVoiceSearchResult(intent);
   assertTrue(
       String.format(
           "Expected qualified URL: %s, to start " + "with http://www.google.com", query),
       query.indexOf("http://www.google.com") == 0);
 }
Exemplo n.º 13
0
 @SmallTest
 @Feature({"Android-AppBase"})
 public void testNullUrlIntent() {
   mIntent.setData(null);
   assertTrue("Intent with null data should be valid", mIntentHandler.intentHasValidUrl(mIntent));
 }