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.Intent; | 7 import android.content.Intent; |
8 import android.net.Uri; | 8 import android.net.Uri; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.os.Environment; | 10 import android.os.Environment; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 protected void tearDown() throws Exception { | 170 protected void tearDown() throws Exception { |
171 mTestServer.stopAndDestroyServer(); | 171 mTestServer.stopAndDestroyServer(); |
172 super.tearDown(); | 172 super.tearDown(); |
173 } | 173 } |
174 | 174 |
175 /** | 175 /** |
176 * Launch the specified URL as if it was triggered by an external applicatio
n with id appId. | 176 * Launch the specified URL as if it was triggered by an external applicatio
n with id appId. |
177 * Returns when the URL has been navigated to. | 177 * Returns when the URL has been navigated to. |
178 * @throws InterruptedException | 178 * @throws InterruptedException |
179 */ | 179 */ |
180 private void launchUrlFromExternalApp(String url, String appId, boolean crea
teNewTab, | 180 private void launchUrlFromExternalApp(String url, String expectedUrl, String
appId, |
181 Bundle extras) throws InterruptedException { | 181 boolean createNewTab, Bundle extras) throws InterruptedException { |
182 final Intent intent = new Intent(Intent.ACTION_VIEW); | 182 final Intent intent = new Intent(Intent.ACTION_VIEW); |
183 if (appId != null) { | 183 if (appId != null) { |
184 intent.putExtra(Browser.EXTRA_APPLICATION_ID, appId); | 184 intent.putExtra(Browser.EXTRA_APPLICATION_ID, appId); |
185 } | 185 } |
186 if (createNewTab) { | 186 if (createNewTab) { |
187 intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); | 187 intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
188 } | 188 } |
189 intent.setData(Uri.parse(url)); | 189 intent.setData(Uri.parse(url)); |
190 if (extras != null) intent.putExtras(extras); | 190 if (extras != null) intent.putExtras(extras); |
191 | 191 |
192 final Tab originalTab = getActivity().getActivityTab(); | 192 final Tab originalTab = getActivity().getActivityTab(); |
193 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 193 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
194 @Override | 194 @Override |
195 public void run() { | 195 public void run() { |
196 getActivity().onNewIntent(intent); | 196 getActivity().onNewIntent(intent); |
197 } | 197 } |
198 }); | 198 }); |
199 if (createNewTab) { | 199 if (createNewTab) { |
200 CriteriaHelper.pollForUIThreadCriteria(new Criteria("Failed to selec
t different tab") { | 200 CriteriaHelper.pollForUIThreadCriteria(new Criteria("Failed to selec
t different tab") { |
201 @Override | 201 @Override |
202 public boolean isSatisfied() { | 202 public boolean isSatisfied() { |
203 return getActivity().getActivityTab() != originalTab; | 203 return getActivity().getActivityTab() != originalTab; |
204 } | 204 } |
205 }); | 205 }); |
206 } | 206 } |
207 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), url)
; | 207 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), expe
ctedUrl); |
208 } | 208 } |
209 | 209 |
210 private void launchUrlFromExternalApp(String url, String appId, boolean crea
teNewTab) | 210 private void launchUrlFromExternalApp(String url, String appId, boolean crea
teNewTab) |
211 throws InterruptedException { | 211 throws InterruptedException { |
212 launchUrlFromExternalApp(url, appId, createNewTab, null); | 212 launchUrlFromExternalApp(url, url, appId, createNewTab, null); |
213 } | 213 } |
214 | 214 |
215 /** | 215 /** |
216 * Tests that URLs opened from external apps can set an android-app scheme r
eferrer. | 216 * Tests that URLs opened from external apps can set an android-app scheme r
eferrer. |
217 * @throws InterruptedException | 217 * @throws InterruptedException |
218 */ | 218 */ |
219 @LargeTest | 219 @LargeTest |
220 @Feature({"Navigation"}) | 220 @Feature({"Navigation"}) |
221 public void testReferrer() throws InterruptedException { | 221 public void testReferrer() throws InterruptedException { |
222 String url = mTestServer.getURL("/chrome/test/data/android/about.html"); | 222 String url = mTestServer.getURL("/chrome/test/data/android/about.html"); |
223 startMainActivityFromLauncher(); | 223 startMainActivityFromLauncher(); |
224 Bundle extras = new Bundle(); | 224 Bundle extras = new Bundle(); |
225 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(ANDROID_APP_REFERR
ER)); | 225 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(ANDROID_APP_REFERR
ER)); |
226 launchUrlFromExternalApp(url, EXTERNAL_APP_1_ID, true, extras); | 226 launchUrlFromExternalApp(url, url, EXTERNAL_APP_1_ID, true, extras); |
227 CriteriaHelper.pollForCriteria( | 227 CriteriaHelper.pollForCriteria( |
228 new ReferrerCriteria(getActivity().getActivityTab(), ANDROID_APP
_REFERRER), 2000, | 228 new ReferrerCriteria(getActivity().getActivityTab(), ANDROID_APP
_REFERRER), 2000, |
229 200); | 229 200); |
230 } | 230 } |
231 | 231 |
232 /** | 232 /** |
233 * Tests that URLs opened from external apps can set an android-app scheme r
eferrer. | 233 * Tests that URLs opened from external apps can set an android-app scheme r
eferrer. |
234 * @throws InterruptedException | 234 * @throws InterruptedException |
235 */ | 235 */ |
236 @LargeTest | 236 @LargeTest |
237 @Feature({"Navigation"}) | 237 @Feature({"Navigation"}) |
238 public void testCannotSetArbitraryReferrer() throws InterruptedException { | 238 public void testCannotSetArbitraryReferrer() throws InterruptedException { |
239 String url = mTestServer.getURL("/chrome/test/data/android/about.html"); | 239 String url = mTestServer.getURL("/chrome/test/data/android/about.html"); |
240 startMainActivityFromLauncher(); | 240 startMainActivityFromLauncher(); |
241 String referrer = "foobar://totally.legit.referrer"; | 241 String referrer = "foobar://totally.legit.referrer"; |
242 Bundle extras = new Bundle(); | 242 Bundle extras = new Bundle(); |
243 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(referrer)); | 243 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(referrer)); |
244 launchUrlFromExternalApp(url, EXTERNAL_APP_1_ID, true, extras); | 244 launchUrlFromExternalApp(url, url, EXTERNAL_APP_1_ID, true, extras); |
245 CriteriaHelper.pollForCriteria( | 245 CriteriaHelper.pollForCriteria( |
246 new ReferrerCriteria(getActivity().getActivityTab(), ""), 2000,
200); | 246 new ReferrerCriteria(getActivity().getActivityTab(), ""), 2000,
200); |
247 } | 247 } |
248 | 248 |
249 /** | 249 /** |
250 * Tests that URLs opened from the same external app don't create new tabs. | 250 * Tests that URLs opened from the same external app don't create new tabs. |
251 * @throws InterruptedException | 251 * @throws InterruptedException |
252 */ | 252 */ |
253 @LargeTest | 253 @LargeTest |
254 @Feature({"Navigation"}) | 254 @Feature({"Navigation"}) |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 getActivity().onBackPressed(); | 625 getActivity().onBackPressed(); |
626 } | 626 } |
627 }); | 627 }); |
628 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 628 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
629 @Override | 629 @Override |
630 public boolean isSatisfied() { | 630 public boolean isSatisfied() { |
631 return getActivity().getTabModelSelector().getTotalTabCount() ==
1; | 631 return getActivity().getTabModelSelector().getTotalTabCount() ==
1; |
632 } | 632 } |
633 }); | 633 }); |
634 } | 634 } |
| 635 |
| 636 /** |
| 637 * Tests that a Weblite url from an external app uses the lite_url param whe
n Data Reduction |
| 638 * Proxy previews are being used. |
| 639 */ |
| 640 @MediumTest |
| 641 @CommandLineFlags.Add({"enable-spdy-proxy-auth", "data-reduction-proxy-lo-fi
=always-on", |
| 642 "enable-data-reduction-proxy-lo-fi-preview"}) |
| 643 public void testLaunchWebLiteURL() throws InterruptedException { |
| 644 startMainActivityFromLauncher(); |
| 645 |
| 646 String url = mTestServer.getURL("/chrome/test/data/android/about.html"); |
| 647 |
| 648 // Launch a first URL from an app. |
| 649 launchUrlFromExternalApp("http://googleweblight.com/?lite_url=" + url, u
rl, |
| 650 EXTERNAL_APP_1_ID, false, null); |
| 651 |
| 652 assertEquals("Selected tab is not on the right URL.", |
| 653 url, getActivity().getActivityTab().getUrl()); |
| 654 } |
| 655 |
| 656 /** |
| 657 * Tests that a Weblite url from an external app does not use the lite_url p
aram when Data |
| 658 * Reduction Proxy previews are not being used. |
| 659 */ |
| 660 @MediumTest |
| 661 public void testLaunchWebLiteURLNoPreviews() throws InterruptedException { |
| 662 startMainActivityFromLauncher(); |
| 663 |
| 664 String url = "http://googleweblight.com/?lite_url=chrome/test/data/andro
id/about.html"; |
| 665 |
| 666 // Launch a first URL from an app. |
| 667 launchUrlFromExternalApp(url, url, EXTERNAL_APP_1_ID, false, null); |
| 668 |
| 669 assertEquals("Selected tab is not on the right URL.", |
| 670 url, getActivity().getActivityTab().getUrl()); |
| 671 } |
635 } | 672 } |
OLD | NEW |