OLD | NEW |
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/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/google/google_url_tracker.h" | 7 #include "chrome/browser/google/google_url_tracker.h" |
8 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using google_util::IsGoogleDomainUrl; | 12 using google_util::IsGoogleDomainUrl; |
13 using google_util::IsGoogleHomePageUrl; | 13 using google_util::IsGoogleHomePageUrl; |
14 using google_util::IsGoogleSearchUrl; | 14 using google_util::IsGoogleSearchUrl; |
15 using google_util::IsInstantExtendedAPIGoogleSearchUrl; | |
16 | 15 |
17 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { | 16 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { |
18 // Valid home page hosts. | 17 // Valid home page hosts. |
19 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); | 18 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); |
20 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); | 19 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); |
21 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); | 20 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); |
22 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); | 21 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); |
23 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); | 22 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); |
24 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); | 23 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); |
25 | 24 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 "http://www.google.com/webhp/nogood#q=something")); | 239 "http://www.google.com/webhp/nogood#q=something")); |
241 EXPECT_FALSE(IsGoogleSearchUrl("")); | 240 EXPECT_FALSE(IsGoogleSearchUrl("")); |
242 | 241 |
243 // Case sensitive paths. | 242 // Case sensitive paths. |
244 EXPECT_FALSE(IsGoogleSearchUrl( | 243 EXPECT_FALSE(IsGoogleSearchUrl( |
245 "http://www.google.com/SEARCH?q=something")); | 244 "http://www.google.com/SEARCH?q=something")); |
246 EXPECT_FALSE(IsGoogleSearchUrl( | 245 EXPECT_FALSE(IsGoogleSearchUrl( |
247 "http://www.google.com/WEBHP#q=something")); | 246 "http://www.google.com/WEBHP#q=something")); |
248 } | 247 } |
249 | 248 |
250 TEST(GoogleUtilTest, IsInstantExtendedAPIGoogleSearchUrl) { | |
251 EXPECT_TRUE(IsInstantExtendedAPIGoogleSearchUrl( | |
252 "http://www.google.com/search?q=something&espv=1")); | |
253 EXPECT_TRUE(IsInstantExtendedAPIGoogleSearchUrl( | |
254 "http://www.google.com/search?q=something&espv=3")); | |
255 EXPECT_TRUE(IsInstantExtendedAPIGoogleSearchUrl( | |
256 "http://www.google.com/search?q=something&espv=42")); | |
257 | |
258 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
259 "http://www.google.com/search?q=something&espv=")); | |
260 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
261 "http://www.google.com/search?q=something&espv=0")); | |
262 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
263 "http://www.google.com/search?q=something&espv=00")); | |
264 | |
265 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
266 "http://www.foo.com/search?q=something&espv=0")); | |
267 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
268 "http://www.foo.com/search?q=something&espv=1")); | |
269 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
270 "http://www.google.com/bing?q=something&espv=1")); | |
271 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
272 "http://www.google.com/search?q=something&vespv=1")); | |
273 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
274 "http://www.google.com/search?q=something&espvx=1")); | |
275 EXPECT_FALSE(IsInstantExtendedAPIGoogleSearchUrl( | |
276 "http://www.google.com/search#q=something&espv=1")); | |
277 } | |
278 | |
279 TEST(GoogleUtilTest, GoogleDomains) { | 249 TEST(GoogleUtilTest, GoogleDomains) { |
280 // Test some good Google domains (valid TLDs). | 250 // Test some good Google domains (valid TLDs). |
281 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", | 251 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", |
282 google_util::ALLOW_SUBDOMAIN, | 252 google_util::ALLOW_SUBDOMAIN, |
283 google_util::DISALLOW_NON_STANDARD_PORTS)); | 253 google_util::DISALLOW_NON_STANDARD_PORTS)); |
284 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", | 254 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", |
285 google_util::ALLOW_SUBDOMAIN, | 255 google_util::ALLOW_SUBDOMAIN, |
286 google_util::DISALLOW_NON_STANDARD_PORTS)); | 256 google_util::DISALLOW_NON_STANDARD_PORTS)); |
287 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca", | 257 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca", |
288 google_util::ALLOW_SUBDOMAIN, | 258 google_util::ALLOW_SUBDOMAIN, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 EXPECT_TRUE(IsGoogleDomainUrl("http://test.foo.com:1234", | 339 EXPECT_TRUE(IsGoogleDomainUrl("http://test.foo.com:1234", |
370 google_util::DISALLOW_SUBDOMAIN, | 340 google_util::DISALLOW_SUBDOMAIN, |
371 google_util::DISALLOW_NON_STANDARD_PORTS)); | 341 google_util::DISALLOW_NON_STANDARD_PORTS)); |
372 EXPECT_FALSE(IsGoogleDomainUrl("file://test.foo.com:1234", | 342 EXPECT_FALSE(IsGoogleDomainUrl("file://test.foo.com:1234", |
373 google_util::DISALLOW_SUBDOMAIN, | 343 google_util::DISALLOW_SUBDOMAIN, |
374 google_util::DISALLOW_NON_STANDARD_PORTS)); | 344 google_util::DISALLOW_NON_STANDARD_PORTS)); |
375 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", | 345 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", |
376 google_util::DISALLOW_SUBDOMAIN, | 346 google_util::DISALLOW_SUBDOMAIN, |
377 google_util::DISALLOW_NON_STANDARD_PORTS)); | 347 google_util::DISALLOW_NON_STANDARD_PORTS)); |
378 } | 348 } |
379 | |
380 TEST(GoogleUtilTest, SearchTerms) { | |
381 // Simple searches. | |
382 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
383 "http://google.com/search?q=tractor+supply")); | |
384 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
385 google_util::GetSearchTermsFromGoogleSearchURL( | |
386 "http://google.com/search?q=tractor+supply&espv=1")); | |
387 // espv=1 only applies in query. | |
388 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
389 "http://google.com/search?q=potato#espv=1")); | |
390 | |
391 // Instant searches. | |
392 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
393 "http://google.com/webhp#q=tractor+supply")); | |
394 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
395 google_util::GetSearchTermsFromGoogleSearchURL( | |
396 "http://google.com/webhp?espv=1#q=tractor+supply")); | |
397 // espv=1 only applies in query. | |
398 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
399 "http://google.com/webhp?#espv=1&q=potato")); | |
400 | |
401 // Both query and ref components have a search term. | |
402 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
403 google_util::GetSearchTermsFromGoogleSearchURL( | |
404 "http://google.com/webhp?q=potato&espv=1#q=tractor+supply")); | |
405 | |
406 // Blank queries. | |
407 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
408 "http://google.com/search?q=&q=potato&espv=1")); | |
409 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
410 "http://google.com/webhp?espv=1#q=&q=tractor+supply")); | |
411 | |
412 // Multiple non-empty queries. | |
413 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
414 google_util::GetSearchTermsFromGoogleSearchURL( | |
415 "http://google.com/search?q=tractor+supply&q=potato&espv=1")); | |
416 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
417 google_util::GetSearchTermsFromGoogleSearchURL( | |
418 "http://google.com/webhp?espv=1#q=tractor+supply&q=potato")); | |
419 | |
420 // Blank terms in ref override non-blank terms in query. | |
421 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
422 "http://google.com/search?q=potato&espv=1#q=")); | |
423 | |
424 // Blank terms in query do not override non-blank terms in ref. | |
425 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
426 google_util::GetSearchTermsFromGoogleSearchURL( | |
427 "http://google.com/search?q=&espv=1#q=tractor+supply")); | |
428 } | |
OLD | NEW |