Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/IntentHandlerTest.java

Issue 2778103002: Alternative: Convert Chrome NativeLibraryTestBase tests example (Closed)
Patch Set: change BUILD.gn Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 static org.chromium.content.browser.test.NativeLibraryTestRule.NativeLibr aryInitializationOption.INIT_BROWSER_PROCESS;
8
7 import android.content.Context; 9 import android.content.Context;
8 import android.content.Intent; 10 import android.content.Intent;
9 import android.net.Uri; 11 import android.net.Uri;
10 import android.os.Bundle; 12 import android.os.Bundle;
11 import android.os.SystemClock; 13 import android.os.SystemClock;
12 import android.provider.Browser; 14 import android.provider.Browser;
13 import android.speech.RecognizerResultsIntent; 15 import android.speech.RecognizerResultsIntent;
16 import android.support.test.InstrumentationRegistry;
17 import android.support.test.annotation.UiThreadTest;
14 import android.support.test.filters.MediumTest; 18 import android.support.test.filters.MediumTest;
15 import android.support.test.filters.SmallTest; 19 import android.support.test.filters.SmallTest;
16 import android.test.UiThreadTest; 20 import android.support.test.rule.UiThreadTestRule;
21
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.RuleChain;
27 import org.junit.runner.RunWith;
17 28
18 import org.chromium.base.CollectionUtil; 29 import org.chromium.base.CollectionUtil;
19 import org.chromium.base.CommandLine; 30 import org.chromium.base.test.BaseJUnit4ClassRunner;
20 import org.chromium.base.test.util.Feature; 31 import org.chromium.base.test.util.Feature;
21 import org.chromium.content.browser.test.NativeLibraryTestBase; 32 import org.chromium.content.browser.test.NativeLibraryTestRule;
22 33
23 import java.util.Vector; 34 import java.util.Vector;
24 35
25 /** 36 /**
26 * Tests for IntentHandler. 37 * Tests for IntentHandler.
27 * TODO(nileshagrawal): Add tests for onNewIntent. 38 * TODO(nileshagrawal): Add tests for onNewIntent.
28 */ 39 */
29 public class IntentHandlerTest extends NativeLibraryTestBase { 40 @RunWith(BaseJUnit4ClassRunner.class)
41 public class IntentHandlerTest {
42 @Rule
43 public RuleChain mAllRules =
44 RuleChain.outerRule(new ChromeTestCommandLineInitRule().shouldSetUp( true))
45 .around(new NativeLibraryTestRule()
46 .setInitOption(INIT_BROWSER_PROCESS)
47 .shouldSetUp(true))
48 .around(new UiThreadTestRule());
49
30 private static final String VOICE_SEARCH_QUERY = "VOICE_QUERY"; 50 private static final String VOICE_SEARCH_QUERY = "VOICE_QUERY";
31 private static final String VOICE_SEARCH_QUERY_URL = "http://www.google.com/ ?q=VOICE_QUERY"; 51 private static final String VOICE_SEARCH_QUERY_URL = "http://www.google.com/ ?q=VOICE_QUERY";
32 52
33 private static final String VOICE_URL_QUERY = "www.google.com"; 53 private static final String VOICE_URL_QUERY = "www.google.com";
34 private static final String VOICE_URL_QUERY_URL = "INVALID_URLZ"; 54 private static final String VOICE_URL_QUERY_URL = "INVALID_URLZ";
35 55
36 private static final String[] ACCEPTED_INTENT_URLS = {"http://www.google.com ", 56 private static final String[] ACCEPTED_INTENT_URLS = {"http://www.google.com ",
37 "http://movies.nytimes.com/movie/review?" 57 "http://movies.nytimes.com/movie/review?"
38 + "res=9405EFDB1E3BE23BBC4153DFB7678382659EDE&partner=Rotten Tomatoes", 58 + "res=9405EFDB1E3BE23BBC4153DFB7678382659EDE&partner=Rotten Tomatoes",
39 "chrome://newtab", "file://foo.txt", "ftp://www.foo.com", "https://w ww.gmail.com", "", 59 "chrome://newtab", "file://foo.txt", "ftp://www.foo.com", "https://w ww.gmail.com", "",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 96
77 private void processUrls(String[] urls, boolean isValid) { 97 private void processUrls(String[] urls, boolean isValid) {
78 Vector<String> failedTests = new Vector<String>(); 98 Vector<String> failedTests = new Vector<String>();
79 99
80 for (String url : urls) { 100 for (String url : urls) {
81 mIntent.setData(Uri.parse(url)); 101 mIntent.setData(Uri.parse(url));
82 if (mIntentHandler.intentHasValidUrl(mIntent) != isValid) { 102 if (mIntentHandler.intentHasValidUrl(mIntent) != isValid) {
83 failedTests.add(url); 103 failedTests.add(url);
84 } 104 }
85 } 105 }
86 assertTrue(failedTests.toString(), failedTests.isEmpty()); 106 Assert.assertTrue(failedTests.toString(), failedTests.isEmpty());
87 } 107 }
88 108
89 @Override 109 @Before
90 public void setUp() throws Exception { 110 public void setUp() throws Exception {
91 super.setUp();
92
93 CommandLine.init(null);
94 loadNativeLibraryAndInitBrowserProcess();
95 IntentHandler.setTestIntentsEnabled(false); 111 IntentHandler.setTestIntentsEnabled(false);
96 mIntentHandler = new IntentHandler(null, null); 112 mIntentHandler = new IntentHandler(null, null);
97 mIntent = new Intent(); 113 mIntent = new Intent();
98 } 114 }
99 115
116 @Test
100 @SmallTest 117 @SmallTest
101 @Feature({"Android-AppBase"}) 118 @Feature({"Android-AppBase"})
102 public void testAcceptedUrls() { 119 public void testAcceptedUrls() {
103 processUrls(ACCEPTED_INTENT_URLS, true); 120 processUrls(ACCEPTED_INTENT_URLS, true);
104 } 121 }
105 122
123 @Test
106 @SmallTest 124 @SmallTest
107 @Feature({"Android-AppBase"}) 125 @Feature({"Android-AppBase"})
108 public void testRejectedUrls() { 126 public void testRejectedUrls() {
109 processUrls(REJECTED_INTENT_URLS, false); 127 processUrls(REJECTED_INTENT_URLS, false);
110 } 128 }
111 129
130 @Test
112 @SmallTest 131 @SmallTest
113 @Feature({"Android-AppBase"}) 132 @Feature({"Android-AppBase"})
114 public void testAcceptedGoogleChromeSchemeNavigateUrls() { 133 public void testAcceptedGoogleChromeSchemeNavigateUrls() {
115 // Test all of the accepted URLs after prepending googlechrome://navigat e?url. 134 // Test all of the accepted URLs after prepending googlechrome://navigat e?url.
116 String[] expectedAccepts = new String[ACCEPTED_INTENT_URLS.length]; 135 String[] expectedAccepts = new String[ACCEPTED_INTENT_URLS.length];
117 for (int i = 0; i < ACCEPTED_INTENT_URLS.length; ++i) { 136 for (int i = 0; i < ACCEPTED_INTENT_URLS.length; ++i) {
118 expectedAccepts[i] = 137 expectedAccepts[i] =
119 IntentHandler.GOOGLECHROME_NAVIGATE_PREFIX + ACCEPTED_INTENT _URLS[i]; 138 IntentHandler.GOOGLECHROME_NAVIGATE_PREFIX + ACCEPTED_INTENT _URLS[i];
120 } 139 }
121 processUrls(expectedAccepts, true); 140 processUrls(expectedAccepts, true);
122 } 141 }
123 142
143 @Test
124 @SmallTest 144 @SmallTest
125 @Feature({"Android-AppBase"}) 145 @Feature({"Android-AppBase"})
126 public void testRejectedGoogleChromeSchemeNavigateUrls() { 146 public void testRejectedGoogleChromeSchemeNavigateUrls() {
127 // Test all of the rejected URLs after prepending googlechrome://navigat e?url. 147 // Test all of the rejected URLs after prepending googlechrome://navigat e?url.
128 String[] expectedRejections = new String[REJECTED_INTENT_URLS.length]; 148 String[] expectedRejections = new String[REJECTED_INTENT_URLS.length];
129 for (int i = 0; i < REJECTED_INTENT_URLS.length; ++i) { 149 for (int i = 0; i < REJECTED_INTENT_URLS.length; ++i) {
130 expectedRejections[i] = 150 expectedRejections[i] =
131 IntentHandler.GOOGLECHROME_NAVIGATE_PREFIX + REJECTED_INTENT _URLS[i]; 151 IntentHandler.GOOGLECHROME_NAVIGATE_PREFIX + REJECTED_INTENT _URLS[i];
132 } 152 }
133 processUrls(expectedRejections, false); 153 processUrls(expectedRejections, false);
134 } 154 }
135 155
156 @Test
136 @SmallTest 157 @SmallTest
137 @Feature({"Android-AppBase"}) 158 @Feature({"Android-AppBase"})
138 public void testRejectedGoogleChromeSchemeUrls() { 159 public void testRejectedGoogleChromeSchemeUrls() {
139 Vector<String> failedTests = new Vector<String>(); 160 Vector<String> failedTests = new Vector<String>();
140 161
141 for (String url : REJECTED_GOOGLECHROME_URLS) { 162 for (String url : REJECTED_GOOGLECHROME_URLS) {
142 mIntent.setData(Uri.parse(url)); 163 mIntent.setData(Uri.parse(url));
143 if (IntentHandler.getUrlFromIntent(mIntent) != null) { 164 if (IntentHandler.getUrlFromIntent(mIntent) != null) {
144 failedTests.add(url); 165 failedTests.add(url);
145 } 166 }
146 } 167 }
147 assertTrue(failedTests.toString(), failedTests.isEmpty()); 168 Assert.assertTrue(failedTests.toString(), failedTests.isEmpty());
148 } 169 }
149 170
171 @Test
150 @SmallTest 172 @SmallTest
151 @Feature({"Android-AppBase"}) 173 @Feature({"Android-AppBase"})
152 public void testNullUrlIntent() { 174 public void testNullUrlIntent() {
153 mIntent.setData(null); 175 mIntent.setData(null);
154 assertTrue( 176 Assert.assertTrue(
155 "Intent with null data should be valid", mIntentHandler.intentHa sValidUrl(mIntent)); 177 "Intent with null data should be valid", mIntentHandler.intentHa sValidUrl(mIntent));
156 } 178 }
157 179
180 @Test
158 @UiThreadTest 181 @UiThreadTest
159 @MediumTest 182 @MediumTest
160 @Feature({"Android-AppBase"}) 183 @Feature({"Android-AppBase"})
161 public void testGetQueryFromVoiceSearchResultIntent_validVoiceQuery() { 184 public void testGetQueryFromVoiceSearchResultIntent_validVoiceQuery() {
162 Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_R ESULTS); 185 Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_R ESULTS);
163 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_STRINGS, 186 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_STRINGS,
164 CollectionUtil.newArrayList(VOICE_SEARCH_QUERY)); 187 CollectionUtil.newArrayList(VOICE_SEARCH_QUERY));
165 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_URLS, 188 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_URLS,
166 CollectionUtil.newArrayList(VOICE_SEARCH_QUERY_URL)); 189 CollectionUtil.newArrayList(VOICE_SEARCH_QUERY_URL));
167 String query = IntentHandler.getUrlFromVoiceSearchResult(intent); 190 String query = IntentHandler.getUrlFromVoiceSearchResult(intent);
168 assertEquals(VOICE_SEARCH_QUERY_URL, query); 191 Assert.assertEquals(VOICE_SEARCH_QUERY_URL, query);
169 } 192 }
170 193
194 @Test
171 @UiThreadTest 195 @UiThreadTest
172 @MediumTest 196 @MediumTest
173 @Feature({"Android-AppBase"}) 197 @Feature({"Android-AppBase"})
174 public void testGetQueryFromVoiceSearchResultIntent_validUrlQuery() { 198 public void testGetQueryFromVoiceSearchResultIntent_validUrlQuery() {
175 Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_R ESULTS); 199 Intent intent = new Intent(RecognizerResultsIntent.ACTION_VOICE_SEARCH_R ESULTS);
176 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_STRINGS, 200 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_STRINGS,
177 CollectionUtil.newArrayList(VOICE_URL_QUERY)); 201 CollectionUtil.newArrayList(VOICE_URL_QUERY));
178 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_URLS, 202 intent.putStringArrayListExtra(RecognizerResultsIntent.EXTRA_VOICE_SEARC H_RESULT_URLS,
179 CollectionUtil.newArrayList(VOICE_URL_QUERY_URL)); 203 CollectionUtil.newArrayList(VOICE_URL_QUERY_URL));
180 String query = IntentHandler.getUrlFromVoiceSearchResult(intent); 204 String query = IntentHandler.getUrlFromVoiceSearchResult(intent);
181 assertTrue(String.format("Expected qualified URL: %s, to start " 205 Assert.assertTrue(String.format("Expected qualified URL: %s, to start "
182 + "with http://www.google.com", 206 + "with http://www.google.com",
183 query), 207 query),
184 query.indexOf("http://www.google.com") == 0); 208 query.indexOf("http://www.google.com") == 0);
185 } 209 }
186 210
211 @Test
187 @UiThreadTest 212 @UiThreadTest
188 @SmallTest 213 @SmallTest
189 @Feature({"Android-AppBase"}) 214 @Feature({"Android-AppBase"})
190 public void testRefererUrl_extraReferrer() { 215 public void testRefererUrl_extraReferrer() {
191 // Check that EXTRA_REFERRER is not accepted with a random URL. 216 // Check that EXTRA_REFERRER is not accepted with a random URL.
192 Intent foreignIntent = new Intent(Intent.ACTION_VIEW); 217 Intent foreignIntent = new Intent(Intent.ACTION_VIEW);
193 foreignIntent.putExtra(Intent.EXTRA_REFERRER, GOOGLE_URL); 218 foreignIntent.putExtra(Intent.EXTRA_REFERRER, GOOGLE_URL);
194 assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(foreignInte nt)); 219 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(fore ignIntent));
195 220
196 // Check that EXTRA_REFERRER with android-app URL works. 221 // Check that EXTRA_REFERRER with android-app URL works.
197 final String appUrl = "android-app://com.application/http/www.applicatio n.com"; 222 final String appUrl = "android-app://com.application/http/www.applicatio n.com";
198 Intent appIntent = new Intent(Intent.ACTION_VIEW); 223 Intent appIntent = new Intent(Intent.ACTION_VIEW);
199 appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl)); 224 appIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(appUrl));
200 assertEquals(appUrl, IntentHandler.getReferrerUrlIncludingExtraHeaders(a ppIntent)); 225 Assert.assertEquals(appUrl, IntentHandler.getReferrerUrlIncludingExtraHe aders(appIntent));
201 226
202 // Check that EXTRA_REFERRER_NAME with android-app works. 227 // Check that EXTRA_REFERRER_NAME with android-app works.
203 Intent nameIntent = new Intent(Intent.ACTION_VIEW); 228 Intent nameIntent = new Intent(Intent.ACTION_VIEW);
204 nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl); 229 nameIntent.putExtra(Intent.EXTRA_REFERRER_NAME, appUrl);
205 assertEquals(appUrl, IntentHandler.getReferrerUrlIncludingExtraHeaders(n ameIntent)); 230 Assert.assertEquals(appUrl, IntentHandler.getReferrerUrlIncludingExtraHe aders(nameIntent));
206 } 231 }
207 232
233 @Test
208 @UiThreadTest 234 @UiThreadTest
209 @SmallTest 235 @SmallTest
210 @Feature({"Android-AppBase"}) 236 @Feature({"Android-AppBase"})
211 public void testRefererUrl_extraHeadersInclReferer() { 237 public void testRefererUrl_extraHeadersInclReferer() {
212 // Check that invalid header specified in EXTRA_HEADERS isn't used. 238 // Check that invalid header specified in EXTRA_HEADERS isn't used.
213 Bundle bundle = new Bundle(); 239 Bundle bundle = new Bundle();
214 bundle.putString("X-custom-header", "X-custom-value"); 240 bundle.putString("X-custom-header", "X-custom-value");
215 bundle.putString("Referer", GOOGLE_URL); 241 bundle.putString("Referer", GOOGLE_URL);
216 Intent headersIntent = new Intent(Intent.ACTION_VIEW); 242 Intent headersIntent = new Intent(Intent.ACTION_VIEW);
217 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle); 243 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
218 assertEquals("X-custom-header: X-custom-value", 244 Assert.assertEquals("X-custom-header: X-custom-value",
219 IntentHandler.getExtraHeadersFromIntent(headersIntent)); 245 IntentHandler.getExtraHeadersFromIntent(headersIntent));
220 assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(headersInte nt)); 246 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(head ersIntent));
221 } 247 }
222 248
249 @Test
223 @UiThreadTest 250 @UiThreadTest
224 @SmallTest 251 @SmallTest
225 @Feature({"Android-AppBase"}) 252 @Feature({"Android-AppBase"})
226 public void testRefererUrl_extraHeadersInclRefererMultiple() { 253 public void testRefererUrl_extraHeadersInclRefererMultiple() {
227 // Check that invalid header specified in EXTRA_HEADERS isn't used. 254 // Check that invalid header specified in EXTRA_HEADERS isn't used.
228 Bundle bundle = new Bundle(); 255 Bundle bundle = new Bundle();
229 bundle.putString("X-custom-header", "X-custom-value"); 256 bundle.putString("X-custom-header", "X-custom-value");
230 bundle.putString("X-custom-header-2", "X-custom-value-2"); 257 bundle.putString("X-custom-header-2", "X-custom-value-2");
231 bundle.putString("Referer", GOOGLE_URL); 258 bundle.putString("Referer", GOOGLE_URL);
232 Intent headersIntent = new Intent(Intent.ACTION_VIEW); 259 Intent headersIntent = new Intent(Intent.ACTION_VIEW);
233 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle); 260 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
234 assertEquals("X-custom-header-2: X-custom-value-2\nX-custom-header: X-cu stom-value", 261 Assert.assertEquals("X-custom-header-2: X-custom-value-2\nX-custom-heade r: X-custom-value",
235 IntentHandler.getExtraHeadersFromIntent(headersIntent)); 262 IntentHandler.getExtraHeadersFromIntent(headersIntent));
236 assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(headersInte nt)); 263 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(head ersIntent));
237 } 264 }
238 265
266 @Test
239 @UiThreadTest 267 @UiThreadTest
240 @SmallTest 268 @SmallTest
241 @Feature({"Android-AppBase"}) 269 @Feature({"Android-AppBase"})
242 public void testRefererUrl_extraHeadersOnlyReferer() { 270 public void testRefererUrl_extraHeadersOnlyReferer() {
243 // Check that invalid header specified in EXTRA_HEADERS isn't used. 271 // Check that invalid header specified in EXTRA_HEADERS isn't used.
244 Bundle bundle = new Bundle(); 272 Bundle bundle = new Bundle();
245 bundle.putString("Referer", GOOGLE_URL); 273 bundle.putString("Referer", GOOGLE_URL);
246 Intent headersIntent = new Intent(Intent.ACTION_VIEW); 274 Intent headersIntent = new Intent(Intent.ACTION_VIEW);
247 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle); 275 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
248 assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(headersInte nt)); 276 Assert.assertNull(IntentHandler.getReferrerUrlIncludingExtraHeaders(head ersIntent));
249 } 277 }
250 278
279 @Test
251 @UiThreadTest 280 @UiThreadTest
252 @SmallTest 281 @SmallTest
253 @Feature({"Android-AppBase"}) 282 @Feature({"Android-AppBase"})
254 public void testRefererUrl_extraHeadersAndExtraReferrer() { 283 public void testRefererUrl_extraHeadersAndExtraReferrer() {
255 String validReferer = "android-app://package/http/url"; 284 String validReferer = "android-app://package/http/url";
256 Bundle bundle = new Bundle(); 285 Bundle bundle = new Bundle();
257 bundle.putString("Referer", GOOGLE_URL); 286 bundle.putString("Referer", GOOGLE_URL);
258 Intent headersIntent = new Intent(Intent.ACTION_VIEW); 287 Intent headersIntent = new Intent(Intent.ACTION_VIEW);
259 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle); 288 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
260 headersIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(validReferer)); 289 headersIntent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(validReferer));
261 assertEquals(validReferer, 290 Assert.assertEquals(
262 IntentHandler.getReferrerUrlIncludingExtraHeaders(headersIntent) ); 291 validReferer, IntentHandler.getReferrerUrlIncludingExtraHeaders( headersIntent));
263 assertNull(IntentHandler.getExtraHeadersFromIntent(headersIntent)); 292 Assert.assertNull(IntentHandler.getExtraHeadersFromIntent(headersIntent) );
264 } 293 }
265 294
295 @Test
266 @UiThreadTest 296 @UiThreadTest
267 @SmallTest 297 @SmallTest
268 @Feature({"Android-AppBase"}) 298 @Feature({"Android-AppBase"})
269 public void testRefererUrl_extraHeadersValidReferrer() { 299 public void testRefererUrl_extraHeadersValidReferrer() {
270 String validReferer = "android-app://package/http/url"; 300 String validReferer = "android-app://package/http/url";
271 Bundle bundle = new Bundle(); 301 Bundle bundle = new Bundle();
272 bundle.putString("Referer", validReferer); 302 bundle.putString("Referer", validReferer);
273 Intent headersIntent = new Intent(Intent.ACTION_VIEW); 303 Intent headersIntent = new Intent(Intent.ACTION_VIEW);
274 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle); 304 headersIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
275 assertEquals(validReferer, 305 Assert.assertEquals(
276 IntentHandler.getReferrerUrlIncludingExtraHeaders(headersIntent) ); 306 validReferer, IntentHandler.getReferrerUrlIncludingExtraHeaders( headersIntent));
277 assertNull(IntentHandler.getExtraHeadersFromIntent(headersIntent)); 307 Assert.assertNull(IntentHandler.getExtraHeadersFromIntent(headersIntent) );
278 } 308 }
279 309
310 @Test
280 @SmallTest 311 @SmallTest
281 @Feature({"Android-AppBase"}) 312 @Feature({"Android-AppBase"})
282 public void testAddTimestampToIntent() { 313 public void testAddTimestampToIntent() {
283 Intent intent = new Intent(); 314 Intent intent = new Intent();
284 assertEquals(-1, IntentHandler.getTimestampFromIntent(intent)); 315 Assert.assertEquals(-1, IntentHandler.getTimestampFromIntent(intent));
285 // Check both before and after to make sure that the returned value is 316 // Check both before and after to make sure that the returned value is
286 // really from {@link SystemClock#elapsedRealtime()}. 317 // really from {@link SystemClock#elapsedRealtime()}.
287 long before = SystemClock.elapsedRealtime(); 318 long before = SystemClock.elapsedRealtime();
288 IntentHandler.addTimestampToIntent(intent); 319 IntentHandler.addTimestampToIntent(intent);
289 long after = SystemClock.elapsedRealtime(); 320 long after = SystemClock.elapsedRealtime();
290 assertTrue("Time should be increasing", 321 Assert.assertTrue("Time should be increasing",
291 before <= IntentHandler.getTimestampFromIntent(intent)); 322 before <= IntentHandler.getTimestampFromIntent(intent));
292 assertTrue("Time should be increasing", 323 Assert.assertTrue(
293 IntentHandler.getTimestampFromIntent(intent) <= after); 324 "Time should be increasing", IntentHandler.getTimestampFromInten t(intent) <= after);
294 } 325 }
295 326
327 @Test
296 @SmallTest 328 @SmallTest
297 @Feature({"Android-AppBase"}) 329 @Feature({"Android-AppBase"})
298 public void testGeneratedReferrer() { 330 public void testGeneratedReferrer() {
299 Context context = getInstrumentation().getTargetContext(); 331 Context context = InstrumentationRegistry.getInstrumentation().getTarget Context();
300 String packageName = context.getPackageName(); 332 String packageName = context.getPackageName();
301 String referrer = IntentHandler.constructValidReferrerForAuthority(packa geName).getUrl(); 333 String referrer = IntentHandler.constructValidReferrerForAuthority(packa geName).getUrl();
302 assertEquals("android-app://" + packageName, referrer); 334 Assert.assertEquals("android-app://" + packageName, referrer);
303 } 335 }
304 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698