Chromium Code Reviews| 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 "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 #include "chrome/browser/google/google_util.h" | 6 #include "chrome/browser/google/google_util.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 using google_util::IsGoogleDomainUrl; | 9 using google_util::IsGoogleDomainUrl; |
| 10 using google_util::IsGoogleHomePageUrl; | 10 using google_util::IsGoogleHomePageUrl; |
| 11 using google_util::IsGoogleSearchUrl; | 11 using google_util::IsGoogleSearchUrl; |
| 12 using google_util::IsEmbeddedGoogleSearchUrl; | |
| 12 | 13 |
| 13 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { | 14 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { |
| 14 // Valid home page hosts. | 15 // Valid home page hosts. |
| 15 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); | 16 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); |
| 16 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); | 17 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); |
| 17 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); | 18 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); |
| 18 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); | 19 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); |
| 19 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); | 20 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); |
| 20 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); | 21 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); |
| 21 | 22 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 "http://www.google.com/webhp/nogood#q=something")); | 237 "http://www.google.com/webhp/nogood#q=something")); |
| 237 EXPECT_FALSE(IsGoogleSearchUrl("")); | 238 EXPECT_FALSE(IsGoogleSearchUrl("")); |
| 238 | 239 |
| 239 // Case sensitive paths. | 240 // Case sensitive paths. |
| 240 EXPECT_FALSE(IsGoogleSearchUrl( | 241 EXPECT_FALSE(IsGoogleSearchUrl( |
| 241 "http://www.google.com/SEARCH?q=something")); | 242 "http://www.google.com/SEARCH?q=something")); |
| 242 EXPECT_FALSE(IsGoogleSearchUrl( | 243 EXPECT_FALSE(IsGoogleSearchUrl( |
| 243 "http://www.google.com/WEBHP#q=something")); | 244 "http://www.google.com/WEBHP#q=something")); |
| 244 } | 245 } |
| 245 | 246 |
| 247 TEST(GoogleUtilTest, IsEmbeddedGoogleSearchUrl) { | |
| 248 EXPECT_TRUE(IsEmbeddedGoogleSearchUrl( | |
| 249 "http://www.google.com/search?q=something&espv=1")); | |
| 250 EXPECT_TRUE(IsEmbeddedGoogleSearchUrl( | |
| 251 "http://www.google.com/search?q=something&espv=3")); | |
| 252 EXPECT_TRUE(IsEmbeddedGoogleSearchUrl( | |
| 253 "http://www.google.com/search?q=something&espv=42")); | |
| 254 | |
| 255 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 256 "http://www.google.com/search?q=something&espv=")); | |
|
Ilya Sherman
2012/06/21 17:46:58
nit: Please also add a test for espv=0 on google.c
dhollowa
2012/06/21 22:16:43
Done.
| |
| 257 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 258 "http://www.foo.com/search?q=something&espv=0")); | |
| 259 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 260 "http://www.foo.com/search?q=something&espv=1")); | |
| 261 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 262 "http://www.google.com/bing?q=something&espv=1")); | |
| 263 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 264 "http://www.google.com/search?q=something&vespv=1")); | |
| 265 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 266 "http://www.google.com/search?q=something&espvx=1")); | |
| 267 EXPECT_FALSE(IsEmbeddedGoogleSearchUrl( | |
| 268 "http://www.google.com/search#q=something&espv=1")); | |
| 269 } | |
| 270 | |
| 246 TEST(GoogleUtilTest, GoogleDomains) { | 271 TEST(GoogleUtilTest, GoogleDomains) { |
| 247 // Test some good Google domains (valid TLDs). | 272 // Test some good Google domains (valid TLDs). |
| 248 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", | 273 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", |
| 249 google_util::ALLOW_SUBDOMAIN)); | 274 google_util::ALLOW_SUBDOMAIN)); |
| 250 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", | 275 EXPECT_TRUE(IsGoogleDomainUrl("http://google.com", |
| 251 google_util::ALLOW_SUBDOMAIN)); | 276 google_util::ALLOW_SUBDOMAIN)); |
| 252 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca", | 277 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca", |
| 253 google_util::ALLOW_SUBDOMAIN)); | 278 google_util::ALLOW_SUBDOMAIN)); |
| 254 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.biz.tj", | 279 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.biz.tj", |
| 255 google_util::ALLOW_SUBDOMAIN)); | 280 google_util::ALLOW_SUBDOMAIN)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 283 google_util::DISALLOW_SUBDOMAIN)); | 308 google_util::DISALLOW_SUBDOMAIN)); |
| 284 EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:443", | 309 EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:443", |
| 285 google_util::DISALLOW_SUBDOMAIN)); | 310 google_util::DISALLOW_SUBDOMAIN)); |
| 286 EXPECT_FALSE(IsGoogleDomainUrl("https://www.google.com:123", | 311 EXPECT_FALSE(IsGoogleDomainUrl("https://www.google.com:123", |
| 287 google_util::DISALLOW_SUBDOMAIN)); | 312 google_util::DISALLOW_SUBDOMAIN)); |
| 288 EXPECT_FALSE(IsGoogleDomainUrl("file://www.google.com", | 313 EXPECT_FALSE(IsGoogleDomainUrl("file://www.google.com", |
| 289 google_util::DISALLOW_SUBDOMAIN)); | 314 google_util::DISALLOW_SUBDOMAIN)); |
| 290 EXPECT_FALSE(IsGoogleDomainUrl("doesnotexist://www.google.com", | 315 EXPECT_FALSE(IsGoogleDomainUrl("doesnotexist://www.google.com", |
| 291 google_util::DISALLOW_SUBDOMAIN)); | 316 google_util::DISALLOW_SUBDOMAIN)); |
| 292 } | 317 } |
| OLD | NEW |