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; |
11 | 11 |
12 import org.chromium.base.test.util.CommandLineFlags; | |
13 import org.chromium.base.test.util.RetryOnFailure; | 12 import org.chromium.base.test.util.RetryOnFailure; |
14 import org.chromium.chrome.browser.ChromeActivity; | 13 import org.chromium.chrome.browser.ChromeActivity; |
15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
16 | 15 |
17 import java.util.ArrayList; | 16 import java.util.ArrayList; |
18 import java.util.Arrays; | 17 import java.util.Arrays; |
19 import java.util.List; | 18 import java.util.List; |
20 | 19 |
21 /** | 20 /** |
22 * Instrumentation tests for {@link ExternalNavigationHandler}. | 21 * Instrumentation tests for {@link ExternalNavigationHandler}. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 info.filter = new IntentFilter(); | 96 info.filter = new IntentFilter(); |
98 info.filter.addDataAuthority("http://www.google.com", "80"); | 97 info.filter.addDataAuthority("http://www.google.com", "80"); |
99 info.activityInfo = new ActivityInfo(); | 98 info.activityInfo = new ActivityInfo(); |
100 info.activityInfo.packageName = "com.foo.bar"; | 99 info.activityInfo.packageName = "com.foo.bar"; |
101 List<ResolveInfo> resolveInfos = makeResolveInfos(info); | 100 List<ResolveInfo> resolveInfos = makeResolveInfos(info); |
102 assertEquals(0, ExternalNavigationDelegateImpl.getSpecializedHandlersWit
hFilter( | 101 assertEquals(0, ExternalNavigationDelegateImpl.getSpecializedHandlersWit
hFilter( |
103 resolveInfos, packageName).size()); | 102 resolveInfos, packageName).size()); |
104 } | 103 } |
105 | 104 |
106 @SmallTest | 105 @SmallTest |
107 @CommandLineFlags.Add({"disable-features=SystemDownloadManager"}) | |
108 @RetryOnFailure | 106 @RetryOnFailure |
109 public void testIsDownload_noSystemDownloadManager() throws Exception { | 107 public void testIsDownload_noSystemDownloadManager() throws Exception { |
110 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( | 108 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( |
111 getActivity().getActivityTab()); | 109 getActivity().getActivityTab()); |
112 assertTrue("pdf should be a download, no viewer in Android Chrome", | 110 assertTrue("pdf should be a download, no viewer in Android Chrome", |
113 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; | 111 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; |
114 assertFalse("URL is not a file, but web page", | 112 assertFalse("URL is not a file, but web page", |
115 delegate.isPdfDownload("http://somesampleurldne.com/index.html")
); | 113 delegate.isPdfDownload("http://somesampleurldne.com/index.html")
); |
116 assertFalse("URL is not a file url", | 114 assertFalse("URL is not a file url", |
117 delegate.isPdfDownload("http://somesampeleurldne.com/not.a.real.
extension")); | 115 delegate.isPdfDownload("http://somesampeleurldne.com/not.a.real.
extension")); |
118 assertFalse("URL is an image, can be viewed in Chrome", | 116 assertFalse("URL is an image, can be viewed in Chrome", |
119 delegate.isPdfDownload("http://somesampleurldne.com/image.jpg"))
; | 117 delegate.isPdfDownload("http://somesampleurldne.com/image.jpg"))
; |
120 assertFalse("URL is a text file can be viewed in Chrome", | 118 assertFalse("URL is a text file can be viewed in Chrome", |
121 delegate.isPdfDownload("http://somesampleurldne.com/copy.txt")); | 119 delegate.isPdfDownload("http://somesampleurldne.com/copy.txt")); |
122 } | 120 } |
123 | 121 |
124 @SmallTest | |
125 @CommandLineFlags.Add({"enable-features=SystemDownloadManager"}) | |
126 public void testIsDownload_withSystemDownloadManager() throws Exception { | |
127 ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegate
Impl( | |
128 getActivity().getActivityTab()); | |
129 assertFalse("isDownload should return false with SystemDownloadManager e
nabled", | |
130 delegate.isPdfDownload("http://somesampeleurldne.com/file.pdf"))
; | |
131 } | |
132 | |
133 @Override | 122 @Override |
134 public void startMainActivity() throws InterruptedException { | 123 public void startMainActivity() throws InterruptedException { |
135 startMainActivityOnBlankPage(); | 124 startMainActivityOnBlankPage(); |
136 } | 125 } |
137 } | 126 } |
OLD | NEW |