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

Side by Side Diff: net/filter/sdch_filter_unittest.cc

Issue 495523003: Change SDCHDictionaryFetcher to use URLRequest instead of URLFetcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed try job failures. Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/base/sdch_manager_unittest.cc ('k') | net/net.gypi » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <limits.h> 5 #include <limits.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 sizeof(kSdchCompressedTestData) - 1), 56 sizeof(kSdchCompressedTestData) - 1),
57 expanded_(kTestData, sizeof(kTestData) - 1), 57 expanded_(kTestData, sizeof(kTestData) - 1),
58 sdch_manager_(new SdchManager), 58 sdch_manager_(new SdchManager),
59 filter_context_(new MockFilterContext) { 59 filter_context_(new MockFilterContext) {
60 URLRequestContext* url_request_context = 60 URLRequestContext* url_request_context =
61 filter_context_->GetModifiableURLRequestContext(); 61 filter_context_->GetModifiableURLRequestContext();
62 62
63 url_request_context->set_sdch_manager(sdch_manager_.get()); 63 url_request_context->set_sdch_manager(sdch_manager_.get());
64 } 64 }
65 65
66 // Attempt to add a dictionary to the manager; returns whether or not
67 // the attempt succeeded.
68 bool AddSdchDictionary(const std::string& dictionary_text,
69 const GURL& gurl) {
70 std::string list;
71 sdch_manager_->GetAvailDictionaryList(gurl, &list);
72 sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
73 std::string list2;
74 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
75
76 // The list of hashes should change iff the addition succeeds.
77 return (list != list2);
78 }
79
66 MockFilterContext* filter_context() { return filter_context_.get(); } 80 MockFilterContext* filter_context() { return filter_context_.get(); }
67 81
68 std::string NewSdchCompressedData(const std::string dictionary); 82 std::string NewSdchCompressedData(const std::string dictionary) {
83 std::string client_hash;
84 std::string server_hash;
85 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
86
87 // Build compressed data that refers to our dictionary.
88 std::string compressed(server_hash);
89 compressed.append("\0", 1);
90 compressed.append(vcdiff_compressed_data_);
91 return compressed;
92 }
69 93
70 const std::string test_vcdiff_dictionary_; 94 const std::string test_vcdiff_dictionary_;
71 const std::string vcdiff_compressed_data_; 95 const std::string vcdiff_compressed_data_;
72 const std::string expanded_; // Desired final, decompressed data. 96 const std::string expanded_; // Desired final, decompressed data.
73 97
74 scoped_ptr<SdchManager> sdch_manager_; 98 scoped_ptr<SdchManager> sdch_manager_;
75 scoped_ptr<MockFilterContext> filter_context_; 99 scoped_ptr<MockFilterContext> filter_context_;
76 }; 100 };
77 101
78 std::string SdchFilterTest::NewSdchCompressedData(
79 const std::string dictionary) {
80 std::string client_hash;
81 std::string server_hash;
82 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
83
84 // Build compressed data that refers to our dictionary.
85 std::string compressed(server_hash);
86 compressed.append("\0", 1);
87 compressed.append(vcdiff_compressed_data_);
88 return compressed;
89 }
90
91 //------------------------------------------------------------------------------ 102 //------------------------------------------------------------------------------
92 103
93 104
94 TEST_F(SdchFilterTest, Hashing) { 105 TEST_F(SdchFilterTest, Hashing) {
95 std::string client_hash, server_hash; 106 std::string client_hash, server_hash;
96 std::string dictionary("test contents"); 107 std::string dictionary("test contents");
97 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); 108 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
98 109
99 EXPECT_EQ(client_hash, "lMQBjS3P"); 110 EXPECT_EQ(client_hash, "lMQBjS3P");
100 EXPECT_EQ(server_hash, "MyciMVll"); 111 EXPECT_EQ(server_hash, "MyciMVll");
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 417 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
407 } 418 }
408 419
409 TEST_F(SdchFilterTest, DictionaryAddOnce) { 420 TEST_F(SdchFilterTest, DictionaryAddOnce) {
410 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 421 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
411 const std::string kSampleDomain = "sdchtest.com"; 422 const std::string kSampleDomain = "sdchtest.com";
412 std::string dictionary(NewSdchDictionary(kSampleDomain)); 423 std::string dictionary(NewSdchDictionary(kSampleDomain));
413 424
414 std::string url_string = "http://" + kSampleDomain; 425 std::string url_string = "http://" + kSampleDomain;
415 GURL url(url_string); 426 GURL url(url_string);
416 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 427 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
417 428
418 // Check we can't add it twice. 429 // Check we can't add it twice.
419 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url)); 430 EXPECT_FALSE(AddSdchDictionary(dictionary, url));
420 431
421 const std::string kSampleDomain2 = "sdchtest2.com"; 432 const std::string kSampleDomain2 = "sdchtest2.com";
422 433
423 // Don't test adding a second dictionary if our limits are tight. 434 // Don't test adding a second dictionary if our limits are tight.
424 if (SdchManager::kMaxDictionaryCount > 1) { 435 if (SdchManager::kMaxDictionaryCount > 1) {
425 // Construct a second SDCH dictionary from a VCDIFF dictionary. 436 // Construct a second SDCH dictionary from a VCDIFF dictionary.
426 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); 437 std::string dictionary2(NewSdchDictionary(kSampleDomain2));
427 438
428 std::string url_string2 = "http://" + kSampleDomain2; 439 std::string url_string2 = "http://" + kSampleDomain2;
429 GURL url2(url_string2); 440 GURL url2(url_string2);
430 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2)); 441 EXPECT_TRUE(AddSdchDictionary(dictionary2, url2));
431 } 442 }
432 } 443 }
433 444
434 TEST_F(SdchFilterTest, BasicDictionary) { 445 TEST_F(SdchFilterTest, BasicDictionary) {
435 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 446 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
436 const std::string kSampleDomain = "sdchtest.com"; 447 const std::string kSampleDomain = "sdchtest.com";
437 std::string dictionary(NewSdchDictionary(kSampleDomain)); 448 std::string dictionary(NewSdchDictionary(kSampleDomain));
438 449
439 std::string url_string = "http://" + kSampleDomain; 450 std::string url_string = "http://" + kSampleDomain;
440 451
441 GURL url(url_string); 452 GURL url(url_string);
442 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 453 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
443 454
444 std::string compressed(NewSdchCompressedData(dictionary)); 455 std::string compressed(NewSdchCompressedData(dictionary));
445 456
446 std::vector<Filter::FilterType> filter_types; 457 std::vector<Filter::FilterType> filter_types;
447 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 458 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
448 459
449 filter_context()->SetURL(url); 460 filter_context()->SetURL(url);
450 461
451 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 462 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
452 463
(...skipping 16 matching lines...) Expand all
469 } 480 }
470 481
471 TEST_F(SdchFilterTest, NoDecodeHttps) { 482 TEST_F(SdchFilterTest, NoDecodeHttps) {
472 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 483 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
473 const std::string kSampleDomain = "sdchtest.com"; 484 const std::string kSampleDomain = "sdchtest.com";
474 std::string dictionary(NewSdchDictionary(kSampleDomain)); 485 std::string dictionary(NewSdchDictionary(kSampleDomain));
475 486
476 std::string url_string = "http://" + kSampleDomain; 487 std::string url_string = "http://" + kSampleDomain;
477 488
478 GURL url(url_string); 489 GURL url(url_string);
479 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 490 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
480 491
481 std::string compressed(NewSdchCompressedData(dictionary)); 492 std::string compressed(NewSdchCompressedData(dictionary));
482 493
483 std::vector<Filter::FilterType> filter_types; 494 std::vector<Filter::FilterType> filter_types;
484 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 495 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
485 496
486 filter_context()->SetURL(GURL("https://" + kSampleDomain)); 497 filter_context()->SetURL(GURL("https://" + kSampleDomain));
487 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 498 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
488 499
489 const size_t feed_block_size(100); 500 const size_t feed_block_size(100);
490 const size_t output_block_size(100); 501 const size_t output_block_size(100);
491 std::string output; 502 std::string output;
492 503
493 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 504 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
494 filter.get(), &output)); 505 filter.get(), &output));
495 } 506 }
496 507
497 // Current failsafe TODO/hack refuses to decode any content that doesn't use 508 // Current failsafe TODO/hack refuses to decode any content that doesn't use
498 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). 509 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP).
499 // The following tests this blockage. Note that blacklisting results, so we 510 // The following tests this blockage. Note that blacklisting results, so we
500 // we need separate tests for each of these. 511 // we need separate tests for each of these.
501 TEST_F(SdchFilterTest, NoDecodeFtp) { 512 TEST_F(SdchFilterTest, NoDecodeFtp) {
502 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 513 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
503 const std::string kSampleDomain = "sdchtest.com"; 514 const std::string kSampleDomain = "sdchtest.com";
504 std::string dictionary(NewSdchDictionary(kSampleDomain)); 515 std::string dictionary(NewSdchDictionary(kSampleDomain));
505 516
506 std::string url_string = "http://" + kSampleDomain; 517 std::string url_string = "http://" + kSampleDomain;
507 518
508 GURL url(url_string); 519 GURL url(url_string);
509 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 520 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
510 521
511 std::string compressed(NewSdchCompressedData(dictionary)); 522 std::string compressed(NewSdchCompressedData(dictionary));
512 523
513 std::vector<Filter::FilterType> filter_types; 524 std::vector<Filter::FilterType> filter_types;
514 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 525 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
515 526
516 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); 527 filter_context()->SetURL(GURL("ftp://" + kSampleDomain));
517 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 528 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
518 529
519 const size_t feed_block_size(100); 530 const size_t feed_block_size(100);
520 const size_t output_block_size(100); 531 const size_t output_block_size(100);
521 std::string output; 532 std::string output;
522 533
523 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 534 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
524 filter.get(), &output)); 535 filter.get(), &output));
525 } 536 }
526 537
527 TEST_F(SdchFilterTest, NoDecodeFileColon) { 538 TEST_F(SdchFilterTest, NoDecodeFileColon) {
528 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 539 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
529 const std::string kSampleDomain = "sdchtest.com"; 540 const std::string kSampleDomain = "sdchtest.com";
530 std::string dictionary(NewSdchDictionary(kSampleDomain)); 541 std::string dictionary(NewSdchDictionary(kSampleDomain));
531 542
532 std::string url_string = "http://" + kSampleDomain; 543 std::string url_string = "http://" + kSampleDomain;
533 544
534 GURL url(url_string); 545 GURL url(url_string);
535 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 546 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
536 547
537 std::string compressed(NewSdchCompressedData(dictionary)); 548 std::string compressed(NewSdchCompressedData(dictionary));
538 549
539 std::vector<Filter::FilterType> filter_types; 550 std::vector<Filter::FilterType> filter_types;
540 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 551 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
541 552
542 filter_context()->SetURL(GURL("file://" + kSampleDomain)); 553 filter_context()->SetURL(GURL("file://" + kSampleDomain));
543 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 554 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
544 555
545 const size_t feed_block_size(100); 556 const size_t feed_block_size(100);
546 const size_t output_block_size(100); 557 const size_t output_block_size(100);
547 std::string output; 558 std::string output;
548 559
549 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 560 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
550 filter.get(), &output)); 561 filter.get(), &output));
551 } 562 }
552 563
553 TEST_F(SdchFilterTest, NoDecodeAboutColon) { 564 TEST_F(SdchFilterTest, NoDecodeAboutColon) {
554 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 565 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
555 const std::string kSampleDomain = "sdchtest.com"; 566 const std::string kSampleDomain = "sdchtest.com";
556 std::string dictionary(NewSdchDictionary(kSampleDomain)); 567 std::string dictionary(NewSdchDictionary(kSampleDomain));
557 568
558 std::string url_string = "http://" + kSampleDomain; 569 std::string url_string = "http://" + kSampleDomain;
559 570
560 GURL url(url_string); 571 GURL url(url_string);
561 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 572 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
562 573
563 std::string compressed(NewSdchCompressedData(dictionary)); 574 std::string compressed(NewSdchCompressedData(dictionary));
564 575
565 std::vector<Filter::FilterType> filter_types; 576 std::vector<Filter::FilterType> filter_types;
566 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 577 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
567 578
568 filter_context()->SetURL(GURL("about://" + kSampleDomain)); 579 filter_context()->SetURL(GURL("about://" + kSampleDomain));
569 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 580 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
570 581
571 const size_t feed_block_size(100); 582 const size_t feed_block_size(100);
572 const size_t output_block_size(100); 583 const size_t output_block_size(100);
573 std::string output; 584 std::string output;
574 585
575 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 586 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
576 filter.get(), &output)); 587 filter.get(), &output));
577 } 588 }
578 589
579 TEST_F(SdchFilterTest, NoDecodeJavaScript) { 590 TEST_F(SdchFilterTest, NoDecodeJavaScript) {
580 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 591 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
581 const std::string kSampleDomain = "sdchtest.com"; 592 const std::string kSampleDomain = "sdchtest.com";
582 std::string dictionary(NewSdchDictionary(kSampleDomain)); 593 std::string dictionary(NewSdchDictionary(kSampleDomain));
583 594
584 std::string url_string = "http://" + kSampleDomain; 595 std::string url_string = "http://" + kSampleDomain;
585 596
586 GURL url(url_string); 597 GURL url(url_string);
587 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 598 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
588 599
589 std::string compressed(NewSdchCompressedData(dictionary)); 600 std::string compressed(NewSdchCompressedData(dictionary));
590 601
591 std::vector<Filter::FilterType> filter_types; 602 std::vector<Filter::FilterType> filter_types;
592 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 603 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
593 604
594 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); 605 filter_context()->SetURL(GURL("javascript://" + kSampleDomain));
595 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 606 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
596 607
597 const size_t feed_block_size(100); 608 const size_t feed_block_size(100);
598 const size_t output_block_size(100); 609 const size_t output_block_size(100);
599 std::string output; 610 std::string output;
600 611
601 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 612 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
602 filter.get(), &output)); 613 filter.get(), &output));
603 } 614 }
604 615
605 TEST_F(SdchFilterTest, CanStillDecodeHttp) { 616 TEST_F(SdchFilterTest, CanStillDecodeHttp) {
606 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 617 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
607 const std::string kSampleDomain = "sdchtest.com"; 618 const std::string kSampleDomain = "sdchtest.com";
608 std::string dictionary(NewSdchDictionary(kSampleDomain)); 619 std::string dictionary(NewSdchDictionary(kSampleDomain));
609 620
610 std::string url_string = "http://" + kSampleDomain; 621 std::string url_string = "http://" + kSampleDomain;
611 622
612 GURL url(url_string); 623 GURL url(url_string);
613 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 624 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
614 625
615 std::string compressed(NewSdchCompressedData(dictionary)); 626 std::string compressed(NewSdchCompressedData(dictionary));
616 627
617 std::vector<Filter::FilterType> filter_types; 628 std::vector<Filter::FilterType> filter_types;
618 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 629 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
619 630
620 filter_context()->SetURL(GURL("http://" + kSampleDomain)); 631 filter_context()->SetURL(GURL("http://" + kSampleDomain));
621 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 632 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
622 633
623 const size_t feed_block_size(100); 634 const size_t feed_block_size(100);
624 const size_t output_block_size(100); 635 const size_t output_block_size(100);
625 std::string output; 636 std::string output;
626 637
627 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 638 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
628 filter.get(), &output)); 639 filter.get(), &output));
629 } 640 }
630 641
631 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { 642 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
632 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 643 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
633 const std::string kSampleDomain = "sdchtest.com"; 644 const std::string kSampleDomain = "sdchtest.com";
634 std::string dictionary(NewSdchDictionary(kSampleDomain)); 645 std::string dictionary(NewSdchDictionary(kSampleDomain));
635 646
636 std::string url_string = "http://" + kSampleDomain; 647 std::string url_string = "http://" + kSampleDomain;
637 648
638 GURL url(url_string); 649 GURL url(url_string);
639 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 650 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
640 651
641 std::string compressed(NewSdchCompressedData(dictionary)); 652 std::string compressed(NewSdchCompressedData(dictionary));
642 653
643 std::vector<Filter::FilterType> filter_types; 654 std::vector<Filter::FilterType> filter_types;
644 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 655 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
645 656
646 // Decode with content arriving from the "wrong" domain. 657 // Decode with content arriving from the "wrong" domain.
647 // This tests SdchManager::CanSet(). 658 // This tests SdchManager::CanSet().
648 GURL wrong_domain_url("http://www.wrongdomain.com"); 659 GURL wrong_domain_url("http://www.wrongdomain.com");
649 filter_context()->SetURL(wrong_domain_url); 660 filter_context()->SetURL(wrong_domain_url);
(...skipping 18 matching lines...) Expand all
668 if (SdchManager::kMaxDictionaryCount <= 1) 679 if (SdchManager::kMaxDictionaryCount <= 1)
669 return; 680 return;
670 681
671 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 682 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
672 const std::string kSampleDomain = "sdchtest.com"; 683 const std::string kSampleDomain = "sdchtest.com";
673 std::string dictionary(NewSdchDictionary(kSampleDomain)); 684 std::string dictionary(NewSdchDictionary(kSampleDomain));
674 685
675 std::string url_string = "http://" + kSampleDomain; 686 std::string url_string = "http://" + kSampleDomain;
676 687
677 GURL url(url_string); 688 GURL url(url_string);
678 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 689 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
679 690
680 // Create a dictionary with a path restriction, by prefixing dictionary. 691 // Create a dictionary with a path restriction, by prefixing dictionary.
681 const std::string path("/special_path/bin"); 692 const std::string path("/special_path/bin");
682 std::string dictionary_with_path("Path: " + path + "\n"); 693 std::string dictionary_with_path("Path: " + path + "\n");
683 dictionary_with_path.append(dictionary); 694 dictionary_with_path.append(dictionary);
684 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); 695 GURL url2(url_string + path);
696 EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2));
685 697
686 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); 698 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path));
687 699
688 std::vector<Filter::FilterType> filter_types; 700 std::vector<Filter::FilterType> filter_types;
689 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 701 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
690 702
691 // Test decode the path data, arriving from a valid path. 703 // Test decode the path data, arriving from a valid path.
692 filter_context()->SetURL(GURL(url_string + path)); 704 filter_context()->SetURL(GURL(url_string + path));
693 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 705 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
694 706
(...skipping 27 matching lines...) Expand all
722 if (SdchManager::kMaxDictionaryCount <= 1) 734 if (SdchManager::kMaxDictionaryCount <= 1)
723 return; 735 return;
724 736
725 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 737 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
726 const std::string kSampleDomain = "sdchtest.com"; 738 const std::string kSampleDomain = "sdchtest.com";
727 std::string dictionary(NewSdchDictionary(kSampleDomain)); 739 std::string dictionary(NewSdchDictionary(kSampleDomain));
728 740
729 std::string url_string = "http://" + kSampleDomain; 741 std::string url_string = "http://" + kSampleDomain;
730 742
731 GURL url(url_string); 743 GURL url(url_string);
732 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 744 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
733
734 745
735 // Create a dictionary with a port restriction, by prefixing old dictionary. 746 // Create a dictionary with a port restriction, by prefixing old dictionary.
736 const std::string port("502"); 747 const std::string port("502");
737 std::string dictionary_with_port("Port: " + port + "\n"); 748 std::string dictionary_with_port("Port: " + port + "\n");
738 dictionary_with_port.append("Port: 80\n"); // Add default port. 749 dictionary_with_port.append("Port: 80\n"); // Add default port.
739 dictionary_with_port.append(dictionary); 750 dictionary_with_port.append(dictionary);
740 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, 751 EXPECT_TRUE(AddSdchDictionary(dictionary_with_port,
741 GURL(url_string + ":" + port))); 752 GURL(url_string + ":" + port)));
742 753
743 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); 754 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
744 755
745 std::vector<Filter::FilterType> filter_types; 756 std::vector<Filter::FilterType> filter_types;
746 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 757 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
747 758
748 // Test decode the port data, arriving from a valid port. 759 // Test decode the port data, arriving from a valid port.
749 filter_context()->SetURL(GURL(url_string + ":" + port)); 760 filter_context()->SetURL(GURL(url_string + ":" + port));
750 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 761 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
751 762
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 // routinely followed by gzip (during encoding). The filter we'll test for will 863 // routinely followed by gzip (during encoding). The filter we'll test for will
853 // do the gzip decoding first, and then decode the SDCH content. 864 // do the gzip decoding first, and then decode the SDCH content.
854 TEST_F(SdchFilterTest, FilterChaining) { 865 TEST_F(SdchFilterTest, FilterChaining) {
855 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 866 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
856 const std::string kSampleDomain = "sdchtest.com"; 867 const std::string kSampleDomain = "sdchtest.com";
857 std::string dictionary(NewSdchDictionary(kSampleDomain)); 868 std::string dictionary(NewSdchDictionary(kSampleDomain));
858 869
859 std::string url_string = "http://" + kSampleDomain; 870 std::string url_string = "http://" + kSampleDomain;
860 871
861 GURL url(url_string); 872 GURL url(url_string);
862 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 873 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
863 874
864 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 875 std::string sdch_compressed(NewSdchCompressedData(dictionary));
865 876
866 // Use Gzip to compress the sdch sdch_compressed data. 877 // Use Gzip to compress the sdch sdch_compressed data.
867 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 878 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
868 879
869 // Construct a chained filter. 880 // Construct a chained filter.
870 std::vector<Filter::FilterType> filter_types; 881 std::vector<Filter::FilterType> filter_types;
871 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 882 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
872 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 883 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 } 945 }
935 946
936 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { 947 TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
937 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 948 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
938 const std::string kSampleDomain = "sdchtest.com"; 949 const std::string kSampleDomain = "sdchtest.com";
939 std::string dictionary(NewSdchDictionary(kSampleDomain)); 950 std::string dictionary(NewSdchDictionary(kSampleDomain));
940 951
941 std::string url_string = "http://" + kSampleDomain; 952 std::string url_string = "http://" + kSampleDomain;
942 953
943 GURL url(url_string); 954 GURL url(url_string);
944 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 955 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
945 956
946 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 957 std::string sdch_compressed(NewSdchCompressedData(dictionary));
947 958
948 // Use Gzip to compress the sdch sdch_compressed data. 959 // Use Gzip to compress the sdch sdch_compressed data.
949 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 960 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
950 961
951 // Only claim to have sdch content, but really use the gzipped sdch content. 962 // Only claim to have sdch content, but really use the gzipped sdch content.
952 // System should automatically add the missing (optional) gzip. 963 // System should automatically add the missing (optional) gzip.
953 std::vector<Filter::FilterType> filter_types; 964 std::vector<Filter::FilterType> filter_types;
954 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 965 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } 1001 }
991 1002
992 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { 1003 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) {
993 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 1004 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
994 const std::string kSampleDomain = "sdchtest.com"; 1005 const std::string kSampleDomain = "sdchtest.com";
995 std::string dictionary(NewSdchDictionary(kSampleDomain)); 1006 std::string dictionary(NewSdchDictionary(kSampleDomain));
996 1007
997 std::string url_string = "http://" + kSampleDomain; 1008 std::string url_string = "http://" + kSampleDomain;
998 1009
999 GURL url(url_string); 1010 GURL url(url_string);
1000 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 1011 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
1001 1012
1002 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 1013 std::string sdch_compressed(NewSdchCompressedData(dictionary));
1003 1014
1004 // Use Gzip to compress the sdch sdch_compressed data. 1015 // Use Gzip to compress the sdch sdch_compressed data.
1005 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 1016 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
1006 1017
1007 // Some proxies strip the content encoding statement down to a mere gzip, but 1018 // Some proxies strip the content encoding statement down to a mere gzip, but
1008 // pass through the original content (with full sdch,gzip encoding). 1019 // pass through the original content (with full sdch,gzip encoding).
1009 // Only claim to have gzip content, but really use the gzipped sdch content. 1020 // Only claim to have gzip content, but really use the gzipped sdch content.
1010 // System should automatically add the missing (optional) sdch. 1021 // System should automatically add the missing (optional) sdch.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1060 }
1050 1061
1051 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { 1062 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) {
1052 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 1063 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
1053 const std::string kSampleDomain = "sdchtest.com"; 1064 const std::string kSampleDomain = "sdchtest.com";
1054 std::string dictionary(NewSdchDictionary(kSampleDomain)); 1065 std::string dictionary(NewSdchDictionary(kSampleDomain));
1055 1066
1056 std::string url_string = "http://" + kSampleDomain; 1067 std::string url_string = "http://" + kSampleDomain;
1057 1068
1058 GURL url(url_string); 1069 GURL url(url_string);
1059 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 1070 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
1060 1071
1061 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 1072 std::string sdch_compressed(NewSdchCompressedData(dictionary));
1062 1073
1063 // Use Gzip to compress the sdch sdch_compressed data. 1074 // Use Gzip to compress the sdch sdch_compressed data.
1064 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 1075 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
1065 1076
1066 // Only claim to have non-encoded content, but really use the gzipped sdch 1077 // Only claim to have non-encoded content, but really use the gzipped sdch
1067 // content. 1078 // content.
1068 // System should automatically add the missing (optional) sdch,gzip. 1079 // System should automatically add the missing (optional) sdch,gzip.
1069 std::vector<Filter::FilterType> filter_types; 1080 std::vector<Filter::FilterType> filter_types;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1116 }
1106 1117
1107 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { 1118 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) {
1108 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 1119 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
1109 const std::string kSampleDomain = "sdchtest.com"; 1120 const std::string kSampleDomain = "sdchtest.com";
1110 std::string dictionary(NewSdchDictionary(kSampleDomain)); 1121 std::string dictionary(NewSdchDictionary(kSampleDomain));
1111 1122
1112 std::string url_string = "http://" + kSampleDomain; 1123 std::string url_string = "http://" + kSampleDomain;
1113 1124
1114 GURL url(url_string); 1125 GURL url(url_string);
1115 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 1126 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
1116 1127
1117 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 1128 std::string sdch_compressed(NewSdchCompressedData(dictionary));
1118 1129
1119 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content 1130 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content
1120 // encoding of merely gzip (apparently, only listing the extra level of 1131 // encoding of merely gzip (apparently, only listing the extra level of
1121 // wrapper compression they added, but discarding the actual content encoding. 1132 // wrapper compression they added, but discarding the actual content encoding.
1122 // Use Gzip to double compress the sdch sdch_compressed data. 1133 // Use Gzip to double compress the sdch sdch_compressed data.
1123 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( 1134 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress(
1124 sdch_compressed)); 1135 sdch_compressed));
1125 1136
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1170
1160 feed_block_size = 1; 1171 feed_block_size = 1;
1161 output_block_size = 1; 1172 output_block_size = 1;
1162 output.clear(); 1173 output.clear();
1163 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1174 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1164 output_block_size, filter.get(), &output)); 1175 output_block_size, filter.get(), &output));
1165 EXPECT_EQ(output, expanded_); 1176 EXPECT_EQ(output, expanded_);
1166 } 1177 }
1167 1178
1168 } // namespace net 1179 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager_unittest.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698