OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.externalnav; | 5 package org.chromium.chrome.browser.externalnav; |
6 | 6 |
7 import android.content.IntentFilter; | 7 import android.content.IntentFilter; |
8 import android.content.pm.ActivityInfo; | 8 import android.content.pm.ActivityInfo; |
9 import android.content.pm.ResolveInfo; | 9 import android.content.pm.ResolveInfo; |
10 import android.test.InstrumentationTestCase; | |
11 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
12 | 11 |
| 12 import org.chromium.base.test.util.CommandLineFlags; |
| 13 import org.chromium.chrome.browser.ChromeActivity; |
| 14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 15 |
13 import java.util.ArrayList; | 16 import java.util.ArrayList; |
14 import java.util.Arrays; | 17 import java.util.Arrays; |
15 import java.util.List; | 18 import java.util.List; |
16 | 19 |
17 | |
18 /** | 20 /** |
19 * Instrumentation tests for {@link ExternalNavigationHandler}. | 21 * Instrumentation tests for {@link ExternalNavigationHandler}. |
20 */ | 22 */ |
21 public class ExternalNavigationDelegateImplTest extends InstrumentationTestCase
{ | 23 public class ExternalNavigationDelegateImplTest extends ChromeActivityTestCaseBa
se<ChromeActivity> { |
| 24 |
| 25 public ExternalNavigationDelegateImplTest() { |
| 26 super(ChromeActivity.class); |
| 27 } |
22 | 28 |
23 private static List<ResolveInfo> makeResolveInfos(ResolveInfo... infos) { | 29 private static List<ResolveInfo> makeResolveInfos(ResolveInfo... infos) { |
24 return Arrays.asList(infos); | 30 return Arrays.asList(infos); |
25 } | 31 } |
26 | 32 |
27 @SmallTest | 33 @SmallTest |
28 public void testIsPackageSpecializedHandler_NoResolveInfo() { | 34 public void testIsPackageSpecializedHandler_NoResolveInfo() { |
29 String packageName = ""; | 35 String packageName = ""; |
30 List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); | 36 List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); |
31 assertFalse(ExternalNavigationDelegateImpl | 37 assertFalse(ExternalNavigationDelegateImpl |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 String packageName = "com.android.chrome"; | 88 String packageName = "com.android.chrome"; |
83 ResolveInfo info = new ResolveInfo(); | 89 ResolveInfo info = new ResolveInfo(); |
84 info.filter = new IntentFilter(); | 90 info.filter = new IntentFilter(); |
85 info.filter.addDataAuthority("http://www.google.com", "80"); | 91 info.filter.addDataAuthority("http://www.google.com", "80"); |
86 info.activityInfo = new ActivityInfo(); | 92 info.activityInfo = new ActivityInfo(); |
87 info.activityInfo.packageName = "com.foo.bar"; | 93 info.activityInfo.packageName = "com.foo.bar"; |
88 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 94 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
89 assertFalse(ExternalNavigationDelegateImpl | 95 assertFalse(ExternalNavigationDelegateImpl |
90 .isPackageSpecializedHandler(resolveInfos, packageName)); | 96 .isPackageSpecializedHandler(resolveInfos, packageName)); |
91 } | 97 } |
| 98 |
| 99 @SmallTest |
| 100 @CommandLineFlags.Add({"disable-features=SystemDownloadManager"}) |
| 101 public void testIsDownload_noSystemDownloadManager() throws Exception { |
| 102 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( |
| 103 getActivity().getActivityTab()); |
| 104 assertTrue("pdf should be a download, no viewer in Android Chrome", |
| 105 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; |
| 106 assertFalse("URL is not a file, but web page", |
| 107 delegate.isPdfDownload("http://somesampleurldne.com/index.html")
); |
| 108 assertFalse("URL is not a file url", |
| 109 delegate.isPdfDownload("http://somesampeleurldne.com/not.a.real.
extension")); |
| 110 assertFalse("URL is an image, can be viewed in Chrome", |
| 111 delegate.isPdfDownload("http://somesampleurldne.com/image.jpg"))
; |
| 112 assertFalse("URL is a text file can be viewed in Chrome", |
| 113 delegate.isPdfDownload("http://somesampleurldne.com/copy.txt")); |
| 114 } |
| 115 |
| 116 @SmallTest |
| 117 @CommandLineFlags.Add({"enable-features=SystemDownloadManager"}) |
| 118 public void testIsDownload_withSystemDownloadManager() throws Exception { |
| 119 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( |
| 120 getActivity().getActivityTab()); |
| 121 assertFalse("isDownload should return false with SystemDownloadManager e
nabled", |
| 122 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; |
| 123 } |
| 124 |
| 125 @Override |
| 126 public void startMainActivity() throws InterruptedException { |
| 127 startMainActivityOnBlankPage(); |
| 128 } |
92 } | 129 } |
OLD | NEW |