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

Side by Side Diff: chrome/browser/google/google_util_unittest.cc

Issue 17022004: Replace --google-base-suggest-url and --instant-url with --google-base-url. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/google/google_url_tracker.h" 6 #include "chrome/browser/google/google_url_tracker.h"
8 #include "chrome/browser/google/google_util.h" 7 #include "chrome/browser/google/google_util.h"
9 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 using google_util::IsGoogleDomainUrl; 11 using google_util::IsGoogleDomainUrl;
13 using google_util::IsGoogleHomePageUrl; 12
14 using google_util::IsGoogleSearchUrl; 13
14 // Helpers --------------------------------------------------------------------
Jered 2013/06/26 00:32:16 Omit the ------- stuff here and below.
Peter Kasting 2013/06/26 00:40:27 This is how we separate sections of files in a lar
15
16 namespace {
17
18 // These functions merely provide brevity in the callers.
19
20 bool IsHomePage(const std::string& url) {
21 return google_util::IsGoogleHomePageUrl(GURL(url));
22 }
23
24 bool IsSearch(const std::string& url) {
25 return google_util::IsGoogleSearchUrl(GURL(url));
26 }
27
28 bool StartsWithBaseURL(const std::string& url) {
29 return google_util::StartsWithCommandLineGoogleBaseURL(GURL(url));
30 }
31
32 } // namespace
33
34
35 // Actual tests ---------------------------------------------------------------
15 36
16 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { 37 TEST(GoogleUtilTest, GoodHomePagesNonSecure) {
17 // Valid home page hosts. 38 // Valid home page hosts.
18 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); 39 EXPECT_TRUE(IsHomePage(GoogleURLTracker::kDefaultGoogleHomepage));
19 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); 40 EXPECT_TRUE(IsHomePage("http://google.com"));
20 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); 41 EXPECT_TRUE(IsHomePage("http://www.google.com"));
21 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); 42 EXPECT_TRUE(IsHomePage("http://www.google.ca"));
22 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); 43 EXPECT_TRUE(IsHomePage("http://www.google.co.uk"));
23 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); 44 EXPECT_TRUE(IsHomePage("http://www.google.com:80/"));
24 45
25 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are 46 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are
26 // ignored. 47 // ignored.
27 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/")); 48 EXPECT_TRUE(IsHomePage("http://www.google.com/"));
28 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp")); 49 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp"));
29 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp?rlz=TEST")); 50 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp?rlz=TEST"));
30 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig")); 51 EXPECT_TRUE(IsHomePage("http://www.google.com/ig"));
31 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo")); 52 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo"));
32 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig?rlz=TEST")); 53 EXPECT_TRUE(IsHomePage("http://www.google.com/ig?rlz=TEST"));
33 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo?rlz=TEST")); 54 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo?rlz=TEST"));
34 } 55 }
35 56
36 TEST(GoogleUtilTest, GoodHomePagesSecure) { 57 TEST(GoogleUtilTest, GoodHomePagesSecure) {
37 // Valid home page hosts. 58 // Valid home page hosts.
38 EXPECT_TRUE(IsGoogleHomePageUrl("https://google.com")); 59 EXPECT_TRUE(IsHomePage("https://google.com"));
39 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com")); 60 EXPECT_TRUE(IsHomePage("https://www.google.com"));
40 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.ca")); 61 EXPECT_TRUE(IsHomePage("https://www.google.ca"));
41 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.co.uk")); 62 EXPECT_TRUE(IsHomePage("https://www.google.co.uk"));
42 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com:443/")); 63 EXPECT_TRUE(IsHomePage("https://www.google.com:443/"));
43 64
44 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are 65 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are
45 // ignored. 66 // ignored.
46 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/")); 67 EXPECT_TRUE(IsHomePage("https://www.google.com/"));
47 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp")); 68 EXPECT_TRUE(IsHomePage("https://www.google.com/webhp"));
48 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp?rlz=TEST")); 69 EXPECT_TRUE(IsHomePage("https://www.google.com/webhp?rlz=TEST"));
49 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig")); 70 EXPECT_TRUE(IsHomePage("https://www.google.com/ig"));
50 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo")); 71 EXPECT_TRUE(IsHomePage("https://www.google.com/ig/foo"));
51 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig?rlz=TEST")); 72 EXPECT_TRUE(IsHomePage("https://www.google.com/ig?rlz=TEST"));
52 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo?rlz=TEST")); 73 EXPECT_TRUE(IsHomePage("https://www.google.com/ig/foo?rlz=TEST"));
53 } 74 }
54 75
55 TEST(GoogleUtilTest, BadHomePages) { 76 TEST(GoogleUtilTest, BadHomePages) {
56 EXPECT_FALSE(IsGoogleHomePageUrl(std::string())); 77 EXPECT_FALSE(IsHomePage(std::string()));
57 78
58 // If specified, only the "www" subdomain is OK. 79 // If specified, only the "www" subdomain is OK.
59 EXPECT_FALSE(IsGoogleHomePageUrl("http://maps.google.com")); 80 EXPECT_FALSE(IsHomePage("http://maps.google.com"));
60 EXPECT_FALSE(IsGoogleHomePageUrl("http://foo.google.com")); 81 EXPECT_FALSE(IsHomePage("http://foo.google.com"));
61 82
62 // No non-standard port numbers. 83 // No non-standard port numbers.
63 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com:1234")); 84 EXPECT_FALSE(IsHomePage("http://www.google.com:1234"));
64 EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com:5678")); 85 EXPECT_FALSE(IsHomePage("https://www.google.com:5678"));
65 86
66 // Invalid TLDs. 87 // Invalid TLDs.
67 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc")); 88 EXPECT_FALSE(IsHomePage("http://www.google.abc"));
68 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com.abc")); 89 EXPECT_FALSE(IsHomePage("http://www.google.com.abc"));
69 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc.com")); 90 EXPECT_FALSE(IsHomePage("http://www.google.abc.com"));
70 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.ab.cd")); 91 EXPECT_FALSE(IsHomePage("http://www.google.ab.cd"));
71 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.uk.qq")); 92 EXPECT_FALSE(IsHomePage("http://www.google.uk.qq"));
72 93
73 // Must be http or https. 94 // Must be http or https.
74 EXPECT_FALSE(IsGoogleHomePageUrl("ftp://www.google.com")); 95 EXPECT_FALSE(IsHomePage("ftp://www.google.com"));
75 EXPECT_FALSE(IsGoogleHomePageUrl("file://does/not/exist")); 96 EXPECT_FALSE(IsHomePage("file://does/not/exist"));
76 EXPECT_FALSE(IsGoogleHomePageUrl("bad://www.google.com")); 97 EXPECT_FALSE(IsHomePage("bad://www.google.com"));
77 EXPECT_FALSE(IsGoogleHomePageUrl("www.google.com")); 98 EXPECT_FALSE(IsHomePage("www.google.com"));
78 99
79 // Only the paths /, /webhp, and /ig.* are valid. 100 // Only the paths /, /webhp, and /ig.* are valid.
80 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abc")); 101 EXPECT_FALSE(IsHomePage("http://www.google.com/abc"));
81 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhpabc")); 102 EXPECT_FALSE(IsHomePage("http://www.google.com/webhpabc"));
82 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/abc")); 103 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/abc"));
83 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abcig")); 104 EXPECT_FALSE(IsHomePage("http://www.google.com/abcig"));
84 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/ig")); 105 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/ig"));
85 106
86 // A search URL should not be identified as a home page URL. 107 // A search URL should not be identified as a home page URL.
87 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/search?q=something")); 108 EXPECT_FALSE(IsHomePage("http://www.google.com/search?q=something"));
88 109
89 // Path is case sensitive. 110 // Path is case sensitive.
90 EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com/WEBHP")); 111 EXPECT_FALSE(IsHomePage("https://www.google.com/WEBHP"));
91 } 112 }
92 113
93 TEST(GoogleUtilTest, GoodSearchPagesNonSecure) { 114 TEST(GoogleUtilTest, GoodSearchPagesNonSecure) {
94 // Queries with path "/search" need to have the query parameter in either 115 // Queries with path "/search" need to have the query parameter in either
95 // the url parameter or the hash fragment. 116 // the url parameter or the hash fragment.
96 EXPECT_TRUE(IsGoogleSearchUrl( 117 EXPECT_TRUE(IsSearch("http://www.google.com/search?q=something"));
97 "http://www.google.com/search?q=something")); 118 EXPECT_TRUE(IsSearch("http://www.google.com/search#q=something"));
98 EXPECT_TRUE(IsGoogleSearchUrl( 119 EXPECT_TRUE(IsSearch("http://www.google.com/search?name=bob&q=something"));
99 "http://www.google.com/search#q=something")); 120 EXPECT_TRUE(IsSearch("http://www.google.com/search?name=bob#q=something"));
100 EXPECT_TRUE(IsGoogleSearchUrl( 121 EXPECT_TRUE(IsSearch("http://www.google.com/search?name=bob#age=24&q=thing"));
101 "http://www.google.com/search?name=bob&q=something")); 122 EXPECT_TRUE(IsSearch("http://www.google.co.uk/search?q=something"));
102 EXPECT_TRUE(IsGoogleSearchUrl(
103 "http://www.google.com/search?name=bob#q=something"));
104 EXPECT_TRUE(IsGoogleSearchUrl(
105 "http://www.google.com/search?name=bob#age=24&q=something"));
106 EXPECT_TRUE(IsGoogleSearchUrl(
107 "http://www.google.co.uk/search?q=something"));
108 // It's actually valid for both to have the query parameter. 123 // It's actually valid for both to have the query parameter.
109 EXPECT_TRUE(IsGoogleSearchUrl( 124 EXPECT_TRUE(IsSearch("http://www.google.com/search?q=something#q=other"));
110 "http://www.google.com/search?q=something#q=other"));
111 125
112 // Queries with path "/webhp", "/" or "" need to have the query parameter in 126 // Queries with path "/webhp", "/" or "" need to have the query parameter in
113 // the hash fragment. 127 // the hash fragment.
114 EXPECT_TRUE(IsGoogleSearchUrl( 128 EXPECT_TRUE(IsSearch("http://www.google.com/webhp#q=something"));
115 "http://www.google.com/webhp#q=something")); 129 EXPECT_TRUE(IsSearch("http://www.google.com/webhp#name=bob&q=something"));
116 EXPECT_TRUE(IsGoogleSearchUrl( 130 EXPECT_TRUE(IsSearch("http://www.google.com/webhp?name=bob#q=something"));
117 "http://www.google.com/webhp#name=bob&q=something")); 131 EXPECT_TRUE(IsSearch("http://www.google.com/webhp?name=bob#age=24&q=thing"));
118 EXPECT_TRUE(IsGoogleSearchUrl( 132
119 "http://www.google.com/webhp?name=bob#q=something")); 133 EXPECT_TRUE(IsSearch("http://www.google.com/#q=something"));
120 EXPECT_TRUE(IsGoogleSearchUrl( 134 EXPECT_TRUE(IsSearch("http://www.google.com/#name=bob&q=something"));
121 "http://www.google.com/webhp?name=bob#age=24&q=something")); 135 EXPECT_TRUE(IsSearch("http://www.google.com/?name=bob#q=something"));
122 136 EXPECT_TRUE(IsSearch("http://www.google.com/?name=bob#age=24&q=something"));
123 EXPECT_TRUE(IsGoogleSearchUrl( 137
124 "http://www.google.com/#q=something")); 138 EXPECT_TRUE(IsSearch("http://www.google.com#q=something"));
125 EXPECT_TRUE(IsGoogleSearchUrl( 139 EXPECT_TRUE(IsSearch("http://www.google.com#name=bob&q=something"));
126 "http://www.google.com/#name=bob&q=something")); 140 EXPECT_TRUE(IsSearch("http://www.google.com?name=bob#q=something"));
127 EXPECT_TRUE(IsGoogleSearchUrl( 141 EXPECT_TRUE(IsSearch("http://www.google.com?name=bob#age=24&q=something"));
128 "http://www.google.com/?name=bob#q=something"));
129 EXPECT_TRUE(IsGoogleSearchUrl(
130 "http://www.google.com/?name=bob#age=24&q=something"));
131
132 EXPECT_TRUE(IsGoogleSearchUrl(
133 "http://www.google.com#q=something"));
134 EXPECT_TRUE(IsGoogleSearchUrl(
135 "http://www.google.com#name=bob&q=something"));
136 EXPECT_TRUE(IsGoogleSearchUrl(
137 "http://www.google.com?name=bob#q=something"));
138 EXPECT_TRUE(IsGoogleSearchUrl(
139 "http://www.google.com?name=bob#age=24&q=something"));
140 } 142 }
141 143
142 TEST(GoogleUtilTest, GoodSearchPagesSecure) { 144 TEST(GoogleUtilTest, GoodSearchPagesSecure) {
143 // Queries with path "/search" need to have the query parameter in either 145 // Queries with path "/search" need to have the query parameter in either
144 // the url parameter or the hash fragment. 146 // the url parameter or the hash fragment.
145 EXPECT_TRUE(IsGoogleSearchUrl( 147 EXPECT_TRUE(IsSearch("https://www.google.com/search?q=something"));
146 "https://www.google.com/search?q=something")); 148 EXPECT_TRUE(IsSearch("https://www.google.com/search#q=something"));
147 EXPECT_TRUE(IsGoogleSearchUrl( 149 EXPECT_TRUE(IsSearch("https://www.google.com/search?name=bob&q=something"));
148 "https://www.google.com/search#q=something")); 150 EXPECT_TRUE(IsSearch("https://www.google.com/search?name=bob#q=something"));
149 EXPECT_TRUE(IsGoogleSearchUrl( 151 EXPECT_TRUE(IsSearch("https://www.google.com/search?name=bob#age=24&q=q"));
150 "https://www.google.com/search?name=bob&q=something")); 152 EXPECT_TRUE(IsSearch("https://www.google.co.uk/search?q=something"));
151 EXPECT_TRUE(IsGoogleSearchUrl(
152 "https://www.google.com/search?name=bob#q=something"));
153 EXPECT_TRUE(IsGoogleSearchUrl(
154 "https://www.google.com/search?name=bob#age=24&q=something"));
155 EXPECT_TRUE(IsGoogleSearchUrl(
156 "https://www.google.co.uk/search?q=something"));
157 // It's actually valid for both to have the query parameter. 153 // It's actually valid for both to have the query parameter.
158 EXPECT_TRUE(IsGoogleSearchUrl( 154 EXPECT_TRUE(IsSearch("https://www.google.com/search?q=something#q=other"));
159 "https://www.google.com/search?q=something#q=other"));
160 155
161 // Queries with path "/webhp", "/" or "" need to have the query parameter in 156 // Queries with path "/webhp", "/" or "" need to have the query parameter in
162 // the hash fragment. 157 // the hash fragment.
163 EXPECT_TRUE(IsGoogleSearchUrl( 158 EXPECT_TRUE(IsSearch("https://www.google.com/webhp#q=something"));
164 "https://www.google.com/webhp#q=something")); 159 EXPECT_TRUE(IsSearch("https://www.google.com/webhp#name=bob&q=something"));
165 EXPECT_TRUE(IsGoogleSearchUrl( 160 EXPECT_TRUE(IsSearch("https://www.google.com/webhp?name=bob#q=something"));
166 "https://www.google.com/webhp#name=bob&q=something")); 161 EXPECT_TRUE(IsSearch("https://www.google.com/webhp?name=bob#age=24&q=thing"));
167 EXPECT_TRUE(IsGoogleSearchUrl( 162
168 "https://www.google.com/webhp?name=bob#q=something")); 163 EXPECT_TRUE(IsSearch("https://www.google.com/#q=something"));
169 EXPECT_TRUE(IsGoogleSearchUrl( 164 EXPECT_TRUE(IsSearch("https://www.google.com/#name=bob&q=something"));
170 "https://www.google.com/webhp?name=bob#age=24&q=something")); 165 EXPECT_TRUE(IsSearch("https://www.google.com/?name=bob#q=something"));
171 166 EXPECT_TRUE(IsSearch("https://www.google.com/?name=bob#age=24&q=something"));
172 EXPECT_TRUE(IsGoogleSearchUrl( 167
173 "https://www.google.com/#q=something")); 168 EXPECT_TRUE(IsSearch("https://www.google.com#q=something"));
174 EXPECT_TRUE(IsGoogleSearchUrl( 169 EXPECT_TRUE(IsSearch("https://www.google.com#name=bob&q=something"));
175 "https://www.google.com/#name=bob&q=something")); 170 EXPECT_TRUE(IsSearch("https://www.google.com?name=bob#q=something"));
176 EXPECT_TRUE(IsGoogleSearchUrl( 171 EXPECT_TRUE(IsSearch("https://www.google.com?name=bob#age=24&q=something"));
177 "https://www.google.com/?name=bob#q=something"));
178 EXPECT_TRUE(IsGoogleSearchUrl(
179 "https://www.google.com/?name=bob#age=24&q=something"));
180
181 EXPECT_TRUE(IsGoogleSearchUrl(
182 "https://www.google.com#q=something"));
183 EXPECT_TRUE(IsGoogleSearchUrl(
184 "https://www.google.com#name=bob&q=something"));
185 EXPECT_TRUE(IsGoogleSearchUrl(
186 "https://www.google.com?name=bob#q=something"));
187 EXPECT_TRUE(IsGoogleSearchUrl(
188 "https://www.google.com?name=bob#age=24&q=something"));
189 } 172 }
190 173
191 TEST(GoogleUtilTest, BadSearches) { 174 TEST(GoogleUtilTest, BadSearches) {
192 // A home page URL should not be identified as a search URL. 175 // A home page URL should not be identified as a search URL.
193 EXPECT_FALSE(IsGoogleSearchUrl(GoogleURLTracker::kDefaultGoogleHomepage)); 176 EXPECT_FALSE(IsSearch(GoogleURLTracker::kDefaultGoogleHomepage));
194 EXPECT_FALSE(IsGoogleSearchUrl("http://google.com")); 177 EXPECT_FALSE(IsSearch("http://google.com"));
195 EXPECT_FALSE(IsGoogleSearchUrl("http://www.google.com")); 178 EXPECT_FALSE(IsSearch("http://www.google.com"));
196 EXPECT_FALSE(IsGoogleSearchUrl("http://www.google.com/search")); 179 EXPECT_FALSE(IsSearch("http://www.google.com/search"));
197 EXPECT_FALSE(IsGoogleSearchUrl("http://www.google.com/search?")); 180 EXPECT_FALSE(IsSearch("http://www.google.com/search?"));
198 181
199 // Must be http or https 182 // Must be http or https
200 EXPECT_FALSE(IsGoogleSearchUrl( 183 EXPECT_FALSE(IsSearch("ftp://www.google.com/search?q=something"));
201 "ftp://www.google.com/search?q=something")); 184 EXPECT_FALSE(IsSearch("file://does/not/exist/search?q=something"));
202 EXPECT_FALSE(IsGoogleSearchUrl( 185 EXPECT_FALSE(IsSearch("bad://www.google.com/search?q=something"));
203 "file://does/not/exist/search?q=something")); 186 EXPECT_FALSE(IsSearch("www.google.com/search?q=something"));
204 EXPECT_FALSE(IsGoogleSearchUrl(
205 "bad://www.google.com/search?q=something"));
206 EXPECT_FALSE(IsGoogleSearchUrl(
207 "www.google.com/search?q=something"));
208 187
209 // Can't have an empty query parameter. 188 // Can't have an empty query parameter.
210 EXPECT_FALSE(IsGoogleSearchUrl( 189 EXPECT_FALSE(IsSearch("http://www.google.com/search?q="));
211 "http://www.google.com/search?q=")); 190 EXPECT_FALSE(IsSearch("http://www.google.com/search?name=bob&q="));
212 EXPECT_FALSE(IsGoogleSearchUrl( 191 EXPECT_FALSE(IsSearch("http://www.google.com/webhp#q="));
213 "http://www.google.com/search?name=bob&q=")); 192 EXPECT_FALSE(IsSearch("http://www.google.com/webhp#name=bob&q="));
214 EXPECT_FALSE(IsGoogleSearchUrl(
215 "http://www.google.com/webhp#q="));
216 EXPECT_FALSE(IsGoogleSearchUrl(
217 "http://www.google.com/webhp#name=bob&q="));
218 193
219 // Home page searches without a hash fragment query parameter are invalid. 194 // Home page searches without a hash fragment query parameter are invalid.
220 EXPECT_FALSE(IsGoogleSearchUrl( 195 EXPECT_FALSE(IsSearch("http://www.google.com/webhp?q=something"));
221 "http://www.google.com/webhp?q=something")); 196 EXPECT_FALSE(IsSearch("http://www.google.com/webhp?q=something#no=good"));
222 EXPECT_FALSE(IsGoogleSearchUrl( 197 EXPECT_FALSE(IsSearch("http://www.google.com/webhp?name=bob&q=something"));
223 "http://www.google.com/webhp?q=something#no=good")); 198 EXPECT_FALSE(IsSearch("http://www.google.com/?q=something"));
224 EXPECT_FALSE(IsGoogleSearchUrl( 199 EXPECT_FALSE(IsSearch("http://www.google.com?q=something"));
225 "http://www.google.com/webhp?name=bob&q=something"));
226 EXPECT_FALSE(IsGoogleSearchUrl(
227 "http://www.google.com/?q=something"));
228 EXPECT_FALSE(IsGoogleSearchUrl(
229 "http://www.google.com?q=something"));
230 200
231 // Some paths are outright invalid as searches. 201 // Some paths are outright invalid as searches.
232 EXPECT_FALSE(IsGoogleSearchUrl( 202 EXPECT_FALSE(IsSearch("http://www.google.com/notreal?q=something"));
233 "http://www.google.com/notreal?q=something")); 203 EXPECT_FALSE(IsSearch("http://www.google.com/chrome?q=something"));
234 EXPECT_FALSE(IsGoogleSearchUrl( 204 EXPECT_FALSE(IsSearch("http://www.google.com/search/nogood?q=something"));
235 "http://www.google.com/chrome?q=something")); 205 EXPECT_FALSE(IsSearch("http://www.google.com/webhp/nogood#q=something"));
236 EXPECT_FALSE(IsGoogleSearchUrl( 206 EXPECT_FALSE(IsSearch(std::string()));
237 "http://www.google.com/search/nogood?q=something"));
238 EXPECT_FALSE(IsGoogleSearchUrl(
239 "http://www.google.com/webhp/nogood#q=something"));
240 EXPECT_FALSE(IsGoogleSearchUrl(std::string()));
241 207
242 // Case sensitive paths. 208 // Case sensitive paths.
243 EXPECT_FALSE(IsGoogleSearchUrl( 209 EXPECT_FALSE(IsSearch("http://www.google.com/SEARCH?q=something"));
244 "http://www.google.com/SEARCH?q=something")); 210 EXPECT_FALSE(IsSearch("http://www.google.com/WEBHP#q=something"));
245 EXPECT_FALSE(IsGoogleSearchUrl(
246 "http://www.google.com/WEBHP#q=something"));
247 } 211 }
248 212
249 TEST(GoogleUtilTest, GoogleDomains) { 213 TEST(GoogleUtilTest, GoogleDomains) {
250 // Test some good Google domains (valid TLDs). 214 // Test some good Google domains (valid TLDs).
251 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", 215 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com"),
252 google_util::ALLOW_SUBDOMAIN, 216 google_util::ALLOW_SUBDOMAIN,
253 google_util::DISALLOW_NON_STANDARD_PORTS)); 217 google_util::DISALLOW_NON_STANDARD_PORTS));
254 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", 218 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://google.com"),
255 google_util::ALLOW_SUBDOMAIN, 219 google_util::ALLOW_SUBDOMAIN,
256 google_util::DISALLOW_NON_STANDARD_PORTS)); 220 google_util::DISALLOW_NON_STANDARD_PORTS));
257 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca", 221 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.ca"),
258 google_util::ALLOW_SUBDOMAIN, 222 google_util::ALLOW_SUBDOMAIN,
259 google_util::DISALLOW_NON_STANDARD_PORTS)); 223 google_util::DISALLOW_NON_STANDARD_PORTS));
260 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.biz.tj", 224 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.biz.tj"),
261 google_util::ALLOW_SUBDOMAIN, 225 google_util::ALLOW_SUBDOMAIN,
262 google_util::DISALLOW_NON_STANDARD_PORTS)); 226 google_util::DISALLOW_NON_STANDARD_PORTS));
263 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com/search?q=something", 227 EXPECT_TRUE(IsGoogleDomainUrl(
264 google_util::ALLOW_SUBDOMAIN, 228 GURL("http://www.google.com/search?q=something"),
265 google_util::DISALLOW_NON_STANDARD_PORTS)); 229 google_util::ALLOW_SUBDOMAIN, google_util::DISALLOW_NON_STANDARD_PORTS));
266 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com/webhp", 230 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com/webhp"),
267 google_util::ALLOW_SUBDOMAIN, 231 google_util::ALLOW_SUBDOMAIN,
268 google_util::DISALLOW_NON_STANDARD_PORTS)); 232 google_util::DISALLOW_NON_STANDARD_PORTS));
269 233
270 // Test some bad Google domains (invalid TLDs). 234 // Test some bad Google domains (invalid TLDs).
271 EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.notrealtld", 235 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.google.notrealtld"),
272 google_util::ALLOW_SUBDOMAIN, 236 google_util::ALLOW_SUBDOMAIN,
273 google_util::DISALLOW_NON_STANDARD_PORTS)); 237 google_util::DISALLOW_NON_STANDARD_PORTS));
274 EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.faketld/search?q=something", 238 EXPECT_FALSE(IsGoogleDomainUrl(
239 GURL("http://www.google.faketld/search?q=something"),
240 google_util::ALLOW_SUBDOMAIN, google_util::DISALLOW_NON_STANDARD_PORTS));
241 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.yahoo.com"),
275 google_util::ALLOW_SUBDOMAIN, 242 google_util::ALLOW_SUBDOMAIN,
276 google_util::DISALLOW_NON_STANDARD_PORTS)); 243 google_util::DISALLOW_NON_STANDARD_PORTS));
277 EXPECT_FALSE(IsGoogleDomainUrl("http://www.yahoo.com",
278 google_util::ALLOW_SUBDOMAIN,
279 google_util::DISALLOW_NON_STANDARD_PORTS));
280 244
281 // Test subdomain checks. 245 // Test subdomain checks.
282 EXPECT_TRUE(IsGoogleDomainUrl("http://images.google.com", 246 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://images.google.com"),
283 google_util::ALLOW_SUBDOMAIN, 247 google_util::ALLOW_SUBDOMAIN,
284 google_util::DISALLOW_NON_STANDARD_PORTS)); 248 google_util::DISALLOW_NON_STANDARD_PORTS));
285 EXPECT_FALSE(IsGoogleDomainUrl("http://images.google.com", 249 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://images.google.com"),
286 google_util::DISALLOW_SUBDOMAIN, 250 google_util::DISALLOW_SUBDOMAIN,
287 google_util::DISALLOW_NON_STANDARD_PORTS)); 251 google_util::DISALLOW_NON_STANDARD_PORTS));
288 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", 252 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://google.com"),
289 google_util::DISALLOW_SUBDOMAIN, 253 google_util::DISALLOW_SUBDOMAIN,
290 google_util::DISALLOW_NON_STANDARD_PORTS)); 254 google_util::DISALLOW_NON_STANDARD_PORTS));
291 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", 255 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com"),
292 google_util::DISALLOW_SUBDOMAIN, 256 google_util::DISALLOW_SUBDOMAIN,
293 google_util::DISALLOW_NON_STANDARD_PORTS)); 257 google_util::DISALLOW_NON_STANDARD_PORTS));
294 258
295 // Port and scheme checks. 259 // Port and scheme checks.
296 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com:80", 260 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com:80"),
297 google_util::DISALLOW_SUBDOMAIN, 261 google_util::DISALLOW_SUBDOMAIN,
298 google_util::DISALLOW_NON_STANDARD_PORTS)); 262 google_util::DISALLOW_NON_STANDARD_PORTS));
299 EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.com:123", 263 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.google.com:123"),
300 google_util::DISALLOW_SUBDOMAIN, 264 google_util::DISALLOW_SUBDOMAIN,
301 google_util::DISALLOW_NON_STANDARD_PORTS)); 265 google_util::DISALLOW_NON_STANDARD_PORTS));
302 EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:443", 266 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.google.com:443"),
303 google_util::DISALLOW_SUBDOMAIN, 267 google_util::DISALLOW_SUBDOMAIN,
304 google_util::DISALLOW_NON_STANDARD_PORTS)); 268 google_util::DISALLOW_NON_STANDARD_PORTS));
305 EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.com:123", 269 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.google.com:123"),
306 google_util::DISALLOW_SUBDOMAIN, 270 google_util::DISALLOW_SUBDOMAIN,
307 google_util::DISALLOW_NON_STANDARD_PORTS)); 271 google_util::DISALLOW_NON_STANDARD_PORTS));
308 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com:123", 272 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com:123"),
309 google_util::DISALLOW_SUBDOMAIN, 273 google_util::DISALLOW_SUBDOMAIN,
310 google_util::ALLOW_NON_STANDARD_PORTS)); 274 google_util::ALLOW_NON_STANDARD_PORTS));
311 EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:123", 275 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.google.com:123"),
312 google_util::DISALLOW_SUBDOMAIN, 276 google_util::DISALLOW_SUBDOMAIN,
313 google_util::ALLOW_NON_STANDARD_PORTS)); 277 google_util::ALLOW_NON_STANDARD_PORTS));
314 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com:80", 278 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.google.com:80"),
315 google_util::DISALLOW_SUBDOMAIN, 279 google_util::DISALLOW_SUBDOMAIN,
316 google_util::ALLOW_NON_STANDARD_PORTS)); 280 google_util::ALLOW_NON_STANDARD_PORTS));
317 EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:443", 281 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.google.com:443"),
318 google_util::DISALLOW_SUBDOMAIN, 282 google_util::DISALLOW_SUBDOMAIN,
319 google_util::ALLOW_NON_STANDARD_PORTS)); 283 google_util::ALLOW_NON_STANDARD_PORTS));
320 EXPECT_FALSE(IsGoogleDomainUrl("file://www.google.com", 284 EXPECT_FALSE(IsGoogleDomainUrl(GURL("file://www.google.com"),
321 google_util::DISALLOW_SUBDOMAIN, 285 google_util::DISALLOW_SUBDOMAIN,
322 google_util::DISALLOW_NON_STANDARD_PORTS)); 286 google_util::DISALLOW_NON_STANDARD_PORTS));
323 EXPECT_FALSE(IsGoogleDomainUrl("doesnotexist://www.google.com", 287 EXPECT_FALSE(IsGoogleDomainUrl(GURL("doesnotexist://www.google.com"),
324 google_util::DISALLOW_SUBDOMAIN, 288 google_util::DISALLOW_SUBDOMAIN,
325 google_util::DISALLOW_NON_STANDARD_PORTS)); 289 google_util::DISALLOW_NON_STANDARD_PORTS));
326 290 }
327 // Test overriding with --instant-url works. 291
328 EXPECT_FALSE(IsGoogleDomainUrl("http://test.foo.com", 292 TEST(GoogleUtilTest, GoogleBaseURL) {
329 google_util::DISALLOW_SUBDOMAIN, 293 // When no command-line flag is specified, no input to
330 google_util::DISALLOW_NON_STANDARD_PORTS)); 294 // StartsWithCommandLineGoogleBaseURL() should return true.
331 EXPECT_FALSE(IsGoogleDomainUrl("http://test.foo.com:1234", 295 EXPECT_FALSE(StartsWithBaseURL(std::string()));
332 google_util::DISALLOW_SUBDOMAIN, 296 EXPECT_FALSE(StartsWithBaseURL("http://www.foo.com/"));
333 google_util::DISALLOW_NON_STANDARD_PORTS)); 297 EXPECT_FALSE(StartsWithBaseURL("http://www.google.com/"));
334 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 298
335 switches::kInstantURL, "http://test.foo.com:1234/bar"); 299 // By default, none of the IsGoogleXXX functions should return true for a
336 EXPECT_FALSE(IsGoogleDomainUrl("http://test.foo.com", 300 // "foo.com" URL.
337 google_util::DISALLOW_SUBDOMAIN, 301 EXPECT_FALSE(IsGoogleHostname("www.foo.com",
338 google_util::DISALLOW_NON_STANDARD_PORTS)); 302 google_util::DISALLOW_SUBDOMAIN));
339 EXPECT_TRUE(IsGoogleDomainUrl("http://test.foo.com:1234", 303 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"),
340 google_util::DISALLOW_SUBDOMAIN, 304 google_util::DISALLOW_SUBDOMAIN,
341 google_util::DISALLOW_NON_STANDARD_PORTS)); 305 google_util::DISALLOW_NON_STANDARD_PORTS));
342 EXPECT_FALSE(IsGoogleDomainUrl("file://test.foo.com:1234", 306 EXPECT_FALSE(IsGoogleDomainUrl(GURL("https://www.foo.com/"),
343 google_util::DISALLOW_SUBDOMAIN, 307 google_util::DISALLOW_SUBDOMAIN,
344 google_util::DISALLOW_NON_STANDARD_PORTS)); 308 google_util::DISALLOW_NON_STANDARD_PORTS));
345 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", 309 EXPECT_FALSE(IsHomePage("https://www.foo.com/webhp"));
346 google_util::DISALLOW_SUBDOMAIN, 310 EXPECT_FALSE(IsSearch("http://www.foo.com/search?q=a"));
347 google_util::DISALLOW_NON_STANDARD_PORTS)); 311
348 } 312 // Override the Google base URL on the command line.
313 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
314 "http://www.foo.com/");
315
316 // Only URLs which start with exactly the string on the command line should
317 // cause StartsWithCommandLineGoogleBaseURL() to return true.
318 EXPECT_FALSE(StartsWithBaseURL(std::string()));
319 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/"));
320 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/abc"));
321 EXPECT_FALSE(StartsWithBaseURL("https://www.foo.com/"));
322 EXPECT_FALSE(StartsWithBaseURL("http://www.google.com/"));
323
324 // The various IsGoogleXXX functions should respect the command-line flag.
325 EXPECT_TRUE(IsGoogleHostname("www.foo.com", google_util::DISALLOW_SUBDOMAIN));
326 EXPECT_FALSE(IsGoogleHostname("foo.com", google_util::ALLOW_SUBDOMAIN));
327 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"),
328 google_util::DISALLOW_SUBDOMAIN,
329 google_util::DISALLOW_NON_STANDARD_PORTS));
330 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.foo.com/"),
331 google_util::DISALLOW_SUBDOMAIN,
332 google_util::DISALLOW_NON_STANDARD_PORTS));
333 EXPECT_TRUE(IsHomePage("https://www.foo.com/webhp"));
334 EXPECT_FALSE(IsHomePage("http://www.foo.com/xyz"));
335 EXPECT_TRUE(IsSearch("http://www.foo.com/search?q=a"));
336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698