summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google/google_util_unittest.cc
blob: 063416766c9966a5e11b03d24d493aa7df352a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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"));
}