| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.net.Uri; | 9 import android.net.Uri; |
| 10 import android.os.Bundle; | 10 import android.os.Bundle; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 public void testRefererUrl_extraReferrer() throws Throwable { | 223 public void testRefererUrl_extraReferrer() throws Throwable { |
| 224 mUiThreadTestRule.runOnUiThread(new Runnable() { | 224 mUiThreadTestRule.runOnUiThread(new Runnable() { |
| 225 @Override | 225 @Override |
| 226 public void run() { | 226 public void run() { |
| 227 // Check that EXTRA_REFERRER is not accepted with a random URL. | 227 // Check that EXTRA_REFERRER is not accepted with a random URL. |
| 228 Intent foreignIntent = new Intent(Intent.ACTION_VIEW); | 228 Intent foreignIntent = new Intent(Intent.ACTION_VIEW); |
| 229 foreignIntent.putExtra(Intent.EXTRA_REFERRER, GOOGLE_URL); | 229 foreignIntent.putExtra(Intent.EXTRA_REFERRER, GOOGLE_URL); |
| 230 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHead
ers(foreignIntent)); | 230 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHead
ers(foreignIntent)); |
| 231 | 231 |
| 232 // Check that EXTRA_REFERRER with android-app URL works. | 232 // Check that EXTRA_REFERRER with android-app URL works. |
| 233 final String appUrl = "android-app://com.application/http/www.ap
plication.com"; | 233 String appUrl = "android-app://com.application/http/www.applicat
ion.com"; |
| 234 Intent appIntent = new Intent(Intent.ACTION_VIEW); | 234 Intent appIntent = new Intent(Intent.ACTION_VIEW); |
| 235 appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl)); | 235 appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl)); |
| 236 Assert.assertEquals( | 236 Assert.assertEquals( |
| 237 appUrl, IntentHandler.getReferrerUrlIncludingExtraHeader
s(appIntent)); | 237 appUrl, IntentHandler.getReferrerUrlIncludingExtraHeader
s(appIntent)); |
| 238 | 238 |
| 239 // Check that EXTRA_REFERRER_NAME with android-app works. | 239 // Ditto, with EXTRA_REFERRER_NAME. |
| 240 Intent nameIntent = new Intent(Intent.ACTION_VIEW); | 240 Intent nameIntent = new Intent(Intent.ACTION_VIEW); |
| 241 nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl); | 241 nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl); |
| 242 Assert.assertEquals( | 242 Assert.assertEquals( |
| 243 appUrl, IntentHandler.getReferrerUrlIncludingExtraHeader
s(nameIntent)); | 243 appUrl, IntentHandler.getReferrerUrlIncludingExtraHeader
s(nameIntent)); |
| 244 |
| 245 // Check that EXTRA_REFERRER with an empty host android-app URL
doesn't work. |
| 246 appUrl = "android-app:///www.application.com"; |
| 247 appIntent = new Intent(Intent.ACTION_VIEW); |
| 248 appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl)); |
| 249 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHead
ers(appIntent)); |
| 250 |
| 251 // Ditto, with EXTRA_REFERRER_NAME. |
| 252 nameIntent = new Intent(Intent.ACTION_VIEW); |
| 253 nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl); |
| 254 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHead
ers(nameIntent)); |
| 244 } | 255 } |
| 245 }); | 256 }); |
| 246 } | 257 } |
| 247 | 258 |
| 248 @Test | 259 @Test |
| 249 @SmallTest | 260 @SmallTest |
| 250 @Feature({"Android-AppBase"}) | 261 @Feature({"Android-AppBase"}) |
| 251 public void testRefererUrl_extraHeadersInclReferer() throws Throwable { | 262 public void testRefererUrl_extraHeadersInclReferer() throws Throwable { |
| 252 mUiThreadTestRule.runOnUiThread(new Runnable() { | 263 mUiThreadTestRule.runOnUiThread(new Runnable() { |
| 253 @Override | 264 @Override |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 @Test | 374 @Test |
| 364 @SmallTest | 375 @SmallTest |
| 365 @Feature({"Android-AppBase"}) | 376 @Feature({"Android-AppBase"}) |
| 366 public void testGeneratedReferrer() { | 377 public void testGeneratedReferrer() { |
| 367 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); | 378 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); |
| 368 String packageName = context.getPackageName(); | 379 String packageName = context.getPackageName(); |
| 369 String referrer = IntentHandler.constructValidReferrerForAuthority(packa
geName).getUrl(); | 380 String referrer = IntentHandler.constructValidReferrerForAuthority(packa
geName).getUrl(); |
| 370 Assert.assertEquals("android-app://" + packageName, referrer); | 381 Assert.assertEquals("android-app://" + packageName, referrer); |
| 371 } | 382 } |
| 372 } | 383 } |
| OLD | NEW |