| OLD | NEW |
| 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 6 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 #include "url/origin.h" | 9 #include "url/origin.h" |
| 10 #include "url/url_features.h" | 10 #include "url/url_features.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return GetCanonicalHostRegistryLength(host, EXCLUDE_UNKNOWN_REGISTRIES, | 84 return GetCanonicalHostRegistryLength(host, EXCLUDE_UNKNOWN_REGISTRIES, |
| 85 INCLUDE_PRIVATE_REGISTRIES); | 85 INCLUDE_PRIVATE_REGISTRIES); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 class RegistryControlledDomainTest : public testing::Test { | 90 class RegistryControlledDomainTest : public testing::Test { |
| 91 protected: | 91 protected: |
| 92 template <typename Graph> | 92 template <typename Graph> |
| 93 void UseDomainData(const Graph& graph) { | 93 void UseDomainData(const Graph& graph) { |
| 94 // This is undone in TearDown. |
| 94 SetFindDomainGraph(graph, sizeof(Graph)); | 95 SetFindDomainGraph(graph, sizeof(Graph)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool CompareDomains(const std::string& url1, const std::string& url2) { | 98 bool CompareDomains(const std::string& url1, const std::string& url2) { |
| 98 SCOPED_TRACE(url1 + " " + url2); | 99 SCOPED_TRACE(url1 + " " + url2); |
| 99 GURL g1 = GURL(url1); | 100 GURL g1 = GURL(url1); |
| 100 GURL g2 = GURL(url2); | 101 GURL g2 = GURL(url2); |
| 101 url::Origin o1 = url::Origin(g1); | 102 url::Origin o1 = url::Origin(g1); |
| 102 url::Origin o2 = url::Origin(g2); | 103 url::Origin o2 = url::Origin(g2); |
| 103 EXPECT_EQ(SameDomainOrHost(o1, o2, EXCLUDE_PRIVATE_REGISTRIES), | 104 EXPECT_EQ(SameDomainOrHost(o1, o2, EXCLUDE_PRIVATE_REGISTRIES), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 EXPECT_EQ("", GetDomainFromHost("192.168.0.1")); | 166 EXPECT_EQ("", GetDomainFromHost("192.168.0.1")); |
| 166 EXPECT_EQ("", GetDomainFromHost("localhost.")); | 167 EXPECT_EQ("", GetDomainFromHost("localhost.")); |
| 167 EXPECT_EQ("", GetDomainFromHost(".localhost.")); | 168 EXPECT_EQ("", GetDomainFromHost(".localhost.")); |
| 168 } | 169 } |
| 169 | 170 |
| 170 TEST_F(RegistryControlledDomainTest, TestGetRegistryLength) { | 171 TEST_F(RegistryControlledDomainTest, TestGetRegistryLength) { |
| 171 UseDomainData(test1::kDafsa); | 172 UseDomainData(test1::kDafsa); |
| 172 | 173 |
| 173 // Test GURL version of GetRegistryLength(). | 174 // Test GURL version of GetRegistryLength(). |
| 174 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://a.baz.jp/file.html", | 175 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://a.baz.jp/file.html", |
| 175 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 176 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 176 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.baz.jp./file.html", | 177 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.baz.jp./file.html", |
| 177 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 178 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 178 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://ac.jp", | 179 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://ac.jp", |
| 179 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 | 180 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 |
| 180 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://a.bar.jp", | 181 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://a.bar.jp", |
| 181 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 182 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 182 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://bar.jp", | 183 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://bar.jp", |
| 183 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 184 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 185 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://xbar.jp", |
| 186 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 184 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.bar.jp", | 187 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.bar.jp", |
| 185 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 | 188 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 189 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://.baz.bar.jp", |
| 190 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 191 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://..baz.bar.jp", |
| 192 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 193 EXPECT_EQ(11U, GetRegistryLengthFromURL("http://foo..baz.bar.jp", |
| 194 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 195 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://xbaz.bar.jp", |
| 196 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 197 EXPECT_EQ(11U, GetRegistryLengthFromURL("http://x.xbaz.bar.jp", |
| 198 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 186 EXPECT_EQ(12U, GetRegistryLengthFromURL("http://a.b.baz.bar.jp", | 199 EXPECT_EQ(12U, GetRegistryLengthFromURL("http://a.b.baz.bar.jp", |
| 187 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 | 200 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 |
| 188 EXPECT_EQ(6U, GetRegistryLengthFromURL("http://baz.pref.bar.jp", | 201 EXPECT_EQ(6U, GetRegistryLengthFromURL("http://baz.pref.bar.jp", |
| 189 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 | 202 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 203 EXPECT_EQ(6U, GetRegistryLengthFromURL("http://z.baz.pref.bar.jp", |
| 204 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 205 EXPECT_EQ(10U, GetRegistryLengthFromURL("http://p.ref.bar.jp", |
| 206 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 207 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://xpref.bar.jp", |
| 208 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 209 EXPECT_EQ(12U, GetRegistryLengthFromURL("http://baz.xpref.bar.jp", |
| 210 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 211 EXPECT_EQ(6U, GetRegistryLengthFromURL("http://baz..pref.bar.jp", |
| 212 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 190 EXPECT_EQ(11U, GetRegistryLengthFromURL("http://a.b.bar.baz.com", | 213 EXPECT_EQ(11U, GetRegistryLengthFromURL("http://a.b.bar.baz.com", |
| 191 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 | 214 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 |
| 192 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.d.c", | 215 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.d.c", |
| 193 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 216 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 194 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://.a.d.c", | 217 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://.a.d.c", |
| 195 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 218 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 196 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://..a.d.c", | 219 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://..a.d.c", |
| 197 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 220 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 198 EXPECT_EQ(1U, GetRegistryLengthFromURL("http://a.b.c", | 221 EXPECT_EQ(1U, GetRegistryLengthFromURL("http://a.b.c", |
| 199 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 | 222 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 |
| 200 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com", | 223 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com", |
| 201 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 224 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 202 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com.", | 225 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com.", |
| 203 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 226 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 204 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://baz.com", | 227 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://baz.com", |
| 205 INCLUDE_UNKNOWN_REGISTRIES)); // none | 228 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 206 EXPECT_EQ(4U, GetRegistryLengthFromURL("http://baz.com.", | 229 EXPECT_EQ(4U, GetRegistryLengthFromURL("http://baz.com.", |
| 207 INCLUDE_UNKNOWN_REGISTRIES)); // none | 230 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 208 | 231 |
| 209 EXPECT_EQ(std::string::npos, | 232 EXPECT_EQ(std::string::npos, |
| 210 GetRegistryLengthFromURL(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); | 233 GetRegistryLengthFromURL(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); |
| 211 EXPECT_EQ(std::string::npos, | 234 EXPECT_EQ(std::string::npos, |
| 212 GetRegistryLengthFromURL("http://", EXCLUDE_UNKNOWN_REGISTRIES)); | 235 GetRegistryLengthFromURL("http://", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 213 EXPECT_EQ(std::string::npos, | 236 EXPECT_EQ(std::string::npos, |
| 214 GetRegistryLengthFromURL("file:///C:/file.html", | 237 GetRegistryLengthFromURL("file:///C:/file.html", |
| 215 EXCLUDE_UNKNOWN_REGISTRIES)); | 238 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 216 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://foo.com..", | 239 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://foo.com..", |
| 217 EXCLUDE_UNKNOWN_REGISTRIES)); | 240 EXCLUDE_UNKNOWN_REGISTRIES)); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 EXPECT_EQ(27U, PermissiveGetHostRegistryLength( | 619 EXPECT_EQ(27U, PermissiveGetHostRegistryLength( |
| 597 "Www.Google%EF%BC%8E%EF%BC%AA%EF%BD%90%EF%BC%8E")); | 620 "Www.Google%EF%BC%8E%EF%BC%AA%EF%BD%90%EF%BC%8E")); |
| 598 // UTF-16 (ending in a dot). | 621 // UTF-16 (ending in a dot). |
| 599 EXPECT_EQ(3U, PermissiveGetHostRegistryLength( | 622 EXPECT_EQ(3U, PermissiveGetHostRegistryLength( |
| 600 base::WideToUTF16(L"Www.Google\xFF0E\xFF2A\xFF50\xFF0E"))); | 623 base::WideToUTF16(L"Www.Google\xFF0E\xFF2A\xFF50\xFF0E"))); |
| 601 #endif | 624 #endif |
| 602 } | 625 } |
| 603 | 626 |
| 604 } // namespace registry_controlled_domains | 627 } // namespace registry_controlled_domains |
| 605 } // namespace net | 628 } // namespace net |
| OLD | NEW |