Chromium Code Reviews| 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 #include "url/origin.h" | 8 #include "url/origin.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 } | 49 } |
| 50 | 50 |
| 51 size_t GetRegistryLengthFromURLIncludingPrivate( | 51 size_t GetRegistryLengthFromURLIncludingPrivate( |
| 52 const std::string& url, | 52 const std::string& url, |
| 53 UnknownRegistryFilter unknown_filter) { | 53 UnknownRegistryFilter unknown_filter) { |
| 54 return GetRegistryLength(GURL(url), | 54 return GetRegistryLength(GURL(url), |
| 55 unknown_filter, | 55 unknown_filter, |
| 56 INCLUDE_PRIVATE_REGISTRIES); | 56 INCLUDE_PRIVATE_REGISTRIES); |
| 57 } | 57 } |
| 58 | 58 |
| 59 size_t GetRegistryLengthFromHost( | 59 size_t GetRegistryLengthForCanonicalHost(const std::string& host, |
| 60 UnknownRegistryFilter unknown_filter) { | |
| 61 return GetRegistryLengthForCanonicalHost(host, unknown_filter, | |
| 62 EXCLUDE_PRIVATE_REGISTRIES); | |
| 63 } | |
| 64 | |
| 65 size_t GetRegistryLengthForCanonicalHostIncludingPrivate( | |
| 60 const std::string& host, | 66 const std::string& host, |
| 61 UnknownRegistryFilter unknown_filter) { | 67 UnknownRegistryFilter unknown_filter) { |
| 62 return GetRegistryLength(host, unknown_filter, EXCLUDE_PRIVATE_REGISTRIES); | 68 return GetRegistryLengthForCanonicalHost(host, unknown_filter, |
| 63 } | 69 INCLUDE_PRIVATE_REGISTRIES); |
| 64 | |
| 65 size_t GetRegistryLengthFromHostIncludingPrivate( | |
| 66 const std::string& host, | |
| 67 UnknownRegistryFilter unknown_filter) { | |
| 68 return GetRegistryLength(host, unknown_filter, INCLUDE_PRIVATE_REGISTRIES); | |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // namespace | 72 } // namespace |
| 72 | 73 |
| 73 class RegistryControlledDomainTest : public testing::Test { | 74 class RegistryControlledDomainTest : public testing::Test { |
| 74 protected: | 75 protected: |
| 75 template <typename Graph> | 76 template <typename Graph> |
| 76 void UseDomainData(const Graph& graph) { | 77 void UseDomainData(const Graph& graph) { |
| 77 SetFindDomainGraph(graph, sizeof(Graph)); | 78 SetFindDomainGraph(graph, sizeof(Graph)); |
| 78 } | 79 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", | 210 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", |
| 210 EXCLUDE_UNKNOWN_REGISTRIES)); | 211 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 211 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", | 212 EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", |
| 212 INCLUDE_UNKNOWN_REGISTRIES)); | 213 INCLUDE_UNKNOWN_REGISTRIES)); |
| 213 EXPECT_EQ(0U, GetRegistryLengthFromURL("http:////Comment", | 214 EXPECT_EQ(0U, GetRegistryLengthFromURL("http:////Comment", |
| 214 EXCLUDE_UNKNOWN_REGISTRIES)); | 215 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 215 | 216 |
| 216 // Test std::string version of GetRegistryLength(). Uses the same | 217 // Test std::string version of GetRegistryLength(). Uses the same |
| 217 // underpinnings as the GURL version, so this is really more of a check of | 218 // underpinnings as the GURL version, so this is really more of a check of |
| 218 // CanonicalizeHost(). | 219 // CanonicalizeHost(). |
| 219 EXPECT_EQ(2U, GetRegistryLengthFromHost("a.baz.jp", | 220 EXPECT_EQ(2U, GetRegistryLengthForCanonicalHost( |
| 220 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 221 "a.baz.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 221 EXPECT_EQ(3U, GetRegistryLengthFromHost("a.baz.jp.", | 222 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHost( |
| 222 EXCLUDE_UNKNOWN_REGISTRIES)); // 1 | 223 "a.baz.jp.", EXCLUDE_UNKNOWN_REGISTRIES)); // 1 |
| 223 EXPECT_EQ(0U, GetRegistryLengthFromHost("ac.jp", | 224 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 224 EXCLUDE_UNKNOWN_REGISTRIES)); // 2 | 225 "ac.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 2 |
| 225 EXPECT_EQ(0U, GetRegistryLengthFromHost("a.bar.jp", | 226 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 226 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 227 "a.bar.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 227 EXPECT_EQ(0U, GetRegistryLengthFromHost("bar.jp", | 228 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 228 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 | 229 "bar.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 3 |
| 229 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.bar.jp", | 230 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 230 EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 | 231 "baz.bar.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 3 4 |
| 231 EXPECT_EQ(12U, GetRegistryLengthFromHost("a.b.baz.bar.jp", | 232 EXPECT_EQ(12U, GetRegistryLengthForCanonicalHost( |
| 232 EXCLUDE_UNKNOWN_REGISTRIES)); // 4 | 233 "a.b.baz.bar.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 4 |
| 233 EXPECT_EQ(6U, GetRegistryLengthFromHost("baz.pref.bar.jp", | 234 EXPECT_EQ(6U, GetRegistryLengthForCanonicalHost( |
| 234 EXCLUDE_UNKNOWN_REGISTRIES)); // 5 | 235 "baz.pref.bar.jp", EXCLUDE_UNKNOWN_REGISTRIES)); // 5 |
| 235 EXPECT_EQ(11U, GetRegistryLengthFromHost("a.b.bar.baz.com", | 236 EXPECT_EQ(11U, GetRegistryLengthForCanonicalHost( |
| 236 EXCLUDE_UNKNOWN_REGISTRIES)); // 6 | 237 "a.b.bar.baz.com", EXCLUDE_UNKNOWN_REGISTRIES)); // 6 |
| 237 EXPECT_EQ(3U, GetRegistryLengthFromHost("a.d.c", | 238 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHost( |
| 238 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 239 "a.d.c", EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 239 EXPECT_EQ(3U, GetRegistryLengthFromHost(".a.d.c", | 240 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHost( |
| 240 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 241 ".a.d.c", EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 241 EXPECT_EQ(3U, GetRegistryLengthFromHost("..a.d.c", | 242 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHost( |
| 242 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 | 243 "..a.d.c", EXCLUDE_UNKNOWN_REGISTRIES)); // 7 |
| 243 EXPECT_EQ(1U, GetRegistryLengthFromHost("a.b.c", | 244 EXPECT_EQ(1U, GetRegistryLengthForCanonicalHost( |
| 244 EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 | 245 "a.b.c", EXCLUDE_UNKNOWN_REGISTRIES)); // 7 8 |
| 245 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.com", | 246 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 246 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 247 "baz.com", EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 247 EXPECT_EQ(0U, GetRegistryLengthFromHost("baz.com.", | 248 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost( |
| 248 EXCLUDE_UNKNOWN_REGISTRIES)); // none | 249 "baz.com.", EXCLUDE_UNKNOWN_REGISTRIES)); // none |
| 249 EXPECT_EQ(3U, GetRegistryLengthFromHost("baz.com", | 250 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHost( |
| 250 INCLUDE_UNKNOWN_REGISTRIES)); // none | 251 "baz.com", INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 251 EXPECT_EQ(4U, GetRegistryLengthFromHost("baz.com.", | 252 EXPECT_EQ(4U, GetRegistryLengthForCanonicalHost( |
| 252 INCLUDE_UNKNOWN_REGISTRIES)); // none | 253 "baz.com.", INCLUDE_UNKNOWN_REGISTRIES)); // none |
| 253 | 254 |
| 254 EXPECT_EQ(std::string::npos, | 255 EXPECT_EQ(std::string::npos, GetRegistryLengthForCanonicalHost( |
| 255 GetRegistryLengthFromHost(std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); | 256 std::string(), EXCLUDE_UNKNOWN_REGISTRIES)); |
| 256 EXPECT_EQ(0U, GetRegistryLengthFromHost("foo.com..", | 257 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("foo.com..", |
| 257 EXCLUDE_UNKNOWN_REGISTRIES)); | 258 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 258 EXPECT_EQ(0U, GetRegistryLengthFromHost("..", | 259 EXPECT_EQ( |
| 259 EXCLUDE_UNKNOWN_REGISTRIES)); | 260 0U, GetRegistryLengthForCanonicalHost("..", EXCLUDE_UNKNOWN_REGISTRIES)); |
| 260 EXPECT_EQ(0U, GetRegistryLengthFromHost("192.168.0.1", | 261 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("192.168.0.1", |
| 261 EXCLUDE_UNKNOWN_REGISTRIES)); | 262 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 262 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost", | 263 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("localhost", |
| 263 EXCLUDE_UNKNOWN_REGISTRIES)); | 264 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 264 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost", | 265 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("localhost", |
| 265 INCLUDE_UNKNOWN_REGISTRIES)); | 266 INCLUDE_UNKNOWN_REGISTRIES)); |
| 266 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost.", | 267 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("localhost.", |
| 267 EXCLUDE_UNKNOWN_REGISTRIES)); | 268 EXCLUDE_UNKNOWN_REGISTRIES)); |
| 268 EXPECT_EQ(0U, GetRegistryLengthFromHost("localhost.", | 269 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHost("localhost.", |
| 269 INCLUDE_UNKNOWN_REGISTRIES)); | 270 INCLUDE_UNKNOWN_REGISTRIES)); |
| 271 | |
| 272 // IDN case. This domain is: | |
| 273 // Unicode: U+4E2D, U+56FD | |
| 274 // UTF8: E4, B8, AD, E5, 9B, BD | |
| 275 // IDN: xn--fiqs8s | |
| 276 EXPECT_EQ(10U, GetRegistryLengthForCanonicalHost("foo.xn--fiqs8s", | |
| 277 EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 278 EXPECT_EQ(10U, BuggyGetHostRegistryLength("foo.xn--fiqs8s", | |
|
brettw
2016/10/19 20:17:43
This has a bug but I'm not uploading the fixed ver
| |
| 279 EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 280 // These illustrate the "buggy" version on non-canonical URLs. They both | |
| 281 // return 10 which is the length of the canonical version, which if the | |
| 282 // calling code starts to use as offsets in the string will lead to | |
| 283 // corruption. | |
| 284 // EXPECT_EQ(18U, BuggyGetHostRegistryLength("foo.%E4%B8%AD%E5%9B%BD", | |
| 285 // EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 286 // EXPECT_EQ(6U, BuggyGetHostRegistryLength("foo.\xE4\xB8\xAD\xE5\x9B\xBD", | |
| 287 // EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 270 } | 288 } |
| 271 | 289 |
| 272 TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) { | 290 TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) { |
| 273 UseDomainData(test2::kDafsa); | 291 UseDomainData(test2::kDafsa); |
| 274 | 292 |
| 275 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", | 293 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", |
| 276 "http://a.b.bar.jp/file.html")); // b.bar.jp | 294 "http://a.b.bar.jp/file.html")); // b.bar.jp |
| 277 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", | 295 EXPECT_TRUE(CompareDomains("http://a.b.bar.jp/file.html", |
| 278 "http://b.b.bar.jp/file.html")); // b.bar.jp | 296 "http://b.b.bar.jp/file.html")); // b.bar.jp |
| 279 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp | 297 EXPECT_FALSE(CompareDomains("http://a.foo.jp/file.html", // foo.jp |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 const char key0[] = | 399 const char key0[] = |
| 382 "a.b.6____________________________________________________" | 400 "a.b.6____________________________________________________" |
| 383 "________________________________________________6"; | 401 "________________________________________________6"; |
| 384 const char key1[] = | 402 const char key1[] = |
| 385 "a.b.7____________________________________________________" | 403 "a.b.7____________________________________________________" |
| 386 "________________________________________________7"; | 404 "________________________________________________7"; |
| 387 const char key2[] = | 405 const char key2[] = |
| 388 "a.b.a____________________________________________________" | 406 "a.b.a____________________________________________________" |
| 389 "________________________________________________8"; | 407 "________________________________________________8"; |
| 390 | 408 |
| 391 EXPECT_EQ(102U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); | 409 EXPECT_EQ(102U, GetRegistryLengthForCanonicalHost( |
| 392 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 410 key0, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 393 EXPECT_EQ(102U, | 411 EXPECT_EQ( |
| 394 GetRegistryLengthFromHostIncludingPrivate( | 412 0U, GetRegistryLengthForCanonicalHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 395 key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 413 EXPECT_EQ(102U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 396 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | 414 key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 415 EXPECT_EQ( | |
| 416 0U, GetRegistryLengthForCanonicalHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 397 } | 417 } |
| 398 | 418 |
| 399 TEST_F(RegistryControlledDomainTest, TestDafsaThreeByteOffsets) { | 419 TEST_F(RegistryControlledDomainTest, TestDafsaThreeByteOffsets) { |
| 400 UseDomainData(test4::kDafsa); | 420 UseDomainData(test4::kDafsa); |
| 401 | 421 |
| 402 // Testing to lookup keys in a DAFSA with three byte offsets. | 422 // Testing to lookup keys in a DAFSA with three byte offsets. |
| 403 // 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 |
| 404 // characters, which makes it impossible to merge labels. The byte array | 424 // characters, which makes it impossible to merge labels. The byte array |
| 405 // has a size of ~54k. A two byte offset can add at most add 8k to the | 425 // has a size of ~54k. A two byte offset can add at most add 8k to the |
| 406 // previous offset. Since we can skip only forward in memory, the nodes | 426 // previous offset. Since we can skip only forward in memory, the nodes |
| 407 // representing the return values must be located near the end of the byte | 427 // representing the return values must be located near the end of the byte |
| 408 // array. The probability that we can reach from an arbitrary inner node to | 428 // array. The probability that we can reach from an arbitrary inner node to |
| 409 // a return value without using a three byte offset is small (but not zero). | 429 // a return value without using a three byte offset is small (but not zero). |
| 410 // The test is repeated with some different keys and with a reasonable | 430 // The test is repeated with some different keys and with a reasonable |
| 411 // probability at least one of the tested paths has go over a three byte | 431 // probability at least one of the tested paths has go over a three byte |
| 412 // offset. | 432 // offset. |
| 413 | 433 |
| 414 const char key0[] = | 434 const char key0[] = |
| 415 "a.b.Z6___________________________________________________" | 435 "a.b.Z6___________________________________________________" |
| 416 "_________________________________________________Z6"; | 436 "_________________________________________________Z6"; |
| 417 const char key1[] = | 437 const char key1[] = |
| 418 "a.b.Z7___________________________________________________" | 438 "a.b.Z7___________________________________________________" |
| 419 "_________________________________________________Z7"; | 439 "_________________________________________________Z7"; |
| 420 const char key2[] = | 440 const char key2[] = |
| 421 "a.b.Za___________________________________________________" | 441 "a.b.Za___________________________________________________" |
| 422 "_________________________________________________Z8"; | 442 "_________________________________________________Z8"; |
| 423 | 443 |
| 424 EXPECT_EQ(104U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); | 444 EXPECT_EQ(104U, GetRegistryLengthForCanonicalHost( |
| 425 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 445 key0, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 426 EXPECT_EQ(104U, | 446 EXPECT_EQ( |
| 427 GetRegistryLengthFromHostIncludingPrivate( | 447 0U, GetRegistryLengthForCanonicalHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 428 key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 448 EXPECT_EQ(104U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 429 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | 449 key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 450 EXPECT_EQ( | |
| 451 0U, GetRegistryLengthForCanonicalHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 430 } | 452 } |
| 431 | 453 |
| 432 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedPrefixes) { | 454 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedPrefixes) { |
| 433 UseDomainData(test5::kDafsa); | 455 UseDomainData(test5::kDafsa); |
| 434 | 456 |
| 435 // Testing to lookup keys in a DAFSA with compressed prefixes. | 457 // Testing to lookup keys in a DAFSA with compressed prefixes. |
| 436 // This DAFSA is constructed from words with similar prefixes but distinct | 458 // This DAFSA is constructed from words with similar prefixes but distinct |
| 437 // suffixes. The DAFSA will then form a trie with the implicit source node | 459 // suffixes. The DAFSA will then form a trie with the implicit source node |
| 438 // as root. | 460 // as root. |
| 439 | 461 |
| 440 const char key0[] = "a.b.ai"; | 462 const char key0[] = "a.b.ai"; |
| 441 const char key1[] = "a.b.bj"; | 463 const char key1[] = "a.b.bj"; |
| 442 const char key2[] = "a.b.aak"; | 464 const char key2[] = "a.b.aak"; |
| 443 const char key3[] = "a.b.bbl"; | 465 const char key3[] = "a.b.bbl"; |
| 444 const char key4[] = "a.b.aaa"; | 466 const char key4[] = "a.b.aaa"; |
| 445 const char key5[] = "a.b.bbb"; | 467 const char key5[] = "a.b.bbb"; |
| 446 const char key6[] = "a.b.aaaam"; | 468 const char key6[] = "a.b.aaaam"; |
| 447 const char key7[] = "a.b.bbbbn"; | 469 const char key7[] = "a.b.bbbbn"; |
| 448 | 470 |
| 449 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); | 471 EXPECT_EQ( |
| 450 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 472 2U, GetRegistryLengthForCanonicalHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 451 EXPECT_EQ(2U, | 473 EXPECT_EQ( |
| 452 GetRegistryLengthFromHostIncludingPrivate( | 474 0U, GetRegistryLengthForCanonicalHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 453 key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 475 EXPECT_EQ(2U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 454 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | 476 key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 455 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); | 477 EXPECT_EQ( |
| 456 EXPECT_EQ(3U, | 478 3U, GetRegistryLengthForCanonicalHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 457 GetRegistryLengthFromHostIncludingPrivate( | 479 EXPECT_EQ( |
| 458 key3, EXCLUDE_UNKNOWN_REGISTRIES)); | 480 0U, GetRegistryLengthForCanonicalHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 459 EXPECT_EQ(0U, | 481 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 460 GetRegistryLengthFromHostIncludingPrivate( | 482 key3, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 461 key4, EXCLUDE_UNKNOWN_REGISTRIES)); | 483 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 462 EXPECT_EQ(0U, | 484 key4, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 463 GetRegistryLengthFromHostIncludingPrivate( | 485 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 464 key5, EXCLUDE_UNKNOWN_REGISTRIES)); | 486 key5, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 465 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); | 487 EXPECT_EQ( |
| 466 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); | 488 5U, GetRegistryLengthForCanonicalHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 489 EXPECT_EQ( | |
| 490 5U, GetRegistryLengthForCanonicalHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 467 } | 491 } |
| 468 | 492 |
| 469 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedSuffixes) { | 493 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedSuffixes) { |
| 470 UseDomainData(test6::kDafsa); | 494 UseDomainData(test6::kDafsa); |
| 471 | 495 |
| 472 // Testing to lookup keys in a DAFSA with compressed suffixes. | 496 // Testing to lookup keys in a DAFSA with compressed suffixes. |
| 473 // This DAFSA is constructed from words with similar suffixes but distinct | 497 // This DAFSA is constructed from words with similar suffixes but distinct |
| 474 // prefixes. The DAFSA will then form a trie with the implicit sink node as | 498 // prefixes. The DAFSA will then form a trie with the implicit sink node as |
| 475 // root. | 499 // root. |
| 476 | 500 |
| 477 const char key0[] = "a.b.ia"; | 501 const char key0[] = "a.b.ia"; |
| 478 const char key1[] = "a.b.jb"; | 502 const char key1[] = "a.b.jb"; |
| 479 const char key2[] = "a.b.kaa"; | 503 const char key2[] = "a.b.kaa"; |
| 480 const char key3[] = "a.b.lbb"; | 504 const char key3[] = "a.b.lbb"; |
| 481 const char key4[] = "a.b.aaa"; | 505 const char key4[] = "a.b.aaa"; |
| 482 const char key5[] = "a.b.bbb"; | 506 const char key5[] = "a.b.bbb"; |
| 483 const char key6[] = "a.b.maaaa"; | 507 const char key6[] = "a.b.maaaa"; |
| 484 const char key7[] = "a.b.nbbbb"; | 508 const char key7[] = "a.b.nbbbb"; |
| 485 | 509 |
| 486 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); | 510 EXPECT_EQ( |
| 487 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 511 2U, GetRegistryLengthForCanonicalHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 488 EXPECT_EQ(2U, | 512 EXPECT_EQ( |
| 489 GetRegistryLengthFromHostIncludingPrivate( | 513 0U, GetRegistryLengthForCanonicalHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 490 key1, EXCLUDE_UNKNOWN_REGISTRIES)); | 514 EXPECT_EQ(2U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 491 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); | 515 key1, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 492 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); | 516 EXPECT_EQ( |
| 493 EXPECT_EQ(3U, | 517 3U, GetRegistryLengthForCanonicalHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 494 GetRegistryLengthFromHostIncludingPrivate( | 518 EXPECT_EQ( |
| 495 key3, EXCLUDE_UNKNOWN_REGISTRIES)); | 519 0U, GetRegistryLengthForCanonicalHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 496 EXPECT_EQ(0U, | 520 EXPECT_EQ(3U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 497 GetRegistryLengthFromHostIncludingPrivate( | 521 key3, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 498 key4, EXCLUDE_UNKNOWN_REGISTRIES)); | 522 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 499 EXPECT_EQ(0U, | 523 key4, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 500 GetRegistryLengthFromHostIncludingPrivate( | 524 EXPECT_EQ(0U, GetRegistryLengthForCanonicalHostIncludingPrivate( |
| 501 key5, EXCLUDE_UNKNOWN_REGISTRIES)); | 525 key5, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 502 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); | 526 EXPECT_EQ( |
| 503 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); | 527 5U, GetRegistryLengthForCanonicalHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); |
| 528 EXPECT_EQ( | |
| 529 5U, GetRegistryLengthForCanonicalHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); | |
| 504 } | 530 } |
| 505 } // namespace registry_controlled_domains | 531 } // namespace registry_controlled_domains |
| 506 } // namespace net | 532 } // namespace net |
| OLD | NEW |