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.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 private static List<ResolveInfo> makeResolveInfos(ResolveInfo... infos) { | 29 private static List<ResolveInfo> makeResolveInfos(ResolveInfo... infos) { |
30 return Arrays.asList(infos); | 30 return Arrays.asList(infos); |
31 } | 31 } |
32 | 32 |
33 @SmallTest | 33 @SmallTest |
34 public void testIsPackageSpecializedHandler_NoResolveInfo() { | 34 public void testIsPackageSpecializedHandler_NoResolveInfo() { |
35 String packageName = ""; | 35 String packageName = ""; |
36 List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); | 36 List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); |
37 assertFalse(ExternalNavigationDelegateImpl | 37 assertEquals(0, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
38 .isPackageSpecializedHandler(resolveInfos, packageName)); | 38 resolveInfos, packageName)); |
39 } | 39 } |
40 | 40 |
41 @SmallTest | 41 @SmallTest |
42 public void testIsPackageSpecializedHandler_NoPathOrAuthority() { | 42 public void testIsPackageSpecializedHandler_NoPathOrAuthority() { |
43 String packageName = ""; | 43 String packageName = ""; |
44 ResolveInfo info = new ResolveInfo(); | 44 ResolveInfo info = new ResolveInfo(); |
45 info.filter = new IntentFilter(); | 45 info.filter = new IntentFilter(); |
46 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 46 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
47 assertFalse(ExternalNavigationDelegateImpl | 47 assertEquals(0, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
48 .isPackageSpecializedHandler(resolveInfos, packageName)); | 48 resolveInfos, packageName)); |
49 } | 49 } |
50 | 50 |
51 @SmallTest | 51 @SmallTest |
52 public void testIsPackageSpecializedHandler_WithPath() { | 52 public void testIsPackageSpecializedHandler_WithPath() { |
53 String packageName = ""; | 53 String packageName = ""; |
54 ResolveInfo info = new ResolveInfo(); | 54 ResolveInfo info = new ResolveInfo(); |
55 info.filter = new IntentFilter(); | 55 info.filter = new IntentFilter(); |
56 info.filter.addDataPath("somepath", 2); | 56 info.filter.addDataPath("somepath", 2); |
57 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 57 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
58 assertTrue(ExternalNavigationDelegateImpl | 58 assertEquals(1, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
59 .isPackageSpecializedHandler(resolveInfos, packageName)); | 59 resolveInfos, packageName)); |
60 } | 60 } |
61 | 61 |
62 @SmallTest | 62 @SmallTest |
63 public void testIsPackageSpecializedHandler_WithAuthority() { | 63 public void testIsPackageSpecializedHandler_WithAuthority() { |
64 String packageName = ""; | 64 String packageName = ""; |
65 ResolveInfo info = new ResolveInfo(); | 65 ResolveInfo info = new ResolveInfo(); |
66 info.filter = new IntentFilter(); | 66 info.filter = new IntentFilter(); |
67 info.filter.addDataAuthority("http://www.google.com", "80"); | 67 info.filter.addDataAuthority("http://www.google.com", "80"); |
68 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 68 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
69 assertTrue(ExternalNavigationDelegateImpl | 69 assertEquals(1, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
70 .isPackageSpecializedHandler(resolveInfos, packageName)); | 70 resolveInfos, packageName)); |
71 } | 71 } |
72 | 72 |
73 @SmallTest | 73 @SmallTest |
74 public void testIsPackageSpecializedHandler_WithTargetPackage_Matching() { | 74 public void testIsPackageSpecializedHandler_WithTargetPackage_Matching() { |
75 String packageName = "com.android.chrome"; | 75 String packageName = "com.android.chrome"; |
76 ResolveInfo info = new ResolveInfo(); | 76 ResolveInfo info = new ResolveInfo(); |
77 info.filter = new IntentFilter(); | 77 info.filter = new IntentFilter(); |
78 info.filter.addDataAuthority("http://www.google.com", "80"); | 78 info.filter.addDataAuthority("http://www.google.com", "80"); |
79 info.activityInfo = new ActivityInfo(); | 79 info.activityInfo = new ActivityInfo(); |
80 info.activityInfo.packageName = packageName; | 80 info.activityInfo.packageName = packageName; |
81 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 81 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
82 assertTrue(ExternalNavigationDelegateImpl | 82 assertEquals(1, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
83 .isPackageSpecializedHandler(resolveInfos, packageName)); | 83 resolveInfos, packageName)); |
84 } | 84 } |
85 | 85 |
86 @SmallTest | 86 @SmallTest |
87 public void testIsPackageSpecializedHandler_WithTargetPackage_NotMatching()
{ | 87 public void testIsPackageSpecializedHandler_WithTargetPackage_NotMatching()
{ |
88 String packageName = "com.android.chrome"; | 88 String packageName = "com.android.chrome"; |
89 ResolveInfo info = new ResolveInfo(); | 89 ResolveInfo info = new ResolveInfo(); |
90 info.filter = new IntentFilter(); | 90 info.filter = new IntentFilter(); |
91 info.filter.addDataAuthority("http://www.google.com", "80"); | 91 info.filter.addDataAuthority("http://www.google.com", "80"); |
92 info.activityInfo = new ActivityInfo(); | 92 info.activityInfo = new ActivityInfo(); |
93 info.activityInfo.packageName = "com.foo.bar"; | 93 info.activityInfo.packageName = "com.foo.bar"; |
94 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 94 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
95 assertFalse(ExternalNavigationDelegateImpl | 95 assertEquals(0, ExternalNavigationDelegateImpl.countSpecializedHandlersW
ithFilter( |
96 .isPackageSpecializedHandler(resolveInfos, packageName)); | 96 resolveInfos, packageName)); |
97 } | 97 } |
98 | 98 |
99 @SmallTest | 99 @SmallTest |
100 @CommandLineFlags.Add({"disable-features=SystemDownloadManager"}) | 100 @CommandLineFlags.Add({"disable-features=SystemDownloadManager"}) |
101 public void testIsDownload_noSystemDownloadManager() throws Exception { | 101 public void testIsDownload_noSystemDownloadManager() throws Exception { |
102 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( | 102 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( |
103 getActivity().getActivityTab()); | 103 getActivity().getActivityTab()); |
104 assertTrue("pdf should be a download, no viewer in Android Chrome", | 104 assertTrue("pdf should be a download, no viewer in Android Chrome", |
105 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; | 105 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; |
106 assertFalse("URL is not a file, but web page", | 106 assertFalse("URL is not a file, but web page", |
(...skipping 13 matching lines...) Expand all Loading... |
120 getActivity().getActivityTab()); | 120 getActivity().getActivityTab()); |
121 assertFalse("isDownload should return false with SystemDownloadManager e
nabled", | 121 assertFalse("isDownload should return false with SystemDownloadManager e
nabled", |
122 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; | 122 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; |
123 } | 123 } |
124 | 124 |
125 @Override | 125 @Override |
126 public void startMainActivity() throws InterruptedException { | 126 public void startMainActivity() throws InterruptedException { |
127 startMainActivityOnBlankPage(); | 127 startMainActivityOnBlankPage(); |
128 } | 128 } |
129 } | 129 } |
OLD | NEW |