| 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 "net/base/registry_controlled_domains/registry_controlled_domain.h" | 5 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "url/gurl.h" | 7 #include "url/gurl.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 namespace test1 { | 10 namespace test1 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 std::string GetDomainFromURL(const std::string& url) { | 34 std::string GetDomainFromURL(const std::string& url) { |
| 35 return GetDomainAndRegistry(GURL(url), EXCLUDE_PRIVATE_REGISTRIES); | 35 return GetDomainAndRegistry(GURL(url), EXCLUDE_PRIVATE_REGISTRIES); |
| 36 } | 36 } |
| 37 | 37 |
| 38 std::string GetDomainFromHost(const std::string& host) { | 38 std::string GetDomainFromHost(const std::string& host) { |
| 39 return GetDomainAndRegistry(host, EXCLUDE_PRIVATE_REGISTRIES); | 39 return GetDomainAndRegistry(host, EXCLUDE_PRIVATE_REGISTRIES); |
| 40 } | 40 } |
| 41 | 41 |
| 42 size_t GetRegistryLengthFromURL( | 42 size_t GetRegistryLengthFromURL(const std::string& url, |
| 43 const std::string& url, | 43 UnknownRegistryFilter unknown_filter) { |
| 44 UnknownRegistryFilter unknown_filter) { | 44 return GetRegistryLength( |
| 45 return GetRegistryLength(GURL(url), | 45 GURL(url), unknown_filter, EXCLUDE_PRIVATE_REGISTRIES); |
| 46 unknown_filter, | |
| 47 EXCLUDE_PRIVATE_REGISTRIES); | |
| 48 } | 46 } |
| 49 | 47 |
| 50 size_t GetRegistryLengthFromURLIncludingPrivate( | 48 size_t GetRegistryLengthFromURLIncludingPrivate( |
| 51 const std::string& url, | 49 const std::string& url, |
| 52 UnknownRegistryFilter unknown_filter) { | 50 UnknownRegistryFilter unknown_filter) { |
| 53 return GetRegistryLength(GURL(url), | 51 return GetRegistryLength( |
| 54 unknown_filter, | 52 GURL(url), unknown_filter, INCLUDE_PRIVATE_REGISTRIES); |
| 55 INCLUDE_PRIVATE_REGISTRIES); | |
| 56 } | 53 } |
| 57 | 54 |
| 58 size_t GetRegistryLengthFromHost( | 55 size_t GetRegistryLengthFromHost(const std::string& host, |
| 59 const std::string& host, | 56 UnknownRegistryFilter unknown_filter) { |
| 60 UnknownRegistryFilter unknown_filter) { | |
| 61 return GetRegistryLength(host, unknown_filter, EXCLUDE_PRIVATE_REGISTRIES); | 57 return GetRegistryLength(host, unknown_filter, EXCLUDE_PRIVATE_REGISTRIES); |
| 62 } | 58 } |
| 63 | 59 |
| 64 size_t GetRegistryLengthFromHostIncludingPrivate( | 60 size_t GetRegistryLengthFromHostIncludingPrivate( |
| 65 const std::string& host, | 61 const std::string& host, |
| 66 UnknownRegistryFilter unknown_filter) { | 62 UnknownRegistryFilter unknown_filter) { |
| 67 return GetRegistryLength(host, unknown_filter, INCLUDE_PRIVATE_REGISTRIES); | 63 return GetRegistryLength(host, unknown_filter, INCLUDE_PRIVATE_REGISTRIES); |
| 68 } | 64 } |
| 69 | 65 |
| 70 bool CompareDomains(const std::string& url1, const std::string& url2) { | 66 bool CompareDomains(const std::string& url1, const std::string& url2) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 89 UseDomainData(test1::kDafsa); | 85 UseDomainData(test1::kDafsa); |
| 90 | 86 |
| 91 // Test GURL version of GetDomainAndRegistry(). | 87 // Test GURL version of GetDomainAndRegistry(). |
| 92 EXPECT_EQ("baz.jp", GetDomainFromURL("http://a.baz.jp/file.html")); // 1 | 88 EXPECT_EQ("baz.jp", GetDomainFromURL("http://a.baz.jp/file.html")); // 1 |
| 93 EXPECT_EQ("baz.jp.", GetDomainFromURL("http://a.baz.jp./file.html")); // 1 | 89 EXPECT_EQ("baz.jp.", GetDomainFromURL("http://a.baz.jp./file.html")); // 1 |
| 94 EXPECT_EQ("", GetDomainFromURL("http://ac.jp")); // 2 | 90 EXPECT_EQ("", GetDomainFromURL("http://ac.jp")); // 2 |
| 95 EXPECT_EQ("", GetDomainFromURL("http://a.bar.jp")); // 3 | 91 EXPECT_EQ("", GetDomainFromURL("http://a.bar.jp")); // 3 |
| 96 EXPECT_EQ("", GetDomainFromURL("http://bar.jp")); // 3 | 92 EXPECT_EQ("", GetDomainFromURL("http://bar.jp")); // 3 |
| 97 EXPECT_EQ("", GetDomainFromURL("http://baz.bar.jp")); // 3 4 | 93 EXPECT_EQ("", GetDomainFromURL("http://baz.bar.jp")); // 3 4 |
| 98 EXPECT_EQ("a.b.baz.bar.jp", GetDomainFromURL("http://a.b.baz.bar.jp")); | 94 EXPECT_EQ("a.b.baz.bar.jp", GetDomainFromURL("http://a.b.baz.bar.jp")); |
| 99 // 4 | 95 // 4 |
| 100 EXPECT_EQ("pref.bar.jp", GetDomainFromURL("http://baz.pref.bar.jp")); // 5 | 96 EXPECT_EQ("pref.bar.jp", GetDomainFromURL("http://baz.pref.bar.jp")); // 5 |
| 101 EXPECT_EQ("b.bar.baz.com.", GetDomainFromURL("http://a.b.bar.baz.com.")); | 97 EXPECT_EQ("b.bar.baz.com.", GetDomainFromURL("http://a.b.bar.baz.com.")); |
| 102 // 6 | 98 // 6 |
| 103 EXPECT_EQ("a.d.c", GetDomainFromURL("http://a.d.c")); // 7 | 99 EXPECT_EQ("a.d.c", GetDomainFromURL("http://a.d.c")); // 7 |
| 104 EXPECT_EQ("a.d.c", GetDomainFromURL("http://.a.d.c")); // 7 | 100 EXPECT_EQ("a.d.c", GetDomainFromURL("http://.a.d.c")); // 7 |
| 105 EXPECT_EQ("a.d.c", GetDomainFromURL("http://..a.d.c")); // 7 | 101 EXPECT_EQ("a.d.c", GetDomainFromURL("http://..a.d.c")); // 7 |
| 106 EXPECT_EQ("b.c", GetDomainFromURL("http://a.b.c")); // 7 8 | 102 EXPECT_EQ("b.c", GetDomainFromURL("http://a.b.c")); // 7 8 |
| 107 EXPECT_EQ("baz.com", GetDomainFromURL("http://baz.com")); // none | 103 EXPECT_EQ("baz.com", GetDomainFromURL("http://baz.com")); // none |
| 108 EXPECT_EQ("baz.com.", GetDomainFromURL("http://baz.com.")); // none | 104 EXPECT_EQ("baz.com.", GetDomainFromURL("http://baz.com.")); // none |
| 109 | 105 |
| 110 EXPECT_EQ("", GetDomainFromURL(std::string())); | 106 EXPECT_EQ("", GetDomainFromURL(std::string())); |
| 111 EXPECT_EQ("", GetDomainFromURL("http://")); | 107 EXPECT_EQ("", GetDomainFromURL("http://")); |
| 112 EXPECT_EQ("", GetDomainFromURL("file:///C:/file.html")); | 108 EXPECT_EQ("", GetDomainFromURL("file:///C:/file.html")); |
| 113 EXPECT_EQ("", GetDomainFromURL("http://foo.com..")); | 109 EXPECT_EQ("", GetDomainFromURL("http://foo.com..")); |
| 114 EXPECT_EQ("", GetDomainFromURL("http://...")); | 110 EXPECT_EQ("", GetDomainFromURL("http://...")); |
| 115 EXPECT_EQ("", GetDomainFromURL("http://192.168.0.1")); | 111 EXPECT_EQ("", GetDomainFromURL("http://192.168.0.1")); |
| 116 EXPECT_EQ("", GetDomainFromURL("http://localhost")); | 112 EXPECT_EQ("", GetDomainFromURL("http://localhost")); |
| 117 EXPECT_EQ("", GetDomainFromURL("http://localhost.")); | 113 EXPECT_EQ("", GetDomainFromURL("http://localhost.")); |
| 118 EXPECT_EQ("", GetDomainFromURL("http:////Comment")); | 114 EXPECT_EQ("", GetDomainFromURL("http:////Comment")); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 141 EXPECT_EQ("", GetDomainFromHost("...")); | 137 EXPECT_EQ("", GetDomainFromHost("...")); |
| 142 EXPECT_EQ("", GetDomainFromHost("192.168.0.1")); | 138 EXPECT_EQ("", GetDomainFromHost("192.168.0.1")); |
| 143 EXPECT_EQ("", GetDomainFromHost("localhost.")); | 139 EXPECT_EQ("", GetDomainFromHost("localhost.")); |
| 144 EXPECT_EQ("", GetDomainFromHost(".localhost.")); | 140 EXPECT_EQ("", GetDomainFromHost(".localhost.")); |
| 145 } | 141 } |
| 146 | 142 |
| 147 TEST_F(RegistryControlledDomainTest, TestGetRegistryLength) { | 143 TEST_F(RegistryControlledDomainTest, TestGetRegistryLength) { |
| 148 UseDomainData(test1::kDafsa); | 144 UseDomainData(test1::kDafsa); |
| 149 | 145 |
| 150 // Test GURL version of GetRegistryLength(). | 146 // Test GURL version of GetRegistryLength(). |
| 151 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://a.baz.jp/file.html", | 147 EXPECT_EQ(2U, |
| 152 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 148 GetRegistryLengthFromURL("http://a.baz.jp/file.html", |
| 153 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.baz.jp./file.html", | 149 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 154 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 150 EXPECT_EQ(3U, |
| 155 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://ac.jp", | 151 GetRegistryLengthFromURL("http://a.baz.jp./file.html", |
| 156 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 | 152 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 157 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://a.bar.jp", | 153 EXPECT_EQ(0U, |
| 158 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 154 GetRegistryLengthFromURL("http://ac.jp", |
| 159 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://bar.jp", | 155 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 |
| 160 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 156 EXPECT_EQ(0U, |
| 161 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.bar.jp", | 157 GetRegistryLengthFromURL("http://a.bar.jp", |
| 162 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 | 158 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 163 EXPECT_EQ(12U, GetRegistryLengthFromURL("http://a.b.baz.bar.jp", | 159 EXPECT_EQ(0U, |
| 164 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 | 160 GetRegistryLengthFromURL("http://bar.jp", |
| 165 EXPECT_EQ(6U, GetRegistryLengthFromURL("http://baz.pref.bar.jp", | 161 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 166 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 | 162 EXPECT_EQ(0U, |
| 167 EXPECT_EQ(11U, GetRegistryLengthFromURL("http://a.b.bar.baz.com", | 163 GetRegistryLengthFromURL("http://baz.bar.jp", |
| 168 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 | 164 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 169 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.d.c", | 165 EXPECT_EQ(12U, |
| 170 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 166 GetRegistryLengthFromURL("http://a.b.baz.bar.jp", |
| 171 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://.a.d.c", | 167 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 |
| 172 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 168 EXPECT_EQ(6U, |
| 173 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://..a.d.c", | 169 GetRegistryLengthFromURL("http://baz.pref.bar.jp", |
| 174 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 170 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 175 EXPECT_EQ(1U, GetRegistryLengthFromURL("http://a.b.c", | 171 EXPECT_EQ(11U, |
| 176 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 | 172 GetRegistryLengthFromURL("http://a.b.bar.baz.com", |
| 177 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com", | 173 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 |
| 178 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 174 EXPECT_EQ(3U, |
| 179 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com.", | 175 GetRegistryLengthFromURL("http://a.d.c", |
| 180 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 176 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 181 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://baz.com", | 177 EXPECT_EQ(3U, |
| 182 INCLUDE_UNKNOWN_REGISTRIES)); // none | 178 GetRegistryLengthFromURL("http://.a.d.c", |
| 183 EXPECT_EQ(4U, GetRegistryLengthFromURL("http://baz.com.", | 179 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 184 INCLUDE_UNKNOWN_REGISTRIES)); // none | 180 EXPECT_EQ(3U, |
| 181 GetRegistryLengthFromURL("http://..a.d.c", |
| 182 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 183 EXPECT_EQ(1U, |
| 184 GetRegistryLengthFromURL("http://a.b.c", |
| 185 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 |
| 186 EXPECT_EQ(0U, |
| 187 GetRegistryLengthFromURL("http://baz.com", |
| 188 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 189 EXPECT_EQ(0U, |
| 190 GetRegistryLengthFromURL("http://baz.com.", |
| 191 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 192 EXPECT_EQ(3U, |
| 193 GetRegistryLengthFromURL("http://baz.com", |
| 194 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 195 EXPECT_EQ(4U, |
| 196 GetRegistryLengthFromURL("http://baz.com.", |
| 197 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 185 | 198 |
| 186 EXPECT_EQ(std::string::npos, | 199 EXPECT_EQ( |
| 200 std::string::npos, |
| 187 GetRegistryLengthFromURL(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); | 201 GetRegistryLengthFromURL(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); |
| 188 EXPECT_EQ(std::string::npos, | 202 EXPECT_EQ(std::string::npos, |
| 189 GetRegistryLengthFromURL("http://", EXCLUDE_UNKNOWN_REGISTRIES)); | 203 GetRegistryLengthFromURL("http://", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 190 EXPECT_EQ(std::string::npos, | 204 EXPECT_EQ(std::string::npos, |
| 191 GetRegistryLengthFromURL("file:///C:/file.html", | 205 GetRegistryLengthFromURL("file:///C:/file.html", |
| 192 EXCLUDE_UNKNOWN_REGISTRIES)); | 206 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 193 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://foo.com..", | 207 EXPECT_EQ( |
| 194 EXCLUDE_UNKNOWN_REGISTRIES)); | 208 0U, |
| 195 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://...", | 209 GetRegistryLengthFromURL("http://foo.com..", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 196 EXCLUDE_UNKNOWN_REGISTRIES)); | 210 EXPECT_EQ(0U, |
| 197 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://192.168.0.1", | 211 GetRegistryLengthFromURL("http://...", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 198 EXCLUDE_UNKNOWN_REGISTRIES)); | 212 EXPECT_EQ(0U, |
| 199 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost", | 213 GetRegistryLengthFromURL("http://192.168.0.1", |
| 200 EXCLUDE_UNKNOWN_REGISTRIES)); | 214 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 201 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost", | 215 EXPECT_EQ( |
| 202 INCLUDE_UNKNOWN_REGISTRIES)); | 216 0U, |
| 203 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", | 217 GetRegistryLengthFromURL("http://localhost", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 204 EXCLUDE_UNKNOWN_REGISTRIES)); | 218 EXPECT_EQ( |
| 205 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", | 219 0U, |
| 206 INCLUDE_UNKNOWN_REGISTRIES)); | 220 GetRegistryLengthFromURL("http://localhost", INCLUDE_UNKNOWN_REGISTRIES)); |
| 207 EXPECT_EQ(0U, GetRegistryLengthFromURL("http:////Comment", | 221 EXPECT_EQ(0U, |
| 208 EXCLUDE_UNKNOWN_REGISTRIES)); | 222 GetRegistryLengthFromURL("http://localhost.", |
| 223 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 224 EXPECT_EQ(0U, |
| 225 GetRegistryLengthFromURL("http://localhost.", |
| 226 INCLUDE_UNKNOWN_REGISTRIES)); |
| 227 EXPECT_EQ( |
| 228 0U, |
| 229 GetRegistryLengthFromURL("http:////Comment", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 209 | 230 |
| 210 // Test std::string version of GetRegistryLength(). Uses the same | 231 // Test std::string version of GetRegistryLength(). Uses the same |
| 211 // underpinnings as the GURL version, so this is really more of a check of | 232 // underpinnings as the GURL version, so this is really more of a check of |
| 212 // CanonicalizeHost(). | 233 // CanonicalizeHost(). |
| 213 EXPECT_EQ(2U, GetRegistryLengthFromHost("a.baz.jp", | 234 EXPECT_EQ(2U, |
| 214 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 235 GetRegistryLengthFromHost("a.baz.jp", |
| 215 EXPECT_EQ(3U, GetRegistryLengthFromHost("a.baz.jp.", | 236 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 216 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 237 EXPECT_EQ(3U, |
| 217 EXPECT_EQ(0U, GetRegistryLengthFromHost("ac.jp", | 238 GetRegistryLengthFromHost("a.baz.jp.", |
| 218 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 | 239 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 219 EXPECT_EQ(0U, GetRegistryLengthFromHost("a.bar.jp", | 240 EXPECT_EQ(0U, |
| 220 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 241 GetRegistryLengthFromHost("ac.jp", |
| 221 EXPECT_EQ(0U, GetRegistryLengthFromHost("bar.jp", | 242 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 |
| 222 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 243 EXPECT_EQ(0U, |
| 223 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.bar.jp", | 244 GetRegistryLengthFromHost("a.bar.jp", |
| 224 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 | 245 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 225 EXPECT_EQ(12U, GetRegistryLengthFromHost("a.b.baz.bar.jp", | 246 EXPECT_EQ(0U, |
| 226 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 | 247 GetRegistryLengthFromHost("bar.jp", |
| 227 EXPECT_EQ(6U, GetRegistryLengthFromHost("baz.pref.bar.jp", | 248 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 228 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 | 249 EXPECT_EQ(0U, |
| 229 EXPECT_EQ(11U, GetRegistryLengthFromHost("a.b.bar.baz.com", | 250 GetRegistryLengthFromHost("baz.bar.jp", |
| 230 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 | 251 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 231 EXPECT_EQ(3U, GetRegistryLengthFromHost("a.d.c", | 252 EXPECT_EQ(12U, |
| 232 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 253 GetRegistryLengthFromHost("a.b.baz.bar.jp", |
| 233 EXPECT_EQ(3U, GetRegistryLengthFromHost(".a.d.c", | 254 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 |
| 234 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 255 EXPECT_EQ(6U, |
| 235 EXPECT_EQ(3U, GetRegistryLengthFromHost("..a.d.c", | 256 GetRegistryLengthFromHost("baz.pref.bar.jp", |
| 236 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 257 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 237 EXPECT_EQ(1U, GetRegistryLengthFromHost("a.b.c", | 258 EXPECT_EQ(11U, |
| 238 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 | 259 GetRegistryLengthFromHost("a.b.bar.baz.com", |
| 239 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.com", | 260 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 |
| 240 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 261 EXPECT_EQ(3U, |
| 241 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.com.", | 262 GetRegistryLengthFromHost("a.d.c", |
| 242 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 263 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 243 EXPECT_EQ(3U, GetRegistryLengthFromHost("baz.com", | 264 EXPECT_EQ(3U, |
| 244 INCLUDE_UNKNOWN_REGISTRIES)); // none | 265 GetRegistryLengthFromHost(".a.d.c", |
| 245 EXPECT_EQ(4U, GetRegistryLengthFromHost("baz.com.", | 266 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 246 INCLUDE_UNKNOWN_REGISTRIES)); // none | 267 EXPECT_EQ(3U, |
| 268 GetRegistryLengthFromHost("..a.d.c", |
| 269 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 270 EXPECT_EQ(1U, |
| 271 GetRegistryLengthFromHost("a.b.c", |
| 272 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 |
| 273 EXPECT_EQ(0U, |
| 274 GetRegistryLengthFromHost("baz.com", |
| 275 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 276 EXPECT_EQ(0U, |
| 277 GetRegistryLengthFromHost("baz.com.", |
| 278 EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 279 EXPECT_EQ(3U, |
| 280 GetRegistryLengthFromHost("baz.com", |
| 281 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 282 EXPECT_EQ(4U, |
| 283 GetRegistryLengthFromHost("baz.com.", |
| 284 INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 247 | 285 |
| 248 EXPECT_EQ(std::string::npos, | 286 EXPECT_EQ( |
| 287 std::string::npos, |
| 249 GetRegistryLengthFromHost(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); | 288 GetRegistryLengthFromHost(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); |
| 250 EXPECT_EQ(0U, GetRegistryLengthFromHost("foo.com..", | 289 EXPECT_EQ(0U, |
| 251 EXCLUDE_UNKNOWN_REGISTRIES)); | 290 GetRegistryLengthFromHost("foo.com..", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 252 EXPECT_EQ(0U, GetRegistryLengthFromHost("..", | 291 EXPECT_EQ(0U, GetRegistryLengthFromHost("..", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 253 EXCLUDE_UNKNOWN_REGISTRIES)); | 292 EXPECT_EQ( |
| 254 EXPECT_EQ(0U, GetRegistryLengthFromHost("192.168.0.1", | 293 0U, GetRegistryLengthFromHost("192.168.0.1", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 255 EXCLUDE_UNKNOWN_REGISTRIES)); | 294 EXPECT_EQ(0U, |
| 256 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost", | 295 GetRegistryLengthFromHost("localhost", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 257 EXCLUDE_UNKNOWN_REGISTRIES)); | 296 EXPECT_EQ(0U, |
| 258 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost", | 297 GetRegistryLengthFromHost("localhost", INCLUDE_UNKNOWN_REGISTRIES)); |
| 259 INCLUDE_UNKNOWN_REGISTRIES)); | 298 EXPECT_EQ( |
| 260 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost.", | 299 0U, GetRegistryLengthFromHost("localhost.", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 261 EXCLUDE_UNKNOWN_REGISTRIES)); | 300 EXPECT_EQ( |
| 262 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost.", | 301 0U, GetRegistryLengthFromHost("localhost.", INCLUDE_UNKNOWN_REGISTRIES)); |
| 263 INCLUDE_UNKNOWN_REGISTRIES)); | |
| 264 } | 302 } |
| 265 | 303 |
| 266 TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) { | 304 TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) { |
| 267 UseDomainData(test2::kDafsa); | 305 UseDomainData(test2::kDafsa); |
| 268 | 306 |
| 269 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", | 307 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", |
| 270 "http://a.b.bar.jp/file.html")); // b.bar.jp | 308 "http://a.b.bar.jp/file.html")); // b.bar.jp |
| 271 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", | 309 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", |
| 272 "http://b.b.bar.jp/file.html")); // b.bar.jp | 310 "http://b.b.bar.jp/file.html")); // b.bar.jp |
| 273 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp | 311 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp |
| 274 "http://a.not.jp/file.html")); // not.jp | 312 "http://a.not.jp/file.html")); // not.jp |
| 275 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp | 313 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp |
| 276 "http://a.foo.jp./file.html")); // foo.jp. | 314 "http://a.foo.jp./file.html")); // foo.jp. |
| 277 EXPECT_FALSE(CompareDomains("http://a.com/file.html", // a.com | 315 EXPECT_FALSE(CompareDomains("http://a.com/file.html", // a.com |
| 278 "http://b.com/file.html")); // b.com | 316 "http://b.com/file.html")); // b.com |
| 279 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", | 317 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", |
| 280 "http://b.x.com/file.html")); // x.com | 318 "http://b.x.com/file.html")); // x.com |
| 281 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", | 319 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", |
| 282 "http://.x.com/file.html")); // x.com | 320 "http://.x.com/file.html")); // x.com |
| 283 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", | 321 EXPECT_TRUE(CompareDomains("http://a.x.com/file.html", |
| 284 "http://..b.x.com/file.html")); // x.com | 322 "http://..b.x.com/file.html")); // x.com |
| 285 EXPECT_TRUE(CompareDomains("http://intranet/file.html", | 323 EXPECT_TRUE(CompareDomains("http://intranet/file.html", |
| 286 "http://intranet/file.html")); // intranet | 324 "http://intranet/file.html")); // intranet |
| 287 EXPECT_TRUE(CompareDomains("http://127.0.0.1/file.html", | 325 EXPECT_TRUE(CompareDomains("http://127.0.0.1/file.html", |
| 288 "http://127.0.0.1/file.html")); // 127.0.0.1 | 326 "http://127.0.0.1/file.html")); // 127.0.0.1 |
| 289 EXPECT_FALSE(CompareDomains("http://192.168.0.1/file.html", // 192.168.0.1 | 327 EXPECT_FALSE(CompareDomains("http://192.168.0.1/file.html", // 192.168.0.1 |
| 290 "http://127.0.0.1/file.html")); // 127.0.0.1 | 328 "http://127.0.0.1/file.html")); // 127.0.0.1 |
| 291 EXPECT_FALSE(CompareDomains("file:///C:/file.html", | 329 EXPECT_FALSE(CompareDomains("file:///C:/file.html", |
| 292 "file:///C:/file.html")); // no host | 330 "file:///C:/file.html")); // no host |
| 293 } | 331 } |
| 294 | 332 |
| 295 TEST_F(RegistryControlledDomainTest, TestDefaultData) { | 333 TEST_F(RegistryControlledDomainTest, TestDefaultData) { |
| 296 // Note that no data is set: we're using the default rules. | 334 // Note that no data is set: we're using the default rules. |
| 297 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://google.com", | 335 EXPECT_EQ(3U, |
| 298 EXCLUDE_UNKNOWN_REGISTRIES)); | 336 GetRegistryLengthFromURL("http://google.com", |
| 299 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://stanford.edu", | 337 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 300 EXCLUDE_UNKNOWN_REGISTRIES)); | 338 EXPECT_EQ(3U, |
| 301 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://ustreas.gov", | 339 GetRegistryLengthFromURL("http://stanford.edu", |
| 302 EXCLUDE_UNKNOWN_REGISTRIES)); | 340 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 303 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://icann.net", | 341 EXPECT_EQ(3U, |
| 304 EXCLUDE_UNKNOWN_REGISTRIES)); | 342 GetRegistryLengthFromURL("http://ustreas.gov", |
| 305 EXPECT_EQ(3U, GetRegistryLengthFromURL("http://ferretcentral.org", | 343 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 306 EXCLUDE_UNKNOWN_REGISTRIES)); | 344 EXPECT_EQ( |
| 307 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://nowhere.notavaliddomain", | 345 3U, |
| 308 EXCLUDE_UNKNOWN_REGISTRIES)); | 346 GetRegistryLengthFromURL("http://icann.net", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 309 EXPECT_EQ(15U, GetRegistryLengthFromURL("http://nowhere.notavaliddomain", | 347 EXPECT_EQ(3U, |
| 310 INCLUDE_UNKNOWN_REGISTRIES)); | 348 GetRegistryLengthFromURL("http://ferretcentral.org", |
| 349 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 350 EXPECT_EQ(0U, |
| 351 GetRegistryLengthFromURL("http://nowhere.notavaliddomain", |
| 352 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 353 EXPECT_EQ(15U, |
| 354 GetRegistryLengthFromURL("http://nowhere.notavaliddomain", |
| 355 INCLUDE_UNKNOWN_REGISTRIES)); |
| 311 } | 356 } |
| 312 | 357 |
| 313 TEST_F(RegistryControlledDomainTest, TestPrivateRegistryHandling) { | 358 TEST_F(RegistryControlledDomainTest, TestPrivateRegistryHandling) { |
| 314 UseDomainData(test1::kDafsa); | 359 UseDomainData(test1::kDafsa); |
| 315 | 360 |
| 316 // Testing the same dataset for INCLUDE_PRIVATE_REGISTRIES and | 361 // Testing the same dataset for INCLUDE_PRIVATE_REGISTRIES and |
| 317 // EXCLUDE_PRIVATE_REGISTRIES arguments. | 362 // EXCLUDE_PRIVATE_REGISTRIES arguments. |
| 318 // For the domain data used for this test, the private registries are | 363 // For the domain data used for this test, the private registries are |
| 319 // 'priv.no' and 'private'. | 364 // 'priv.no' and 'private'. |
| 320 | 365 |
| 321 // Non-private registries. | 366 // Non-private registries. |
| 322 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://priv.no", | 367 EXPECT_EQ( |
| 323 EXCLUDE_UNKNOWN_REGISTRIES)); | 368 2U, |
| 324 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://foo.priv.no", | 369 GetRegistryLengthFromURL("http://priv.no", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 325 EXCLUDE_UNKNOWN_REGISTRIES)); | 370 EXPECT_EQ(2U, |
| 326 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://foo.jp", | 371 GetRegistryLengthFromURL("http://foo.priv.no", |
| 327 EXCLUDE_UNKNOWN_REGISTRIES)); | 372 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 328 EXPECT_EQ(2U, GetRegistryLengthFromURL("http://www.foo.jp", | 373 EXPECT_EQ( |
| 329 EXCLUDE_UNKNOWN_REGISTRIES)); | 374 2U, |
| 330 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://private", | 375 GetRegistryLengthFromURL("http://foo.jp", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 331 EXCLUDE_UNKNOWN_REGISTRIES)); | 376 EXPECT_EQ(2U, |
| 332 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://foo.private", | 377 GetRegistryLengthFromURL("http://www.foo.jp", |
| 333 EXCLUDE_UNKNOWN_REGISTRIES)); | 378 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 334 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://private", | 379 EXPECT_EQ( |
| 335 INCLUDE_UNKNOWN_REGISTRIES)); | 380 0U, |
| 336 EXPECT_EQ(7U, GetRegistryLengthFromURL("http://foo.private", | 381 GetRegistryLengthFromURL("http://private", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 337 INCLUDE_UNKNOWN_REGISTRIES)); | 382 EXPECT_EQ(0U, |
| 383 GetRegistryLengthFromURL("http://foo.private", |
| 384 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 385 EXPECT_EQ( |
| 386 0U, |
| 387 GetRegistryLengthFromURL("http://private", INCLUDE_UNKNOWN_REGISTRIES)); |
| 388 EXPECT_EQ(7U, |
| 389 GetRegistryLengthFromURL("http://foo.private", |
| 390 INCLUDE_UNKNOWN_REGISTRIES)); |
| 338 | 391 |
| 339 // Private registries. | 392 // Private registries. |
| 340 EXPECT_EQ(0U, | 393 EXPECT_EQ(0U, |
| 341 GetRegistryLengthFromURLIncludingPrivate("http://priv.no", | 394 GetRegistryLengthFromURLIncludingPrivate( |
| 342 EXCLUDE_UNKNOWN_REGISTRIES)); | 395 "http://priv.no", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 343 EXPECT_EQ(7U, | 396 EXPECT_EQ(7U, |
| 344 GetRegistryLengthFromURLIncludingPrivate("http://foo.priv.no", | 397 GetRegistryLengthFromURLIncludingPrivate( |
| 345 EXCLUDE_UNKNOWN_REGISTRIES)); | 398 "http://foo.priv.no", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 346 EXPECT_EQ(2U, | 399 EXPECT_EQ(2U, |
| 347 GetRegistryLengthFromURLIncludingPrivate("http://foo.jp", | 400 GetRegistryLengthFromURLIncludingPrivate( |
| 348 EXCLUDE_UNKNOWN_REGISTRIES)); | 401 "http://foo.jp", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 349 EXPECT_EQ(2U, | 402 EXPECT_EQ(2U, |
| 350 GetRegistryLengthFromURLIncludingPrivate("http://www.foo.jp", | 403 GetRegistryLengthFromURLIncludingPrivate( |
| 351 EXCLUDE_UNKNOWN_REGISTRIES)); | 404 "http://www.foo.jp", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 352 EXPECT_EQ(0U, | 405 EXPECT_EQ(0U, |
| 353 GetRegistryLengthFromURLIncludingPrivate("http://private", | 406 GetRegistryLengthFromURLIncludingPrivate( |
| 354 EXCLUDE_UNKNOWN_REGISTRIES)); | 407 "http://private", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 355 EXPECT_EQ(7U, | 408 EXPECT_EQ(7U, |
| 356 GetRegistryLengthFromURLIncludingPrivate("http://foo.private", | 409 GetRegistryLengthFromURLIncludingPrivate( |
| 357 EXCLUDE_UNKNOWN_REGISTRIES)); | 410 "http://foo.private", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 358 EXPECT_EQ(0U, | 411 EXPECT_EQ(0U, |
| 359 GetRegistryLengthFromURLIncludingPrivate("http://private", | 412 GetRegistryLengthFromURLIncludingPrivate( |
| 360 INCLUDE_UNKNOWN_REGISTRIES)); | 413 "http://private", INCLUDE_UNKNOWN_REGISTRIES)); |
| 361 EXPECT_EQ(7U, | 414 EXPECT_EQ(7U, |
| 362 GetRegistryLengthFromURLIncludingPrivate("http://foo.private", | 415 GetRegistryLengthFromURLIncludingPrivate( |
| 363 INCLUDE_UNKNOWN_REGISTRIES)); | 416 "http://foo.private", INCLUDE_UNKNOWN_REGISTRIES)); |
| 364 } | 417 } |
| 365 | 418 |
| 366 TEST_F(RegistryControlledDomainTest, TestDafsaTwoByteOffsets) { | 419 TEST_F(RegistryControlledDomainTest, TestDafsaTwoByteOffsets) { |
| 367 UseDomainData(test3::kDafsa); | 420 UseDomainData(test3::kDafsa); |
| 368 | 421 |
| 369 // Testing to lookup keys in a DAFSA with two byte offsets. | 422 // Testing to lookup keys in a DAFSA with two byte offsets. |
| 370 // This DAFSA is constructed so that labels begin and end with unique | 423 // This DAFSA is constructed so that labels begin and end with unique |
| 371 // characters, which makes it impossible to merge labels. Each inner node | 424 // characters, which makes it impossible to merge labels. Each inner node |
| 372 // is about 100 bytes and a one byte offset can at most add 64 bytes to | 425 // is about 100 bytes and a one byte offset can at most add 64 bytes to |
| 373 // previous offset. Thus the paths must go over two byte offsets. | 426 // previous offset. Thus the paths must go over two byte offsets. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 GetRegistryLengthFromHostIncludingPrivate( | 544 GetRegistryLengthFromHostIncludingPrivate( |
| 492 key4, EXCLUDE_UNKNOWN_REGISTRIES)); | 545 key4, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 493 EXPECT_EQ(0U, | 546 EXPECT_EQ(0U, |
| 494 GetRegistryLengthFromHostIncludingPrivate( | 547 GetRegistryLengthFromHostIncludingPrivate( |
| 495 key5, EXCLUDE_UNKNOWN_REGISTRIES)); | 548 key5, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 496 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); | 549 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 497 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); | 550 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 498 } | 551 } |
| 499 } // namespace registry_controlled_domains | 552 } // namespace registry_controlled_domains |
| 500 } // namespace net | 553 } // namespace net |
| OLD | NEW |