OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #include "chrome/browser/google/google_url_tracker.h" |
| 6 #include "chrome/browser/google/google_util.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 using google_util::IsGoogleHomePageUrl; |
| 10 |
| 11 TEST(GoogleUtilTest, GoodHomePagesNonSecure) { |
| 12 // Valid home page hosts. |
| 13 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); |
| 14 EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com")); |
| 15 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); |
| 16 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); |
| 17 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); |
| 18 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/")); |
| 19 |
| 20 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are |
| 21 // ignored. |
| 22 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/")); |
| 23 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp")); |
| 24 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp?rlz=TEST")); |
| 25 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig")); |
| 26 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo")); |
| 27 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig?rlz=TEST")); |
| 28 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo?rlz=TEST")); |
| 29 } |
| 30 |
| 31 TEST(GoogleUtilTest, GoodHomePagesSecure) { |
| 32 // Valid home page hosts. |
| 33 EXPECT_TRUE(IsGoogleHomePageUrl("https://google.com")); |
| 34 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com")); |
| 35 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.ca")); |
| 36 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.co.uk")); |
| 37 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com:443/")); |
| 38 |
| 39 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are |
| 40 // ignored. |
| 41 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/")); |
| 42 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp")); |
| 43 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp?rlz=TEST")); |
| 44 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig")); |
| 45 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo")); |
| 46 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig?rlz=TEST")); |
| 47 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo?rlz=TEST")); |
| 48 } |
| 49 |
| 50 TEST(GoogleUtilTest, BadHomePages) { |
| 51 EXPECT_FALSE(IsGoogleHomePageUrl("")); |
| 52 |
| 53 // If specified, only the "www" subdomain is OK. |
| 54 EXPECT_FALSE(IsGoogleHomePageUrl("http://maps.google.com")); |
| 55 EXPECT_FALSE(IsGoogleHomePageUrl("http://foo.google.com")); |
| 56 |
| 57 // No non-standard port numbers. |
| 58 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com:1234")); |
| 59 EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com:5678")); |
| 60 |
| 61 // Invalid TLDs. |
| 62 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc")); |
| 63 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com.abc")); |
| 64 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc.com")); |
| 65 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.ab.cd")); |
| 66 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.uk.qq")); |
| 67 |
| 68 // Must be http or https. |
| 69 EXPECT_FALSE(IsGoogleHomePageUrl("ftp://www.google.com")); |
| 70 EXPECT_FALSE(IsGoogleHomePageUrl("file://does/not/exist")); |
| 71 EXPECT_FALSE(IsGoogleHomePageUrl("bad://www.google.com")); |
| 72 EXPECT_FALSE(IsGoogleHomePageUrl("www.google.com")); |
| 73 |
| 74 // Only the paths /, /webhp, and /ig.* are valid. |
| 75 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abc")); |
| 76 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhpabc")); |
| 77 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/abc")); |
| 78 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abcig")); |
| 79 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/ig")); |
| 80 } |
OLD | NEW |