summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google/google_util_unittest.cc
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 17:39:37 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 17:39:37 +0000
commit1e1f7378006bf8961ae92e3364365f84162d1878 (patch)
treec2ba65d9cf756ee7fbab949286c9141f706860b1 /chrome/browser/google/google_util_unittest.cc
parenta8946f906f33ec2b58f12d17828faa1b9d5a1aff (diff)
downloadchromium_src-1e1f7378006bf8961ae92e3364365f84162d1878.zip
chromium_src-1e1f7378006bf8961ae92e3364365f84162d1878.tar.gz
chromium_src-1e1f7378006bf8961ae92e3364365f84162d1878.tar.bz2
Add more flexible handling of what is considered a google home page.
BUG=http:b/5609053 TEST=See unit tests for valid and invalid URLs. Review URL: http://codereview.chromium.org/8728004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google/google_util_unittest.cc')
-rw-r--r--chrome/browser/google/google_util_unittest.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/google/google_util_unittest.cc b/chrome/browser/google/google_util_unittest.cc
new file mode 100644
index 0000000..0634167
--- /dev/null
+++ b/chrome/browser/google/google_util_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/google/google_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using google_util::IsGoogleHomePageUrl;
+
+TEST(GoogleUtilTest, GoodHomePagesNonSecure) {
+ // Valid home page hosts.
+ EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/"));
+
+ // Only the paths /, /webhp, and /ig.* are valid. Query parameters are
+ // ignored.
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp?rlz=TEST"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig?rlz=TEST"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo?rlz=TEST"));
+}
+
+TEST(GoogleUtilTest, GoodHomePagesSecure) {
+ // Valid home page hosts.
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://google.com"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.ca"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.co.uk"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com:443/"));
+
+ // Only the paths /, /webhp, and /ig.* are valid. Query parameters are
+ // ignored.
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp?rlz=TEST"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig?rlz=TEST"));
+ EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo?rlz=TEST"));
+}
+
+TEST(GoogleUtilTest, BadHomePages) {
+ EXPECT_FALSE(IsGoogleHomePageUrl(""));
+
+ // If specified, only the "www" subdomain is OK.
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://maps.google.com"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://foo.google.com"));
+
+ // No non-standard port numbers.
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com:1234"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com:5678"));
+
+ // Invalid TLDs.
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com.abc"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc.com"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.ab.cd"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.uk.qq"));
+
+ // Must be http or https.
+ EXPECT_FALSE(IsGoogleHomePageUrl("ftp://www.google.com"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("file://does/not/exist"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("bad://www.google.com"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("www.google.com"));
+
+ // Only the paths /, /webhp, and /ig.* are valid.
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abc"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhpabc"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/abc"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abcig"));
+ EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/ig"));
+}