| 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 "components/google/core/browser/google_switches.h" | 6 #include "components/google/core/browser/google_switches.h" |
| 7 #include "components/google/core/browser/google_url_tracker.h" | 7 #include "components/google/core/browser/google_url_tracker.h" |
| 8 #include "components/google/core/browser/google_util.h" | 8 #include "components/google/core/browser/google_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"), | 303 EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"), |
| 304 google_util::DISALLOW_SUBDOMAIN, | 304 google_util::DISALLOW_SUBDOMAIN, |
| 305 google_util::DISALLOW_NON_STANDARD_PORTS)); | 305 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 306 EXPECT_FALSE(IsGoogleDomainUrl(GURL("https://www.foo.com/"), | 306 EXPECT_FALSE(IsGoogleDomainUrl(GURL("https://www.foo.com/"), |
| 307 google_util::DISALLOW_SUBDOMAIN, | 307 google_util::DISALLOW_SUBDOMAIN, |
| 308 google_util::DISALLOW_NON_STANDARD_PORTS)); | 308 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 309 EXPECT_FALSE(IsHomePage("https://www.foo.com/webhp")); | 309 EXPECT_FALSE(IsHomePage("https://www.foo.com/webhp")); |
| 310 EXPECT_FALSE(IsSearch("http://www.foo.com/search?q=a")); | 310 EXPECT_FALSE(IsSearch("http://www.foo.com/search?q=a")); |
| 311 | 311 |
| 312 // Override the Google base URL on the command line. | 312 // Override the Google base URL on the command line. |
| 313 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 313 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 314 "http://www.foo.com/"); | 314 switches::kGoogleBaseURL, "http://www.foo.com/"); |
| 315 | 315 |
| 316 // Only URLs which start with exactly the string on the command line should | 316 // Only URLs which start with exactly the string on the command line should |
| 317 // cause StartsWithCommandLineGoogleBaseURL() to return true. | 317 // cause StartsWithCommandLineGoogleBaseURL() to return true. |
| 318 EXPECT_FALSE(StartsWithBaseURL(std::string())); | 318 EXPECT_FALSE(StartsWithBaseURL(std::string())); |
| 319 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/")); | 319 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/")); |
| 320 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/abc")); | 320 EXPECT_TRUE(StartsWithBaseURL("http://www.foo.com/abc")); |
| 321 EXPECT_FALSE(StartsWithBaseURL("https://www.foo.com/")); | 321 EXPECT_FALSE(StartsWithBaseURL("https://www.foo.com/")); |
| 322 EXPECT_FALSE(StartsWithBaseURL("http://www.google.com/")); | 322 EXPECT_FALSE(StartsWithBaseURL("http://www.google.com/")); |
| 323 | 323 |
| 324 // The various IsGoogleXXX functions should respect the command-line flag. | 324 // The various IsGoogleXXX functions should respect the command-line flag. |
| 325 EXPECT_TRUE(IsGoogleHostname("www.foo.com", google_util::DISALLOW_SUBDOMAIN)); | 325 EXPECT_TRUE(IsGoogleHostname("www.foo.com", google_util::DISALLOW_SUBDOMAIN)); |
| 326 EXPECT_FALSE(IsGoogleHostname("foo.com", google_util::ALLOW_SUBDOMAIN)); | 326 EXPECT_FALSE(IsGoogleHostname("foo.com", google_util::ALLOW_SUBDOMAIN)); |
| 327 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"), | 327 EXPECT_TRUE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"), |
| 328 google_util::DISALLOW_SUBDOMAIN, | 328 google_util::DISALLOW_SUBDOMAIN, |
| 329 google_util::DISALLOW_NON_STANDARD_PORTS)); | 329 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 330 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.foo.com/"), | 330 EXPECT_TRUE(IsGoogleDomainUrl(GURL("https://www.foo.com/"), |
| 331 google_util::DISALLOW_SUBDOMAIN, | 331 google_util::DISALLOW_SUBDOMAIN, |
| 332 google_util::DISALLOW_NON_STANDARD_PORTS)); | 332 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 333 EXPECT_TRUE(IsHomePage("https://www.foo.com/webhp")); | 333 EXPECT_TRUE(IsHomePage("https://www.foo.com/webhp")); |
| 334 EXPECT_FALSE(IsHomePage("http://www.foo.com/xyz")); | 334 EXPECT_FALSE(IsHomePage("http://www.foo.com/xyz")); |
| 335 EXPECT_TRUE(IsSearch("http://www.foo.com/search?q=a")); | 335 EXPECT_TRUE(IsSearch("http://www.foo.com/search?q=a")); |
| 336 } | 336 } |
| 337 | 337 |
| 338 TEST(GoogleUtilTest, GoogleBaseURLDisallowQuery) { | 338 TEST(GoogleUtilTest, GoogleBaseURLDisallowQuery) { |
| 339 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 339 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 340 "http://www.foo.com/?q="); | 340 switches::kGoogleBaseURL, "http://www.foo.com/?q="); |
| 341 EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid()); | 341 EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST(GoogleUtilTest, GoogleBaseURLDisallowRef) { | 344 TEST(GoogleUtilTest, GoogleBaseURLDisallowRef) { |
| 345 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 345 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 346 "http://www.foo.com/#q="); | 346 switches::kGoogleBaseURL, "http://www.foo.com/#q="); |
| 347 EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid()); | 347 EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 TEST(GoogleUtilTest, GoogleBaseURLFixup) { | 350 TEST(GoogleUtilTest, GoogleBaseURLFixup) { |
| 351 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 351 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 352 "www.foo.com"); | 352 switches::kGoogleBaseURL, "www.foo.com"); |
| 353 ASSERT_TRUE(google_util::CommandLineGoogleBaseURL().is_valid()); | 353 ASSERT_TRUE(google_util::CommandLineGoogleBaseURL().is_valid()); |
| 354 EXPECT_EQ("http://www.foo.com/", | 354 EXPECT_EQ("http://www.foo.com/", |
| 355 google_util::CommandLineGoogleBaseURL().spec()); | 355 google_util::CommandLineGoogleBaseURL().spec()); |
| 356 } | 356 } |
| 357 | 357 |
| 358 TEST(GoogleUtilTest, YoutubeDomains) { | 358 TEST(GoogleUtilTest, YoutubeDomains) { |
| 359 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com"), | 359 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com"), |
| 360 google_util::ALLOW_SUBDOMAIN, | 360 google_util::ALLOW_SUBDOMAIN, |
| 361 google_util::DISALLOW_NON_STANDARD_PORTS)); | 361 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 362 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://youtube.com"), | 362 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://youtube.com"), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), | 398 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), |
| 399 google_util::DISALLOW_SUBDOMAIN, | 399 google_util::DISALLOW_SUBDOMAIN, |
| 400 google_util::DISALLOW_NON_STANDARD_PORTS)); | 400 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 401 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), | 401 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), |
| 402 google_util::DISALLOW_SUBDOMAIN, | 402 google_util::DISALLOW_SUBDOMAIN, |
| 403 google_util::ALLOW_NON_STANDARD_PORTS)); | 403 google_util::ALLOW_NON_STANDARD_PORTS)); |
| 404 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("file://www.youtube.com"), | 404 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("file://www.youtube.com"), |
| 405 google_util::DISALLOW_SUBDOMAIN, | 405 google_util::DISALLOW_SUBDOMAIN, |
| 406 google_util::DISALLOW_NON_STANDARD_PORTS)); | 406 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 407 } | 407 } |
| OLD | NEW |