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, GoodHomePages) { |
| 12 // Valid home page URLs. |
| 13 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com")); |
| 14 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca")); |
| 15 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk")); |
| 16 EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage)); |
| 17 |
| 18 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are |
| 19 // ignored. |
| 20 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/")); |
| 21 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp")); |
| 22 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp?rlz=TEST")); |
| 23 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig")); |
| 24 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo")); |
| 25 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig?rlz=TEST")); |
| 26 EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo?rlz=TEST")); |
| 27 |
| 28 // Protocol https is valid. |
| 29 EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/")); |
| 30 } |
| 31 |
| 32 TEST(GoogleUtilTest, BadHomePages) { |
| 33 EXPECT_FALSE(IsGoogleHomePageUrl("")); |
| 34 |
| 35 // Only the "www" subdomain is OK. |
| 36 EXPECT_FALSE(IsGoogleHomePageUrl("http://maps.google.com")); |
| 37 EXPECT_FALSE(IsGoogleHomePageUrl("http://foo.google.com")); |
| 38 EXPECT_FALSE(IsGoogleHomePageUrl("http://google.com")); |
| 39 |
| 40 // No non-standard port numbers. |
| 41 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com:1234")); |
| 42 EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com:5678")); |
| 43 |
| 44 // Invalid TLDs. |
| 45 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc")); |
| 46 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com.abc")); |
| 47 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc.com")); |
| 48 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.ab.cd")); |
| 49 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.uk.qq")); |
| 50 |
| 51 // Must be http or https. |
| 52 EXPECT_FALSE(IsGoogleHomePageUrl("ftp://www.google.com")); |
| 53 EXPECT_FALSE(IsGoogleHomePageUrl("file://does/not/exist")); |
| 54 EXPECT_FALSE(IsGoogleHomePageUrl("bad://www.google.com")); |
| 55 |
| 56 // Only the paths /, /webhp, and /ig.* are valid. |
| 57 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abc")); |
| 58 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhpabc")); |
| 59 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/abc")); |
| 60 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abcig")); |
| 61 EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/ig")); |
| 62 } |
OLD | NEW |