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

Side by Side Diff: net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 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 | « net/base/network_change_notifier.cc ('k') | net/cert/nss_cert_database_chromeos.h » ('j') | 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 "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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 365
366 TEST_F(RegistryControlledDomainTest, TestDafsaTwoByteOffsets) { 366 TEST_F(RegistryControlledDomainTest, TestDafsaTwoByteOffsets) {
367 UseDomainData(test3::kDafsa); 367 UseDomainData(test3::kDafsa);
368 368
369 // Testing to lookup keys in a DAFSA with two byte offsets. 369 // Testing to lookup keys in a DAFSA with two byte offsets.
370 // This DAFSA is constructed so that labels begin and end with unique 370 // This DAFSA is constructed so that labels begin and end with unique
371 // characters, which makes it impossible to merge labels. Each inner node 371 // 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 372 // 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. 373 // previous offset. Thus the paths must go over two byte offsets.
374 374
375 const char* key0 = 375 const char key0[] =
376 "a.b.6____________________________________________________" 376 "a.b.6____________________________________________________"
377 "________________________________________________6"; 377 "________________________________________________6";
378 const char* key1 = 378 const char key1[] =
379 "a.b.7____________________________________________________" 379 "a.b.7____________________________________________________"
380 "________________________________________________7"; 380 "________________________________________________7";
381 const char* key2 = 381 const char key2[] =
382 "a.b.a____________________________________________________" 382 "a.b.a____________________________________________________"
383 "________________________________________________8"; 383 "________________________________________________8";
384 384
385 EXPECT_EQ(102U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); 385 EXPECT_EQ(102U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES));
386 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); 386 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES));
387 EXPECT_EQ(102U, 387 EXPECT_EQ(102U,
388 GetRegistryLengthFromHostIncludingPrivate( 388 GetRegistryLengthFromHostIncludingPrivate(
389 key1, EXCLUDE_UNKNOWN_REGISTRIES)); 389 key1, EXCLUDE_UNKNOWN_REGISTRIES));
390 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); 390 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES));
391 } 391 }
392 392
393 TEST_F(RegistryControlledDomainTest, TestDafsaThreeByteOffsets) { 393 TEST_F(RegistryControlledDomainTest, TestDafsaThreeByteOffsets) {
394 UseDomainData(test4::kDafsa); 394 UseDomainData(test4::kDafsa);
395 395
396 // Testing to lookup keys in a DAFSA with three byte offsets. 396 // Testing to lookup keys in a DAFSA with three byte offsets.
397 // This DAFSA is constructed so that labels begin and end with unique 397 // This DAFSA is constructed so that labels begin and end with unique
398 // characters, which makes it impossible to merge labels. The byte array 398 // characters, which makes it impossible to merge labels. The byte array
399 // has a size of ~54k. A two byte offset can add at most add 8k to the 399 // has a size of ~54k. A two byte offset can add at most add 8k to the
400 // previous offset. Since we can skip only forward in memory, the nodes 400 // previous offset. Since we can skip only forward in memory, the nodes
401 // representing the return values must be located near the end of the byte 401 // representing the return values must be located near the end of the byte
402 // array. The probability that we can reach from an arbitrary inner node to 402 // array. The probability that we can reach from an arbitrary inner node to
403 // a return value without using a three byte offset is small (but not zero). 403 // a return value without using a three byte offset is small (but not zero).
404 // The test is repeated with some different keys and with a reasonable 404 // The test is repeated with some different keys and with a reasonable
405 // probability at least one of the tested paths has go over a three byte 405 // probability at least one of the tested paths has go over a three byte
406 // offset. 406 // offset.
407 407
408 const char* key0 = 408 const char key0[] =
409 "a.b.Z6___________________________________________________" 409 "a.b.Z6___________________________________________________"
410 "_________________________________________________Z6"; 410 "_________________________________________________Z6";
411 const char* key1 = 411 const char key1[] =
412 "a.b.Z7___________________________________________________" 412 "a.b.Z7___________________________________________________"
413 "_________________________________________________Z7"; 413 "_________________________________________________Z7";
414 const char* key2 = 414 const char key2[] =
415 "a.b.Za___________________________________________________" 415 "a.b.Za___________________________________________________"
416 "_________________________________________________Z8"; 416 "_________________________________________________Z8";
417 417
418 EXPECT_EQ(104U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); 418 EXPECT_EQ(104U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES));
419 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); 419 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES));
420 EXPECT_EQ(104U, 420 EXPECT_EQ(104U,
421 GetRegistryLengthFromHostIncludingPrivate( 421 GetRegistryLengthFromHostIncludingPrivate(
422 key1, EXCLUDE_UNKNOWN_REGISTRIES)); 422 key1, EXCLUDE_UNKNOWN_REGISTRIES));
423 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); 423 EXPECT_EQ(0U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES));
424 } 424 }
425 425
426 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedPrefixes) { 426 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedPrefixes) {
427 UseDomainData(test5::kDafsa); 427 UseDomainData(test5::kDafsa);
428 428
429 // Testing to lookup keys in a DAFSA with compressed prefixes. 429 // Testing to lookup keys in a DAFSA with compressed prefixes.
430 // This DAFSA is constructed from words with similar prefixes but distinct 430 // This DAFSA is constructed from words with similar prefixes but distinct
431 // suffixes. The DAFSA will then form a trie with the implicit source node 431 // suffixes. The DAFSA will then form a trie with the implicit source node
432 // as root. 432 // as root.
433 433
434 const char* key0 = "a.b.ai"; 434 const char key0[] = "a.b.ai";
435 const char* key1 = "a.b.bj"; 435 const char key1[] = "a.b.bj";
436 const char* key2 = "a.b.aak"; 436 const char key2[] = "a.b.aak";
437 const char* key3 = "a.b.bbl"; 437 const char key3[] = "a.b.bbl";
438 const char* key4 = "a.b.aaa"; 438 const char key4[] = "a.b.aaa";
439 const char* key5 = "a.b.bbb"; 439 const char key5[] = "a.b.bbb";
440 const char* key6 = "a.b.aaaam"; 440 const char key6[] = "a.b.aaaam";
441 const char* key7 = "a.b.bbbbn"; 441 const char key7[] = "a.b.bbbbn";
442 442
443 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); 443 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES));
444 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); 444 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES));
445 EXPECT_EQ(2U, 445 EXPECT_EQ(2U,
446 GetRegistryLengthFromHostIncludingPrivate( 446 GetRegistryLengthFromHostIncludingPrivate(
447 key1, EXCLUDE_UNKNOWN_REGISTRIES)); 447 key1, EXCLUDE_UNKNOWN_REGISTRIES));
448 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); 448 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES));
449 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); 449 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES));
450 EXPECT_EQ(3U, 450 EXPECT_EQ(3U,
451 GetRegistryLengthFromHostIncludingPrivate( 451 GetRegistryLengthFromHostIncludingPrivate(
452 key3, EXCLUDE_UNKNOWN_REGISTRIES)); 452 key3, EXCLUDE_UNKNOWN_REGISTRIES));
453 EXPECT_EQ(0U, 453 EXPECT_EQ(0U,
454 GetRegistryLengthFromHostIncludingPrivate( 454 GetRegistryLengthFromHostIncludingPrivate(
455 key4, EXCLUDE_UNKNOWN_REGISTRIES)); 455 key4, EXCLUDE_UNKNOWN_REGISTRIES));
456 EXPECT_EQ(0U, 456 EXPECT_EQ(0U,
457 GetRegistryLengthFromHostIncludingPrivate( 457 GetRegistryLengthFromHostIncludingPrivate(
458 key5, EXCLUDE_UNKNOWN_REGISTRIES)); 458 key5, EXCLUDE_UNKNOWN_REGISTRIES));
459 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); 459 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES));
460 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); 460 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES));
461 } 461 }
462 462
463 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedSuffixes) { 463 TEST_F(RegistryControlledDomainTest, TestDafsaJoinedSuffixes) {
464 UseDomainData(test6::kDafsa); 464 UseDomainData(test6::kDafsa);
465 465
466 // Testing to lookup keys in a DAFSA with compressed suffixes. 466 // Testing to lookup keys in a DAFSA with compressed suffixes.
467 // This DAFSA is constructed from words with similar suffixes but distinct 467 // This DAFSA is constructed from words with similar suffixes but distinct
468 // prefixes. The DAFSA will then form a trie with the implicit sink node as 468 // prefixes. The DAFSA will then form a trie with the implicit sink node as
469 // root. 469 // root.
470 470
471 const char* key0 = "a.b.ia"; 471 const char key0[] = "a.b.ia";
472 const char* key1 = "a.b.jb"; 472 const char key1[] = "a.b.jb";
473 const char* key2 = "a.b.kaa"; 473 const char key2[] = "a.b.kaa";
474 const char* key3 = "a.b.lbb"; 474 const char key3[] = "a.b.lbb";
475 const char* key4 = "a.b.aaa"; 475 const char key4[] = "a.b.aaa";
476 const char* key5 = "a.b.bbb"; 476 const char key5[] = "a.b.bbb";
477 const char* key6 = "a.b.maaaa"; 477 const char key6[] = "a.b.maaaa";
478 const char* key7 = "a.b.nbbbb"; 478 const char key7[] = "a.b.nbbbb";
479 479
480 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES)); 480 EXPECT_EQ(2U, GetRegistryLengthFromHost(key0, EXCLUDE_UNKNOWN_REGISTRIES));
481 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES)); 481 EXPECT_EQ(0U, GetRegistryLengthFromHost(key1, EXCLUDE_UNKNOWN_REGISTRIES));
482 EXPECT_EQ(2U, 482 EXPECT_EQ(2U,
483 GetRegistryLengthFromHostIncludingPrivate( 483 GetRegistryLengthFromHostIncludingPrivate(
484 key1, EXCLUDE_UNKNOWN_REGISTRIES)); 484 key1, EXCLUDE_UNKNOWN_REGISTRIES));
485 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES)); 485 EXPECT_EQ(3U, GetRegistryLengthFromHost(key2, EXCLUDE_UNKNOWN_REGISTRIES));
486 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES)); 486 EXPECT_EQ(0U, GetRegistryLengthFromHost(key3, EXCLUDE_UNKNOWN_REGISTRIES));
487 EXPECT_EQ(3U, 487 EXPECT_EQ(3U,
488 GetRegistryLengthFromHostIncludingPrivate( 488 GetRegistryLengthFromHostIncludingPrivate(
489 key3, EXCLUDE_UNKNOWN_REGISTRIES)); 489 key3, EXCLUDE_UNKNOWN_REGISTRIES));
490 EXPECT_EQ(0U, 490 EXPECT_EQ(0U,
491 GetRegistryLengthFromHostIncludingPrivate( 491 GetRegistryLengthFromHostIncludingPrivate(
492 key4, EXCLUDE_UNKNOWN_REGISTRIES)); 492 key4, EXCLUDE_UNKNOWN_REGISTRIES));
493 EXPECT_EQ(0U, 493 EXPECT_EQ(0U,
494 GetRegistryLengthFromHostIncludingPrivate( 494 GetRegistryLengthFromHostIncludingPrivate(
495 key5, EXCLUDE_UNKNOWN_REGISTRIES)); 495 key5, EXCLUDE_UNKNOWN_REGISTRIES));
496 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); 496 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES));
497 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); 497 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES));
498 } 498 }
499 } // namespace registry_controlled_domains 499 } // namespace registry_controlled_domains
500 } // namespace net 500 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_change_notifier.cc ('k') | net/cert/nss_cert_database_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698