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

Side by Side Diff: ios/chrome/app/chrome_app_startup_parameters_unittest.mm

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: 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
« no previous file with comments | « ios/chrome/app/chrome_app_startup_parameters.mm ('k') | ios/chrome/app/chrome_exe_main.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/app/chrome_app_startup_parameters.h"
6
7 #include <Foundation/Foundation.h>
8
9 #include "base/mac/scoped_nsobject.h"
10 #include "base/strings/stringprintf.h"
11 #include "ios/chrome/browser/app_startup_parameters.h"
12 #include "ios/chrome/browser/chrome_url_constants.h"
13 #import "ios/chrome/browser/xcallback_parameters.h"
14 #include "ios/chrome/common/app_group/app_group_constants.h"
15 #include "testing/gtest_mac.h"
16 #include "testing/platform_test.h"
17 #include "url/gurl.h"
18
19 namespace {
20 void CheckLaunchSourceForURL(first_run::ExternalLaunch expectedSource,
21 NSString* urlString) {
22 NSURL* url = [NSURL URLWithString:urlString];
23 base::scoped_nsobject<ChromeAppStartupParameters> params(
24 [ChromeAppStartupParameters
25 newChromeAppStartupParametersWithURL:url
26 fromSourceApplication:@"com.apple.mobilesafari"]);
27 EXPECT_EQ(expectedSource, [params launchSource]);
28 }
29
30 typedef PlatformTest AppStartupParametersTest;
31 TEST_F(PlatformTest, ParseURLWithEmptyURL) {
32 NSURL* url = [NSURL URLWithString:@""];
33 base::scoped_nsobject<ChromeAppStartupParameters> params(
34 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
35 fromSourceApplication:nil]);
36
37 EXPECT_FALSE(params);
38 }
39
40 TEST_F(AppStartupParametersTest, ParseURLWithOneProtocol) {
41 NSURL* url = [NSURL URLWithString:@"protocol://www.google.com"];
42 base::scoped_nsobject<ChromeAppStartupParameters> params(
43 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
44 fromSourceApplication:nil]);
45 // Here "protocol" opens the app and no protocol is given for the parsed URL,
46 // which defaults to be "http".
47 EXPECT_EQ("http://www.google.com/", [params externalURL].spec());
48 }
49
50 TEST_F(AppStartupParametersTest, ParseURLWithEmptyParsedURL) {
51 // Test chromium://
52 NSURL* url = [NSURL URLWithString:@"chromium://"];
53 base::scoped_nsobject<ChromeAppStartupParameters> params(
54 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
55 fromSourceApplication:nil]);
56
57 EXPECT_FALSE(params);
58 }
59
60 TEST_F(AppStartupParametersTest, ParseURLWithParsedURLDefaultToHttp) {
61 NSURL* url = [NSURL URLWithString:@"chromium://www.google.com"];
62 base::scoped_nsobject<ChromeAppStartupParameters> params(
63 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
64 fromSourceApplication:nil]);
65
66 EXPECT_EQ("http://www.google.com/", [params externalURL].spec());
67 }
68
69 TEST_F(AppStartupParametersTest, ParseURLWithInvalidParsedURL) {
70 NSURL* url = [NSURL URLWithString:@"http:google.com:foo"];
71 base::scoped_nsobject<ChromeAppStartupParameters> params(
72 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
73 fromSourceApplication:nil]);
74
75 EXPECT_FALSE(params);
76 }
77
78 TEST_F(AppStartupParametersTest, ParseURLWithHttpsParsedURL) {
79 NSURL* url = [NSURL URLWithString:@"chromiums://www.google.com"];
80 base::scoped_nsobject<ChromeAppStartupParameters> params(
81 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
82 fromSourceApplication:nil]);
83
84 EXPECT_EQ("https://www.google.com/", [params externalURL].spec());
85 }
86
87 TEST_F(AppStartupParametersTest, ParseURLWithXCallbackURL) {
88 NSURL* url =
89 [NSURL URLWithString:@"chromium-x-callback://x-callback-url/open?"
90 "url=https://www.google.com"];
91 base::scoped_nsobject<ChromeAppStartupParameters> params(
92 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
93 fromSourceApplication:nil]);
94 EXPECT_EQ("https://www.google.com/", [params externalURL].spec());
95 }
96
97 TEST_F(AppStartupParametersTest, ParseURLWithXCallbackURLAndExtraParams) {
98 NSURL* url =
99 [NSURL URLWithString:@"chromium-x-callback://x-callback-url/open?"
100 "url=https://www.google.com&"
101 "x-success=http://success"];
102 base::scoped_nsobject<ChromeAppStartupParameters> params(
103 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
104 fromSourceApplication:nil]);
105 EXPECT_EQ("https://www.google.com/", [params externalURL].spec());
106 }
107
108 TEST_F(AppStartupParametersTest, ParseURLWithMalformedXCallbackURL) {
109 NSURL* url = [NSURL
110 URLWithString:@"chromium-x-callback://x-callback-url/open?url=foobar&"
111 "x-source=myapp&x-success=http://success"];
112 base::scoped_nsobject<ChromeAppStartupParameters> params(
113 [ChromeAppStartupParameters
114 newChromeAppStartupParametersWithURL:url
115 fromSourceApplication:@"com.myapp"]);
116 EXPECT_FALSE(params);
117 }
118
119 TEST_F(AppStartupParametersTest, ParseURLWithJavascriptURLInXCallbackURL) {
120 NSURL* url = [NSURL
121 URLWithString:
122 @"chromium-x-callback://x-callback-url/open?url="
123 "javascript:window.open()&x-source=myapp&x-success=http://success"];
124 base::scoped_nsobject<ChromeAppStartupParameters> params(
125 [ChromeAppStartupParameters
126 newChromeAppStartupParametersWithURL:url
127 fromSourceApplication:@"com.myapp"]);
128 EXPECT_FALSE(params);
129 }
130
131 TEST_F(AppStartupParametersTest, ParseURLWithChromeURLInXCallbackURL) {
132 NSURL* url =
133 [NSURL URLWithString:@"chromium-x-callback://x-callback-url/open?url="
134 "chrome:passwords"];
135 base::scoped_nsobject<ChromeAppStartupParameters> params(
136 [ChromeAppStartupParameters
137 newChromeAppStartupParametersWithURL:url
138 fromSourceApplication:@"com.myapp"]);
139 EXPECT_FALSE(params);
140 }
141
142 TEST_F(AppStartupParametersTest, ParseURLWithFileParsedURL) {
143 NSURL* url = [NSURL URLWithString:@"file://localhost/path/to/file.pdf"];
144 base::scoped_nsobject<ChromeAppStartupParameters> params(
145 [ChromeAppStartupParameters newChromeAppStartupParametersWithURL:url
146 fromSourceApplication:nil]);
147
148 std::string expectedUrlString = base::StringPrintf(
149 "%s://%s/file.pdf", kChromeUIScheme, kChromeUIExternalFileHost);
150
151 EXPECT_EQ(expectedUrlString, [params externalURL].spec());
152 }
153
154 TEST_F(AppStartupParametersTest, ParseURLWithAppGroupVoiceSearch) {
155 base::scoped_nsobject<ChromeAppStartupParameters> params(
156 [ChromeAppStartupParameters
157 newAppStartupParametersForCommand:@"voicesearch"
158 withParameter:nil
159 withURL:nil
160 fromSourceApplication:nil
161 fromSecureSourceApplication:nil]);
162
163 std::string expectedUrlString =
164 base::StringPrintf("%s://%s/", kChromeUIScheme, kChromeUINewTabHost);
165
166 EXPECT_EQ(expectedUrlString, [params externalURL].spec());
167 EXPECT_TRUE([params launchVoiceSearch]);
168 }
169
170 TEST_F(AppStartupParametersTest, ParseURLWithAppGroupNewTab) {
171 base::scoped_nsobject<ChromeAppStartupParameters> params(
172 [ChromeAppStartupParameters newAppStartupParametersForCommand:@"newtab"
173 withParameter:nil
174 withURL:nil
175 fromSourceApplication:nil
176 fromSecureSourceApplication:nil]);
177 std::string expectedUrlString =
178 base::StringPrintf("%s://%s/", kChromeUIScheme, kChromeUINewTabHost);
179
180 EXPECT_EQ(expectedUrlString, [params externalURL].spec());
181 EXPECT_FALSE([params launchVoiceSearch]);
182 }
183
184 TEST_F(AppStartupParametersTest, ParseURLWithAppGroupOpenURL) {
185 base::scoped_nsobject<ChromeAppStartupParameters> params(
186 [ChromeAppStartupParameters
187 newAppStartupParametersForCommand:@"openurl"
188 withParameter:@"http://foo/bar"
189 withURL:nil
190 fromSourceApplication:nil
191 fromSecureSourceApplication:nil]);
192
193 EXPECT_EQ("http://foo/bar", [params externalURL].spec());
194 }
195
196 TEST_F(AppStartupParametersTest, ParseURLWithAppGroupGarbage) {
197 base::scoped_nsobject<ChromeAppStartupParameters> params(
198 [ChromeAppStartupParameters newAppStartupParametersForCommand:@"garbage"
199 withParameter:nil
200 withURL:nil
201 fromSourceApplication:nil
202 fromSecureSourceApplication:nil]);
203 EXPECT_FALSE(params);
204 }
205
206 TEST_F(AppStartupParametersTest, FirstRunExternalLaunchSource) {
207 // Key at the beginning of query string.
208 CheckLaunchSourceForURL(
209 first_run::LAUNCH_BY_SMARTAPPBANNER,
210 @"http://www.google.com/search?safarisab=1&query=pony");
211 // Key at the end of query string.
212 CheckLaunchSourceForURL(
213 first_run::LAUNCH_BY_SMARTAPPBANNER,
214 @"http://www.google.com/search?query=pony&safarisab=1");
215 // Key in the middle of query string.
216 CheckLaunchSourceForURL(
217 first_run::LAUNCH_BY_SMARTAPPBANNER,
218 @"http://www.google.com/search?query=pony&safarisab=1&hl=en");
219 // Key without '=' sign at the beginning, end, and middle of query string.
220 CheckLaunchSourceForURL(first_run::LAUNCH_BY_SMARTAPPBANNER,
221 @"http://www.google.com/search?safarisab&query=pony");
222 CheckLaunchSourceForURL(first_run::LAUNCH_BY_SMARTAPPBANNER,
223 @"http://www.google.com/search?query=pony&safarisab");
224 CheckLaunchSourceForURL(
225 first_run::LAUNCH_BY_SMARTAPPBANNER,
226 @"http://www.google.com/search?query=pony&safarisab&hl=en");
227 // No query string in URL.
228 CheckLaunchSourceForURL(first_run::LAUNCH_BY_MOBILESAFARI,
229 @"http://www.google.com/");
230 CheckLaunchSourceForURL(first_run::LAUNCH_BY_MOBILESAFARI,
231 @"http://www.google.com/safarisab/foo/bar");
232 // Key not present in query string.
233 CheckLaunchSourceForURL(first_run::LAUNCH_BY_MOBILESAFARI,
234 @"http://www.google.com/search?query=pony");
235 // Key is a substring of some other string.
236 CheckLaunchSourceForURL(
237 first_run::LAUNCH_BY_MOBILESAFARI,
238 @"http://www.google.com/search?query=pony&safarisabcdefg=1");
239 CheckLaunchSourceForURL(
240 first_run::LAUNCH_BY_MOBILESAFARI,
241 @"http://www.google.com/search?query=pony&notsafarisab=1&abc=def");
242 }
243
244 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/app/chrome_app_startup_parameters.mm ('k') | ios/chrome/app/chrome_exe_main.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698