Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/google/google_util_unittest.cc

Issue 8728004: Add more flexible handling of what is considered a google home page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix using directive Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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.
SteveT 2011/11/28 21:04:49 Add a case for "www.google.com" (schemeless but va
Roger Tawa OOO till Jul 10th 2011/11/29 16:00:09 Done.
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698