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

Side by Side Diff: components/google/core/browser/google_util_unittest.cc

Issue 2861183002: Google search subdomains included for Safesearch (Closed)
Patch Set: Nits Created 3 years, 7 months 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
« no previous file with comments | « components/google/core/browser/google_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "components/google/core/browser/google_switches.h" 8 #include "components/google/core/browser/google_switches.h"
9 #include "components/google/core/browser/google_url_tracker.h" 9 #include "components/google/core/browser/google_url_tracker.h"
10 #include "components/google/core/browser/google_util.h" 10 #include "components/google/core/browser/google_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are 58 // Only the paths /, /webhp, and /ig.* are valid. Query parameters are
59 // ignored. 59 // ignored.
60 EXPECT_TRUE(IsHomePage("http://www.google.com/")); 60 EXPECT_TRUE(IsHomePage("http://www.google.com/"));
61 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp")); 61 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp"));
62 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp?rlz=TEST")); 62 EXPECT_TRUE(IsHomePage("http://www.google.com/webhp?rlz=TEST"));
63 EXPECT_TRUE(IsHomePage("http://www.google.com/ig")); 63 EXPECT_TRUE(IsHomePage("http://www.google.com/ig"));
64 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo")); 64 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo"));
65 EXPECT_TRUE(IsHomePage("http://www.google.com/ig?rlz=TEST")); 65 EXPECT_TRUE(IsHomePage("http://www.google.com/ig?rlz=TEST"));
66 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo?rlz=TEST")); 66 EXPECT_TRUE(IsHomePage("http://www.google.com/ig/foo?rlz=TEST"));
67
68 // Accepted subdomains.
69 EXPECT_TRUE(IsHomePage("http://ipv4.google.com/"));
70 EXPECT_TRUE(IsHomePage("http://ipv6.google.com/"));
71
72 // Trailing dots.
73 EXPECT_TRUE(IsHomePage("http://ipv4.google.com./"));
74 EXPECT_TRUE(IsHomePage("http://google.com./"));
67 } 75 }
68 76
69 TEST(GoogleUtilTest, GoodHomePagesSecure) { 77 TEST(GoogleUtilTest, GoodHomePagesSecure) {
70 // Valid home page hosts. 78 // Valid home page hosts.
71 EXPECT_TRUE(IsHomePage("https://google.com")); 79 EXPECT_TRUE(IsHomePage("https://google.com"));
72 EXPECT_TRUE(IsHomePage("https://www.google.com")); 80 EXPECT_TRUE(IsHomePage("https://www.google.com"));
73 EXPECT_TRUE(IsHomePage("https://www.google.ca")); 81 EXPECT_TRUE(IsHomePage("https://www.google.ca"));
74 EXPECT_TRUE(IsHomePage("https://www.google.co.uk")); 82 EXPECT_TRUE(IsHomePage("https://www.google.co.uk"));
75 EXPECT_TRUE(IsHomePage("https://www.google.com:443/")); 83 EXPECT_TRUE(IsHomePage("https://www.google.com:443/"));
76 84
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_FALSE(IsHomePage("http://www.google.com/webhpabc")); 122 EXPECT_FALSE(IsHomePage("http://www.google.com/webhpabc"));
115 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/abc")); 123 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/abc"));
116 EXPECT_FALSE(IsHomePage("http://www.google.com/abcig")); 124 EXPECT_FALSE(IsHomePage("http://www.google.com/abcig"));
117 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/ig")); 125 EXPECT_FALSE(IsHomePage("http://www.google.com/webhp/ig"));
118 126
119 // A search URL should not be identified as a home page URL. 127 // A search URL should not be identified as a home page URL.
120 EXPECT_FALSE(IsHomePage("http://www.google.com/search?q=something")); 128 EXPECT_FALSE(IsHomePage("http://www.google.com/search?q=something"));
121 129
122 // Path is case sensitive. 130 // Path is case sensitive.
123 EXPECT_FALSE(IsHomePage("https://www.google.com/WEBHP")); 131 EXPECT_FALSE(IsHomePage("https://www.google.com/WEBHP"));
132
133 // Only .com subdomain and no www.
134 EXPECT_FALSE(IsHomePage("http://ipv4.google.co.uk"));
135 EXPECT_FALSE(IsHomePage("http://www.ipv4.google.com"));
124 } 136 }
125 137
126 TEST(GoogleUtilTest, GoodSearches) { 138 TEST(GoogleUtilTest, GoodSearches) {
127 const std::string patterns[] = { 139 const std::string patterns[] = {
128 // Queries with path "/search" need to have the query parameter in either 140 // Queries with path "/search" need to have the query parameter in either
129 // the url parameter or the hash fragment. 141 // the url parameter or the hash fragment.
130 "%s://www.google.com/search?%s=something", 142 "%s://www.google.com/search?%s=something",
131 "%s://www.google.com/search#%s=something", 143 "%s://www.google.com/search#%s=something",
132 "%s://www.google.com/search?name=bob&%s=something", 144 "%s://www.google.com/search?name=bob&%s=something",
133 "%s://www.google.com/search?name=bob#%s=something", 145 "%s://www.google.com/search?name=bob#%s=something",
134 "%s://www.google.com/search?name=bob#age=24&%s=thng", 146 "%s://www.google.com/search?name=bob#age=24&%s=thng",
135 "%s://www.google.co.uk/search?%s=something", 147 "%s://www.google.co.uk/search?%s=something",
136 // It's actually valid for both to have the query parameter. 148 // It's actually valid for both to have the query parameter.
137 "%s://www.google.com/search?%s=something#q=other", 149 "%s://www.google.com/search?%s=something#q=other",
138 150
139 // Queries with path "/webhp", "/" or "" need to have the query parameter in 151 // Queries with path "/webhp", "/" or "" need to have the query parameter
140 // the hash fragment. 152 // in the hash fragment.
141 "%s://www.google.com/webhp#%s=something", 153 "%s://www.google.com/webhp#%s=something",
142 "%s://www.google.com/webhp#name=bob&%s=something", 154 "%s://www.google.com/webhp#name=bob&%s=something",
143 "%s://www.google.com/webhp?name=bob#%s=something", 155 "%s://www.google.com/webhp?name=bob#%s=something",
144 "%s://www.google.com/webhp?name=bob#age=24&%s=thing", 156 "%s://www.google.com/webhp?name=bob#age=24&%s=thing",
145 157
146 "%s://www.google.com/#%s=something", 158 "%s://www.google.com/#%s=something",
147 "%s://www.google.com/#name=bob&%s=something", 159 "%s://www.google.com/#name=bob&%s=something",
148 "%s://www.google.com/?name=bob#%s=something", 160 "%s://www.google.com/?name=bob#%s=something",
149 "%s://www.google.com/?name=bob#age=24&%s=something", 161 "%s://www.google.com/?name=bob#age=24&%s=something",
150 162
151 "%s://www.google.com#%s=something", 163 "%s://www.google.com#%s=something",
152 "%s://www.google.com#name=bob&%s=something", 164 "%s://www.google.com#name=bob&%s=something",
153 "%s://www.google.com?name=bob#%s=something", 165 "%s://www.google.com?name=bob#%s=something",
154 "%s://www.google.com?name=bob#age=24&%s=something" 166 "%s://www.google.com?name=bob#age=24&%s=something",
155 }; 167
168 // Google subdomain queries.
169 "%s://ipv4.google.com/search?%s=something",
170 "%s://ipv4.google.com#name=bob&%s=something",
171 "%s://ipv6.google.com?name=bob#%s=something",
172 "%s://ipv6.google.com?name=bob#age=24&%s=something",
173
174 // Trailing dots in the hosts.
175 "%s://www.google.com./#%s=something", "%s://www.google.de./#%s=something",
176 "%s://ipv4.google.com./#%s=something",
177 "%s://ipv6.google.com./#%s=something"};
156 178
157 for (const std::string& pattern : patterns) { 179 for (const std::string& pattern : patterns) {
158 for (const std::string& scheme : kValidSearchSchemes) { 180 for (const std::string& scheme : kValidSearchSchemes) {
159 for (const std::string& query_param : kValidSearchQueryParams) { 181 for (const std::string& query_param : kValidSearchQueryParams) {
160 EXPECT_TRUE(IsSearch(base::StringPrintf(pattern.c_str(), 182 EXPECT_TRUE(IsSearch(base::StringPrintf(pattern.c_str(),
161 scheme.c_str(), 183 scheme.c_str(),
162 query_param.c_str()))); 184 query_param.c_str())));
163 } 185 }
164 } 186 }
165 } 187 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), 444 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"),
423 google_util::DISALLOW_SUBDOMAIN, 445 google_util::DISALLOW_SUBDOMAIN,
424 google_util::DISALLOW_NON_STANDARD_PORTS)); 446 google_util::DISALLOW_NON_STANDARD_PORTS));
425 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"), 447 EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.com:123"),
426 google_util::DISALLOW_SUBDOMAIN, 448 google_util::DISALLOW_SUBDOMAIN,
427 google_util::ALLOW_NON_STANDARD_PORTS)); 449 google_util::ALLOW_NON_STANDARD_PORTS));
428 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("file://www.youtube.com"), 450 EXPECT_FALSE(IsYoutubeDomainUrl(GURL("file://www.youtube.com"),
429 google_util::DISALLOW_SUBDOMAIN, 451 google_util::DISALLOW_SUBDOMAIN,
430 google_util::DISALLOW_NON_STANDARD_PORTS)); 452 google_util::DISALLOW_NON_STANDARD_PORTS));
431 } 453 }
OLDNEW
« no previous file with comments | « components/google/core/browser/google_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698