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

Side by Side Diff: chrome/browser/chromeos/arc/intent_helper/arc_external_protocol_dialog_unittest.cc

Issue 2540013004: Allow an external URL with FROM_API qualifier to be forwarded to ARC (Closed)
Patch Set: address comment Created 4 years 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 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 #include "chrome/browser/chromeos/arc/intent_helper/arc_external_protocol_dialog .h" 5 #include "chrome/browser/chromeos/arc/intent_helper/arc_external_protocol_dialog .h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace arc { 10 namespace arc {
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 // Tests that when no apps are returned from ARC, GetAction returns 32 // Tests that when no apps are returned from ARC, GetAction returns
33 // SHOW_CHROME_OS_DIALOG. 33 // SHOW_CHROME_OS_DIALOG.
34 TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) { 34 TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) {
35 std::vector<mojom::IntentHandlerInfoPtr> handlers; 35 std::vector<mojom::IntentHandlerInfoPtr> handlers;
36 std::pair<GURL, std::string> url_and_package; 36 std::pair<GURL, std::string> url_and_package;
37 EXPECT_EQ(GetActionResult::SHOW_CHROME_OS_DIALOG, 37 EXPECT_EQ(GetActionResult::SHOW_CHROME_OS_DIALOG,
38 GetActionForTesting(GURL("external-protocol:foo"), handlers, 38 GetActionForTesting(GURL("external-protocol:foo"), false, handlers,
39 handlers.size(), &url_and_package)); 39 handlers.size(), &url_and_package));
40 } 40 }
41 41
42 // Tests that when one app is passed to GetAction but the user hasn't selected 42 // Tests that when one app is passed to GetAction but the user hasn't selected
43 // it, the function returns ASK_USER. 43 // it, the function returns ASK_USER.
44 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneApp) { 44 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneApp) {
45 std::vector<mojom::IntentHandlerInfoPtr> handlers; 45 std::vector<mojom::IntentHandlerInfoPtr> handlers;
46 handlers.push_back( 46 handlers.push_back(
47 Create("package", "com.google.package.name", false, GURL())); 47 Create("package", "com.google.package.name", false, GURL()));
48 48
49 const size_t no_selection = handlers.size(); 49 const size_t no_selection = handlers.size();
50 std::pair<GURL, std::string> url_and_package; 50 std::pair<GURL, std::string> url_and_package;
51 EXPECT_EQ(GetActionResult::ASK_USER, 51 EXPECT_EQ(GetActionResult::ASK_USER,
52 GetActionForTesting(GURL("external-protocol:foo"), handlers, 52 GetActionForTesting(GURL("external-protocol:foo"), false, handlers,
53 no_selection, &url_and_package)); 53 no_selection, &url_and_package));
54 } 54 }
55 55
56 // Tests that when one preferred app is passed to GetAction, the function 56 // Tests that when one preferred app is passed to GetAction, the function
57 // returns HANDLE_URL_IN_ARC even if the user hasn't selected the app. 57 // returns HANDLE_URL_IN_ARC even if the user hasn't selected the app.
58 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredApp) { 58 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredApp) {
59 const GURL external_url("external-protocol:foo"); 59 const GURL external_url("external-protocol:foo");
60 const std::string package_name("com.google.package.name"); 60 const std::string package_name("com.google.package.name");
61 61
62 std::vector<mojom::IntentHandlerInfoPtr> handlers; 62 std::vector<mojom::IntentHandlerInfoPtr> handlers;
63 handlers.push_back(Create("package", package_name, true, GURL())); 63 handlers.push_back(Create("package", package_name, true, GURL()));
64 64
65 const size_t no_selection = handlers.size(); 65 const size_t no_selection = handlers.size();
66 std::pair<GURL, std::string> url_and_package; 66 std::pair<GURL, std::string> url_and_package;
67 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 67 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
68 GetActionForTesting(external_url, handlers, no_selection, 68 GetActionForTesting(external_url, false, handlers, no_selection,
69 &url_and_package)); 69 &url_and_package));
70 EXPECT_EQ(external_url, url_and_package.first); 70 EXPECT_EQ(external_url, url_and_package.first);
71 EXPECT_EQ(package_name, url_and_package.second); 71 EXPECT_EQ(package_name, url_and_package.second);
72
73 // Test that when |always_ask_user| is true, the preferred app setting is
74 // ignored.
75 EXPECT_EQ(GetActionResult::ASK_USER,
76 GetActionForTesting(external_url, true, handlers, no_selection,
77 &url_and_package));
72 } 78 }
73 79
74 // Tests that when one app is passed to GetAction, the user has already selected 80 // Tests that when one app is passed to GetAction, the user has already selected
75 // it, the function returns HANDLE_URL_IN_ARC. 81 // it, the function returns HANDLE_URL_IN_ARC.
76 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneAppSelected) { 82 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneAppSelected) {
77 const GURL external_url("external-protocol:foo"); 83 const GURL external_url("external-protocol:foo");
78 const std::string package_name("com.google.package.name"); 84 const std::string package_name("com.google.package.name");
79 85
80 std::vector<mojom::IntentHandlerInfoPtr> handlers; 86 std::vector<mojom::IntentHandlerInfoPtr> handlers;
81 handlers.push_back(Create("package", package_name, false, GURL())); 87 handlers.push_back(Create("package", package_name, false, GURL()));
82 88
83 constexpr size_t kSelection = 0; 89 constexpr size_t kSelection = 0;
84 std::pair<GURL, std::string> url_and_package; 90 std::pair<GURL, std::string> url_and_package;
85 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 91 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
86 GetActionForTesting(external_url, handlers, kSelection, 92 GetActionForTesting(external_url, false, handlers, kSelection,
87 &url_and_package)); 93 &url_and_package));
88 EXPECT_EQ(external_url, url_and_package.first); 94 EXPECT_EQ(external_url, url_and_package.first);
89 EXPECT_EQ(package_name, url_and_package.second); 95 EXPECT_EQ(package_name, url_and_package.second);
90 } 96 }
91 97
92 // Tests the same as TestGetActionWithOnePreferredApp but with two apps. 98 // Tests the same as TestGetActionWithOnePreferredApp but with two apps.
93 TEST(ArcExternalProtocolDialogTest, 99 TEST(ArcExternalProtocolDialogTest,
94 TestGetActionWithOnePreferredAppAndOneOther) { 100 TestGetActionWithOnePreferredAppAndOneOther) {
95 const GURL external_url("external-protocol:foo"); 101 const GURL external_url("external-protocol:foo");
96 const std::string package_name("com.google.package2.name"); 102 const std::string package_name("com.google.package2.name");
97 103
98 std::vector<mojom::IntentHandlerInfoPtr> handlers; 104 std::vector<mojom::IntentHandlerInfoPtr> handlers;
99 handlers.push_back( 105 handlers.push_back(
100 Create("package", "com.google.package.name", false, GURL())); 106 Create("package", "com.google.package.name", false, GURL()));
101 handlers.push_back(Create("package2", package_name, true, GURL())); 107 handlers.push_back(Create("package2", package_name, true, GURL()));
102 108
103 const size_t no_selection = handlers.size(); 109 const size_t no_selection = handlers.size();
104 std::pair<GURL, std::string> url_and_package; 110 std::pair<GURL, std::string> url_and_package;
105 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 111 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
106 GetActionForTesting(external_url, handlers, no_selection, 112 GetActionForTesting(external_url, false, handlers, no_selection,
107 &url_and_package)); 113 &url_and_package));
108 EXPECT_EQ(external_url, url_and_package.first); 114 EXPECT_EQ(external_url, url_and_package.first);
109 EXPECT_EQ(package_name, url_and_package.second); 115 EXPECT_EQ(package_name, url_and_package.second);
110 } 116 }
111 117
112 // Tests that HANDLE_URL_IN_ARC is returned for geo: URL. The URL is special in 118 // Tests that HANDLE_URL_IN_ARC is returned for geo: URL. The URL is special in
113 // that intent_helper (i.e. the Chrome proxy) can handle it but Chrome cannot. 119 // that intent_helper (i.e. the Chrome proxy) can handle it but Chrome cannot.
114 // We have to send such a URL to intent_helper to let the helper rewrite the 120 // We have to send such a URL to intent_helper to let the helper rewrite the
115 // URL to https://maps.google.com/?latlon=xxx which Chrome can handle. 121 // URL to https://maps.google.com/?latlon=xxx which Chrome can handle.
116 TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrl) { 122 TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrl) {
117 const GURL geo_url("geo:37.7749,-122.4194"); 123 const GURL geo_url("geo:37.7749,-122.4194");
118 124
119 std::vector<mojom::IntentHandlerInfoPtr> handlers; 125 std::vector<mojom::IntentHandlerInfoPtr> handlers;
120 handlers.push_back(Create("Chrome", kChromePackageName, true, GURL())); 126 handlers.push_back(Create("Chrome", kChromePackageName, true, GURL()));
121 127
122 const size_t no_selection = handlers.size(); 128 const size_t no_selection = handlers.size();
123 std::pair<GURL, std::string> url_and_package; 129 std::pair<GURL, std::string> url_and_package;
124 EXPECT_EQ( 130 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
125 GetActionResult::HANDLE_URL_IN_ARC, 131 GetActionForTesting(geo_url, false, handlers, no_selection,
126 GetActionForTesting(geo_url, handlers, no_selection, &url_and_package)); 132 &url_and_package));
127 EXPECT_EQ(geo_url, url_and_package.first); 133 EXPECT_EQ(geo_url, url_and_package.first);
128 EXPECT_EQ(kChromePackageName, url_and_package.second); 134 EXPECT_EQ(kChromePackageName, url_and_package.second);
129 } 135 }
130 136
131 // Tests that OPEN_URL_IN_CHROME is returned when a handler with a fallback http 137 // Tests that OPEN_URL_IN_CHROME is returned when a handler with a fallback http
132 // URL and kChromePackageName is passed to GetAction, even if the handler is not 138 // URL and kChromePackageName is passed to GetAction, even if the handler is not
133 // a preferred one. 139 // a preferred one.
134 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneFallbackUrl) { 140 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneFallbackUrl) {
135 const GURL intent_url_with_fallback( 141 const GURL intent_url_with_fallback(
136 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 142 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
137 "S.browser_fallback_url=http://zxing.org;end"); 143 "S.browser_fallback_url=http://zxing.org;end");
138 const GURL fallback_url("http://zxing.org"); 144 const GURL fallback_url("http://zxing.org");
139 145
140 std::vector<mojom::IntentHandlerInfoPtr> handlers; 146 std::vector<mojom::IntentHandlerInfoPtr> handlers;
141 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url)); 147 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url));
142 148
143 const size_t no_selection = handlers.size(); 149 const size_t no_selection = handlers.size();
144 std::pair<GURL, std::string> url_and_package; 150 std::pair<GURL, std::string> url_and_package;
145 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME, 151 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME,
146 GetActionForTesting(intent_url_with_fallback, handlers, 152 GetActionForTesting(intent_url_with_fallback, false, handlers,
147 no_selection, &url_and_package)); 153 no_selection, &url_and_package));
148 EXPECT_EQ(fallback_url, url_and_package.first); 154 EXPECT_EQ(fallback_url, url_and_package.first);
149 EXPECT_EQ(kChromePackageName, url_and_package.second); 155 EXPECT_EQ(kChromePackageName, url_and_package.second);
150 } 156 }
151 157
152 // Tests the same with https and is_preferred == true. 158 // Tests the same with https and is_preferred == true.
153 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredFallbackUrl) { 159 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredFallbackUrl) {
154 const GURL intent_url_with_fallback( 160 const GURL intent_url_with_fallback(
155 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 161 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
156 "S.browser_fallback_url=https://zxing.org;end"); 162 "S.browser_fallback_url=https://zxing.org;end");
157 const GURL fallback_url("https://zxing.org"); 163 const GURL fallback_url("https://zxing.org");
158 164
159 std::vector<mojom::IntentHandlerInfoPtr> handlers; 165 std::vector<mojom::IntentHandlerInfoPtr> handlers;
160 handlers.push_back(Create("Chrome", kChromePackageName, true, fallback_url)); 166 handlers.push_back(Create("Chrome", kChromePackageName, true, fallback_url));
161 167
162 const size_t no_selection = handlers.size(); 168 const size_t no_selection = handlers.size();
163 std::pair<GURL, std::string> url_and_package; 169 std::pair<GURL, std::string> url_and_package;
164 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME, 170 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME,
165 GetActionForTesting(intent_url_with_fallback, handlers, 171 GetActionForTesting(intent_url_with_fallback, false, handlers,
166 no_selection, &url_and_package)); 172 no_selection, &url_and_package));
167 EXPECT_EQ(fallback_url, url_and_package.first); 173 EXPECT_EQ(fallback_url, url_and_package.first);
168 EXPECT_EQ(kChromePackageName, url_and_package.second); 174 EXPECT_EQ(kChromePackageName, url_and_package.second);
169 } 175 }
170 176
171 // Tests that ASK_USER is returned when two handlers with fallback URLs are 177 // Tests that ASK_USER is returned when two handlers with fallback URLs are
172 // passed to GetAction. This may happen when the user has installed a 3rd party 178 // passed to GetAction. This may happen when the user has installed a 3rd party
173 // browser app, and then clicks a intent: URI with a http fallback. 179 // browser app, and then clicks a intent: URI with a http fallback.
174 TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoFallbackUrls) { 180 TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoFallbackUrls) {
175 const GURL intent_url_with_fallback( 181 const GURL intent_url_with_fallback(
176 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 182 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
177 "S.browser_fallback_url=http://zxing.org;end"); 183 "S.browser_fallback_url=http://zxing.org;end");
178 const GURL fallback_url("http://zxing.org"); 184 const GURL fallback_url("http://zxing.org");
179 185
180 std::vector<mojom::IntentHandlerInfoPtr> handlers; 186 std::vector<mojom::IntentHandlerInfoPtr> handlers;
181 handlers.push_back( 187 handlers.push_back(
182 Create("Other browser", "com.other.browser", false, fallback_url)); 188 Create("Other browser", "com.other.browser", false, fallback_url));
183 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url)); 189 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url));
184 190
185 const size_t no_selection = handlers.size(); 191 const size_t no_selection = handlers.size();
186 std::pair<GURL, std::string> url_and_package; 192 std::pair<GURL, std::string> url_and_package;
187 EXPECT_EQ(GetActionResult::ASK_USER, 193 EXPECT_EQ(GetActionResult::ASK_USER,
188 GetActionForTesting(intent_url_with_fallback, handlers, 194 GetActionForTesting(intent_url_with_fallback, false, handlers,
189 no_selection, &url_and_package)); 195 no_selection, &url_and_package));
190 } 196 }
191 197
192 // Tests the same but set Chrome as a preferred app. In this case, ASK_USER 198 // Tests the same but set Chrome as a preferred app. In this case, ASK_USER
193 // shouldn't be returned. 199 // shouldn't be returned.
194 TEST(ArcExternalProtocolDialogTest, 200 TEST(ArcExternalProtocolDialogTest,
195 TestGetActionWithTwoFallbackUrlsChromePreferred) { 201 TestGetActionWithTwoFallbackUrlsChromePreferred) {
196 const GURL intent_url_with_fallback( 202 const GURL intent_url_with_fallback(
197 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 203 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
198 "S.browser_fallback_url=http://zxing.org;end"); 204 "S.browser_fallback_url=http://zxing.org;end");
199 const GURL fallback_url("http://zxing.org"); 205 const GURL fallback_url("http://zxing.org");
200 206
201 std::vector<mojom::IntentHandlerInfoPtr> handlers; 207 std::vector<mojom::IntentHandlerInfoPtr> handlers;
202 handlers.push_back( 208 handlers.push_back(
203 Create("Other browser", "com.other.browser", false, fallback_url)); 209 Create("Other browser", "com.other.browser", false, fallback_url));
204 handlers.push_back(Create("Chrome", kChromePackageName, true, fallback_url)); 210 handlers.push_back(Create("Chrome", kChromePackageName, true, fallback_url));
205 211
206 const size_t no_selection = handlers.size(); 212 const size_t no_selection = handlers.size();
207 std::pair<GURL, std::string> url_and_package; 213 std::pair<GURL, std::string> url_and_package;
208 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME, 214 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME,
209 GetActionForTesting(intent_url_with_fallback, handlers, 215 GetActionForTesting(intent_url_with_fallback, false, handlers,
210 no_selection, &url_and_package)); 216 no_selection, &url_and_package));
211 EXPECT_EQ(fallback_url, url_and_package.first); 217 EXPECT_EQ(fallback_url, url_and_package.first);
212 EXPECT_EQ(kChromePackageName, url_and_package.second); 218 EXPECT_EQ(kChromePackageName, url_and_package.second);
213 } 219 }
214 220
215 // Tests the same but set "other browser" as a preferred app. In this case, 221 // Tests the same but set "other browser" as a preferred app. In this case,
216 // ASK_USER shouldn't be returned either. 222 // ASK_USER shouldn't be returned either.
217 TEST(ArcExternalProtocolDialogTest, 223 TEST(ArcExternalProtocolDialogTest,
218 TestGetActionWithTwoFallbackUrlsOtherBrowserPreferred) { 224 TestGetActionWithTwoFallbackUrlsOtherBrowserPreferred) {
219 const GURL intent_url_with_fallback( 225 const GURL intent_url_with_fallback(
220 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 226 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
221 "S.browser_fallback_url=http://zxing.org;end"); 227 "S.browser_fallback_url=http://zxing.org;end");
222 const GURL fallback_url("http://zxing.org"); 228 const GURL fallback_url("http://zxing.org");
223 const std::string package_name = "com.other.browser"; 229 const std::string package_name = "com.other.browser";
224 230
225 std::vector<mojom::IntentHandlerInfoPtr> handlers; 231 std::vector<mojom::IntentHandlerInfoPtr> handlers;
226 handlers.push_back(Create("Other browser", package_name, true, fallback_url)); 232 handlers.push_back(Create("Other browser", package_name, true, fallback_url));
227 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url)); 233 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url));
228 234
229 const size_t no_selection = handlers.size(); 235 const size_t no_selection = handlers.size();
230 std::pair<GURL, std::string> url_and_package; 236 std::pair<GURL, std::string> url_and_package;
231 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 237 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
232 GetActionForTesting(intent_url_with_fallback, handlers, 238 GetActionForTesting(intent_url_with_fallback, false, handlers,
233 no_selection, &url_and_package)); 239 no_selection, &url_and_package));
234 EXPECT_EQ(fallback_url, url_and_package.first); 240 EXPECT_EQ(fallback_url, url_and_package.first);
235 EXPECT_EQ(package_name, url_and_package.second); 241 EXPECT_EQ(package_name, url_and_package.second);
236 } 242 }
237 243
238 // Tests the same but set Chrome as a user-selected app. 244 // Tests the same but set Chrome as a user-selected app.
239 TEST(ArcExternalProtocolDialogTest, 245 TEST(ArcExternalProtocolDialogTest,
240 TestGetActionWithTwoFallbackUrlsChromeSelected) { 246 TestGetActionWithTwoFallbackUrlsChromeSelected) {
241 const GURL intent_url_with_fallback( 247 const GURL intent_url_with_fallback(
242 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 248 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
243 "S.browser_fallback_url=http://zxing.org;end"); 249 "S.browser_fallback_url=http://zxing.org;end");
244 const GURL fallback_url("http://zxing.org"); 250 const GURL fallback_url("http://zxing.org");
245 251
246 std::vector<mojom::IntentHandlerInfoPtr> handlers; 252 std::vector<mojom::IntentHandlerInfoPtr> handlers;
247 handlers.push_back( 253 handlers.push_back(
248 Create("Other browser", "com.other.browser", false, fallback_url)); 254 Create("Other browser", "com.other.browser", false, fallback_url));
249 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url)); 255 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url));
250 256
251 constexpr size_t kSelection = 1; // Chrome 257 constexpr size_t kSelection = 1; // Chrome
252 std::pair<GURL, std::string> url_and_package; 258 std::pair<GURL, std::string> url_and_package;
253 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME, 259 EXPECT_EQ(GetActionResult::OPEN_URL_IN_CHROME,
254 GetActionForTesting(intent_url_with_fallback, handlers, kSelection, 260 GetActionForTesting(intent_url_with_fallback, false, handlers,
255 &url_and_package)); 261 kSelection, &url_and_package));
256 EXPECT_EQ(fallback_url, url_and_package.first); 262 EXPECT_EQ(fallback_url, url_and_package.first);
257 EXPECT_EQ(kChromePackageName, url_and_package.second); 263 EXPECT_EQ(kChromePackageName, url_and_package.second);
258 } 264 }
259 265
260 // Tests the same but set "other browser" as a preferred app. 266 // Tests the same but set "other browser" as a preferred app.
261 TEST(ArcExternalProtocolDialogTest, 267 TEST(ArcExternalProtocolDialogTest,
262 TestGetActionWithTwoFallbackUrlsOtherBrowserSelected) { 268 TestGetActionWithTwoFallbackUrlsOtherBrowserSelected) {
263 const GURL intent_url_with_fallback( 269 const GURL intent_url_with_fallback(
264 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 270 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
265 "S.browser_fallback_url=http://zxing.org;end"); 271 "S.browser_fallback_url=http://zxing.org;end");
266 const GURL fallback_url("http://zxing.org"); 272 const GURL fallback_url("http://zxing.org");
267 const std::string package_name = "com.other.browser"; 273 const std::string package_name = "com.other.browser";
268 274
269 std::vector<mojom::IntentHandlerInfoPtr> handlers; 275 std::vector<mojom::IntentHandlerInfoPtr> handlers;
270 handlers.push_back( 276 handlers.push_back(
271 Create("Other browser", package_name, false, fallback_url)); 277 Create("Other browser", package_name, false, fallback_url));
272 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url)); 278 handlers.push_back(Create("Chrome", kChromePackageName, false, fallback_url));
273 279
274 constexpr size_t kSelection = 0; // the other browser 280 constexpr size_t kSelection = 0; // the other browser
275 std::pair<GURL, std::string> url_and_package; 281 std::pair<GURL, std::string> url_and_package;
276 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 282 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
277 GetActionForTesting(intent_url_with_fallback, handlers, kSelection, 283 GetActionForTesting(intent_url_with_fallback, false, handlers,
278 &url_and_package)); 284 kSelection, &url_and_package));
279 EXPECT_EQ(fallback_url, url_and_package.first); 285 EXPECT_EQ(fallback_url, url_and_package.first);
280 EXPECT_EQ(package_name, url_and_package.second); 286 EXPECT_EQ(package_name, url_and_package.second);
281 } 287 }
282 288
283 // Tests that ASK_USER is returned when a handler with a fallback market: URL 289 // Tests that ASK_USER is returned when a handler with a fallback market: URL
284 // is passed to GetAction. 290 // is passed to GetAction.
285 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneMarketFallbackUrl) { 291 TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneMarketFallbackUrl) {
286 const GURL intent_url_with_fallback( 292 const GURL intent_url_with_fallback(
287 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 293 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
288 const GURL fallback_url("market://details?id=com.google.abc"); 294 const GURL fallback_url("market://details?id=com.google.abc");
289 295
290 std::vector<mojom::IntentHandlerInfoPtr> handlers; 296 std::vector<mojom::IntentHandlerInfoPtr> handlers;
291 handlers.push_back( 297 handlers.push_back(
292 Create("Play Store", "com.google.play.store", false, fallback_url)); 298 Create("Play Store", "com.google.play.store", false, fallback_url));
293 299
294 const size_t no_selection = handlers.size(); 300 const size_t no_selection = handlers.size();
295 std::pair<GURL, std::string> url_and_package; 301 std::pair<GURL, std::string> url_and_package;
296 EXPECT_EQ(GetActionResult::ASK_USER, 302 EXPECT_EQ(GetActionResult::ASK_USER,
297 GetActionForTesting(intent_url_with_fallback, handlers, 303 GetActionForTesting(intent_url_with_fallback, false, handlers,
298 no_selection, &url_and_package)); 304 no_selection, &url_and_package));
299 } 305 }
300 306
301 // Tests the same but with is_preferred == true. 307 // Tests the same but with is_preferred == true.
302 TEST(ArcExternalProtocolDialogTest, 308 TEST(ArcExternalProtocolDialogTest,
303 TestGetActionWithOnePreferredMarketFallbackUrl) { 309 TestGetActionWithOnePreferredMarketFallbackUrl) {
304 const GURL intent_url_with_fallback( 310 const GURL intent_url_with_fallback(
305 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 311 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
306 const GURL fallback_url("market://details?id=com.google.abc"); 312 const GURL fallback_url("market://details?id=com.google.abc");
307 const std::string play_store_package_name = "com.google.play.store"; 313 const std::string play_store_package_name = "com.google.play.store";
308 314
309 std::vector<mojom::IntentHandlerInfoPtr> handlers; 315 std::vector<mojom::IntentHandlerInfoPtr> handlers;
310 handlers.push_back( 316 handlers.push_back(
311 Create("Play Store", play_store_package_name, true, fallback_url)); 317 Create("Play Store", play_store_package_name, true, fallback_url));
312 318
313 const size_t no_selection = handlers.size(); 319 const size_t no_selection = handlers.size();
314 std::pair<GURL, std::string> url_and_package; 320 std::pair<GURL, std::string> url_and_package;
315 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 321 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
316 GetActionForTesting(intent_url_with_fallback, handlers, 322 GetActionForTesting(intent_url_with_fallback, false, handlers,
317 no_selection, &url_and_package)); 323 no_selection, &url_and_package));
318 EXPECT_EQ(fallback_url, url_and_package.first); 324 EXPECT_EQ(fallback_url, url_and_package.first);
319 EXPECT_EQ(play_store_package_name, url_and_package.second); 325 EXPECT_EQ(play_store_package_name, url_and_package.second);
326
327 // Test that when |always_ask_user| is true, the preferred app setting is
328 // ignored.
329 EXPECT_EQ(GetActionResult::ASK_USER,
330 GetActionForTesting(intent_url_with_fallback, true, handlers,
331 no_selection, &url_and_package));
320 } 332 }
321 333
322 // Tests the same but with an app_seleteced_index. 334 // Tests the same but with an app_seleteced_index.
323 TEST(ArcExternalProtocolDialogTest, 335 TEST(ArcExternalProtocolDialogTest,
324 TestGetActionWithOneSelectedMarketFallbackUrl) { 336 TestGetActionWithOneSelectedMarketFallbackUrl) {
325 const GURL intent_url_with_fallback( 337 const GURL intent_url_with_fallback(
326 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 338 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
327 const GURL fallback_url("market://details?id=com.google.abc"); 339 const GURL fallback_url("market://details?id=com.google.abc");
328 const std::string play_store_package_name = "com.google.play.store"; 340 const std::string play_store_package_name = "com.google.play.store";
329 341
330 std::vector<mojom::IntentHandlerInfoPtr> handlers; 342 std::vector<mojom::IntentHandlerInfoPtr> handlers;
331 handlers.push_back( 343 handlers.push_back(
332 Create("Play Store", play_store_package_name, false, fallback_url)); 344 Create("Play Store", play_store_package_name, false, fallback_url));
333 345
334 constexpr size_t kSelection = 0; 346 constexpr size_t kSelection = 0;
335 std::pair<GURL, std::string> url_and_package; 347 std::pair<GURL, std::string> url_and_package;
336 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 348 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
337 GetActionForTesting(intent_url_with_fallback, handlers, kSelection, 349 GetActionForTesting(intent_url_with_fallback, false, handlers,
338 &url_and_package)); 350 kSelection, &url_and_package));
339 EXPECT_EQ(fallback_url, url_and_package.first); 351 EXPECT_EQ(fallback_url, url_and_package.first);
340 EXPECT_EQ(play_store_package_name, url_and_package.second); 352 EXPECT_EQ(play_store_package_name, url_and_package.second);
341 } 353 }
342 354
343 // Tests that ASK_USER is returned when two handlers with fallback market: URLs 355 // Tests that ASK_USER is returned when two handlers with fallback market: URLs
344 // are passed to GetAction. Unlike the two browsers case, this rarely happens on 356 // are passed to GetAction. Unlike the two browsers case, this rarely happens on
345 // the user's device, though. 357 // the user's device, though.
346 TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoMarketFallbackUrls) { 358 TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoMarketFallbackUrls) {
347 const GURL intent_url_with_fallback( 359 const GURL intent_url_with_fallback(
348 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 360 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
349 const GURL fallback_url("market://details?id=com.google.abc"); 361 const GURL fallback_url("market://details?id=com.google.abc");
350 362
351 std::vector<mojom::IntentHandlerInfoPtr> handlers; 363 std::vector<mojom::IntentHandlerInfoPtr> handlers;
352 handlers.push_back( 364 handlers.push_back(
353 Create("Play Store", "com.google.play.store", false, fallback_url)); 365 Create("Play Store", "com.google.play.store", false, fallback_url));
354 handlers.push_back( 366 handlers.push_back(
355 Create("Other Store app", "com.other.play.store", false, fallback_url)); 367 Create("Other Store app", "com.other.play.store", false, fallback_url));
356 368
357 const size_t no_selection = handlers.size(); 369 const size_t no_selection = handlers.size();
358 std::pair<GURL, std::string> url_and_package; 370 std::pair<GURL, std::string> url_and_package;
359 EXPECT_EQ(GetActionResult::ASK_USER, 371 EXPECT_EQ(GetActionResult::ASK_USER,
360 GetActionForTesting(intent_url_with_fallback, handlers, 372 GetActionForTesting(intent_url_with_fallback, false, handlers,
361 no_selection, &url_and_package)); 373 no_selection, &url_and_package));
362 } 374 }
363 375
364 // Tests the same, but make the second handler a preferred one. 376 // Tests the same, but make the second handler a preferred one.
365 TEST(ArcExternalProtocolDialogTest, 377 TEST(ArcExternalProtocolDialogTest,
366 TestGetActionWithTwoMarketFallbackUrlsOnePreferred) { 378 TestGetActionWithTwoMarketFallbackUrlsOnePreferred) {
367 const GURL intent_url_with_fallback( 379 const GURL intent_url_with_fallback(
368 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 380 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
369 const GURL fallback_url("market://details?id=com.google.abc"); 381 const GURL fallback_url("market://details?id=com.google.abc");
370 const std::string play_store_package_name = "com.google.play.store"; 382 const std::string play_store_package_name = "com.google.play.store";
371 383
372 std::vector<mojom::IntentHandlerInfoPtr> handlers; 384 std::vector<mojom::IntentHandlerInfoPtr> handlers;
373 handlers.push_back( 385 handlers.push_back(
374 Create("Other Store app", "com.other.play.store", false, fallback_url)); 386 Create("Other Store app", "com.other.play.store", false, fallback_url));
375 handlers.push_back( 387 handlers.push_back(
376 Create("Play Store", play_store_package_name, true, fallback_url)); 388 Create("Play Store", play_store_package_name, true, fallback_url));
377 389
378 const size_t no_selection = handlers.size(); 390 const size_t no_selection = handlers.size();
379 std::pair<GURL, std::string> url_and_package; 391 std::pair<GURL, std::string> url_and_package;
380 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 392 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
381 GetActionForTesting(intent_url_with_fallback, handlers, 393 GetActionForTesting(intent_url_with_fallback, false, handlers,
382 no_selection, &url_and_package)); 394 no_selection, &url_and_package));
383 EXPECT_EQ(fallback_url, url_and_package.first); 395 EXPECT_EQ(fallback_url, url_and_package.first);
384 EXPECT_EQ(play_store_package_name, url_and_package.second); 396 EXPECT_EQ(play_store_package_name, url_and_package.second);
385 } 397 }
386 398
387 // Tests the same, but make the second handler a selected one. 399 // Tests the same, but make the second handler a selected one.
388 TEST(ArcExternalProtocolDialogTest, 400 TEST(ArcExternalProtocolDialogTest,
389 TestGetActionWithTwoMarketFallbackUrlsOneSelected) { 401 TestGetActionWithTwoMarketFallbackUrlsOneSelected) {
390 const GURL intent_url_with_fallback( 402 const GURL intent_url_with_fallback(
391 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end"); 403 "intent://scan/#Intent;scheme=abc;package=com.google.abc;end");
392 const GURL fallback_url("market://details?id=com.google.abc"); 404 const GURL fallback_url("market://details?id=com.google.abc");
393 const std::string play_store_package_name = "com.google.play.store"; 405 const std::string play_store_package_name = "com.google.play.store";
394 406
395 std::vector<mojom::IntentHandlerInfoPtr> handlers; 407 std::vector<mojom::IntentHandlerInfoPtr> handlers;
396 handlers.push_back( 408 handlers.push_back(
397 Create("Other Store app", "com.other.play.store", false, fallback_url)); 409 Create("Other Store app", "com.other.play.store", false, fallback_url));
398 handlers.push_back( 410 handlers.push_back(
399 Create("Play Store", play_store_package_name, false, fallback_url)); 411 Create("Play Store", play_store_package_name, false, fallback_url));
400 412
401 const size_t kSelection = 1; // Play Store 413 const size_t kSelection = 1; // Play Store
402 std::pair<GURL, std::string> url_and_package; 414 std::pair<GURL, std::string> url_and_package;
403 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 415 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
404 GetActionForTesting(intent_url_with_fallback, handlers, kSelection, 416 GetActionForTesting(intent_url_with_fallback, false, handlers,
405 &url_and_package)); 417 kSelection, &url_and_package));
406 EXPECT_EQ(fallback_url, url_and_package.first); 418 EXPECT_EQ(fallback_url, url_and_package.first);
407 EXPECT_EQ(play_store_package_name, url_and_package.second); 419 EXPECT_EQ(play_store_package_name, url_and_package.second);
408 } 420 }
409 421
410 // Tests the case where geo: URL is returned as a fallback. This should never 422 // Tests the case where geo: URL is returned as a fallback. This should never
411 // happen because intent_helper ignores such a fallback, but just in case. 423 // happen because intent_helper ignores such a fallback, but just in case.
412 // GetAction shouldn't crash at least. 424 // GetAction shouldn't crash at least.
413 TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrlAsFallback) { 425 TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrlAsFallback) {
414 // Note: geo: as a browser fallback is banned in the production code. 426 // Note: geo: as a browser fallback is banned in the production code.
415 const GURL intent_url_with_fallback( 427 const GURL intent_url_with_fallback(
416 "intent://scan/#Intent;scheme=abc;package=com.google.abc;" 428 "intent://scan/#Intent;scheme=abc;package=com.google.abc;"
417 "S.browser_fallback_url=geo:37.7749,-122.4194;end"); 429 "S.browser_fallback_url=geo:37.7749,-122.4194;end");
418 const GURL geo_url("geo:37.7749,-122.4194"); 430 const GURL geo_url("geo:37.7749,-122.4194");
419 431
420 std::vector<mojom::IntentHandlerInfoPtr> handlers; 432 std::vector<mojom::IntentHandlerInfoPtr> handlers;
421 handlers.push_back(Create("Chrome", kChromePackageName, true, geo_url)); 433 handlers.push_back(Create("Chrome", kChromePackageName, true, geo_url));
422 434
423 const size_t no_selection = handlers.size(); 435 const size_t no_selection = handlers.size();
424 std::pair<GURL, std::string> url_and_package; 436 std::pair<GURL, std::string> url_and_package;
425 // GetAction shouldn't return OPEN_URL_IN_CHROME because Chrome doesn't 437 // GetAction shouldn't return OPEN_URL_IN_CHROME because Chrome doesn't
426 // directly support geo:. 438 // directly support geo:.
427 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC, 439 EXPECT_EQ(GetActionResult::HANDLE_URL_IN_ARC,
428 GetActionForTesting(intent_url_with_fallback, handlers, 440 GetActionForTesting(intent_url_with_fallback, false, handlers,
429 no_selection, &url_and_package)); 441 no_selection, &url_and_package));
430 EXPECT_EQ(geo_url, url_and_package.first); 442 EXPECT_EQ(geo_url, url_and_package.first);
431 EXPECT_EQ(kChromePackageName, url_and_package.second); 443 EXPECT_EQ(kChromePackageName, url_and_package.second);
432 } 444 }
433 445
434 // Test that GetUrlToNavigateOnDeactivate returns an empty GURL when |handlers| 446 // Test that GetUrlToNavigateOnDeactivate returns an empty GURL when |handlers|
435 // is empty. 447 // is empty.
436 TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateEmpty) { 448 TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateEmpty) {
437 std::vector<mojom::IntentHandlerInfoPtr> handlers; 449 std::vector<mojom::IntentHandlerInfoPtr> handlers;
438 EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers)); 450 EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 handlers.push_back( 511 handlers.push_back(
500 Create("Chrome", kChromePackageName, false, GURL("https://www2/"))); 512 Create("Chrome", kChromePackageName, false, GURL("https://www2/")));
501 handlers.push_back(Create("Yet another browser app", 513 handlers.push_back(Create("Yet another browser app",
502 "yet.another.browser.app.package", false, 514 "yet.another.browser.app.package", false,
503 GURL("https://www3/"))); 515 GURL("https://www3/")));
504 516
505 EXPECT_EQ(GURL("https://www2/"), 517 EXPECT_EQ(GURL("https://www2/"),
506 GetUrlToNavigateOnDeactivateForTesting(handlers)); 518 GetUrlToNavigateOnDeactivateForTesting(handlers));
507 } 519 }
508 520
521 // Tests that IsSafeToRedirectToArcWithoutUserConfirmation works as expected.
522 TEST(ArcExternalProtocolDialogTest,
523 TestIsSafeToRedirectToArcWithoutUserConfirmation) {
524 const GURL url_a_foo("scheme-a://foo");
525 const GURL url_a_bar("scheme-a://bar");
526 const GURL url_b_foo("scheme-b://foo");
527 const ui::PageTransition not_from_api = ui::PAGE_TRANSITION_LINK;
528 const ui::PageTransition from_api = ui::PageTransitionFromInt(
529 ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FROM_API);
530
531 // When last_* parameters are empty, the function should return true ("safe").
532 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
533 url_a_foo, from_api, GURL(), ui::PageTransition()));
534 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
535 url_a_foo, not_from_api, GURL(), ui::PageTransition()));
536 // When the previous navigation is not from API, it should return true.
537 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
538 url_a_foo, from_api, url_a_foo, not_from_api));
539 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
540 url_a_foo, not_from_api, url_a_foo, not_from_api));
541 // When the current navigation is not from API, it should return true.
542 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
543 url_a_foo, not_from_api, url_a_foo, from_api));
544 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
545 url_a_foo, not_from_api, url_a_foo, not_from_api));
546 // When the current navigation is for a different app than the previous
547 // navigation's, it should return true.
548 EXPECT_TRUE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
549 url_a_foo, from_api, url_b_foo, from_api));
550 // When the current and previous navigations are for the same app, and both
551 // are from API, it should return false ("possibly unsafe").
552 EXPECT_FALSE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
553 url_a_foo, from_api, url_a_foo, from_api));
554 EXPECT_FALSE(IsSafeToRedirectToArcWithoutUserConfirmationForTesting(
555 url_a_foo, from_api, url_a_bar, from_api));
556 }
557
509 } // namespace arc 558 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698