OLD | NEW |
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 Loading... |
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 | 66 // Attempt to add a dictionary to the manager and probe for success or |
67 // the attempt succeeded. | 67 // failure. |
68 bool AddSdchDictionary(const std::string& dictionary_text, | 68 bool AddSdchDictionary(const std::string& dictionary_text, |
69 const GURL& gurl) { | 69 const GURL& gurl) { |
70 std::string list; | 70 scoped_ptr<SdchManager::DictionarySet> set1( |
71 sdch_manager_->GetAvailDictionaryList(gurl, &list); | 71 sdch_manager_->GetDictionarySet(gurl)); |
| 72 std::string set1_hashes; |
| 73 if (set1) |
| 74 set1->GetDictionaryClientHashList(&set1_hashes); |
| 75 |
72 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); | 76 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); |
73 std::string list2; | 77 scoped_ptr<SdchManager::DictionarySet> set2( |
74 sdch_manager_->GetAvailDictionaryList(gurl, &list2); | 78 sdch_manager_->GetDictionarySet(gurl)); |
| 79 std::string set2_hashes; |
| 80 if (set2) |
| 81 set2->GetDictionaryClientHashList(&set2_hashes); |
75 | 82 |
76 // The list of hashes should change iff the addition succeeds. | 83 // The list of hashes should change iff the addition succeeds. |
77 return (list != list2); | 84 return (set1_hashes != set2_hashes); |
78 } | 85 } |
79 | 86 |
80 MockFilterContext* filter_context() { return filter_context_.get(); } | 87 MockFilterContext* filter_context() { return filter_context_.get(); } |
81 | 88 |
| 89 // Sets both the GURL and the SDCH response for a filter context. |
| 90 void SetupFilterContextWithGURL(GURL url) { |
| 91 filter_context_->SetURL(url); |
| 92 filter_context_->SetSdchResponse( |
| 93 sdch_manager_->GetDictionarySet(url).Pass()); |
| 94 } |
| 95 |
82 std::string NewSdchCompressedData(const std::string dictionary) { | 96 std::string NewSdchCompressedData(const std::string dictionary) { |
83 std::string client_hash; | 97 std::string client_hash; |
84 std::string server_hash; | 98 std::string server_hash; |
85 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 99 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
86 | 100 |
87 // Build compressed data that refers to our dictionary. | 101 // Build compressed data that refers to our dictionary. |
88 std::string compressed(server_hash); | 102 std::string compressed(server_hash); |
89 compressed.append("\0", 1); | 103 compressed.append("\0", 1); |
90 compressed.append(vcdiff_compressed_data_); | 104 compressed.append(vcdiff_compressed_data_); |
91 return compressed; | 105 return compressed; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (!domain.empty()) { | 173 if (!domain.empty()) { |
160 dictionary.append("Domain: "); | 174 dictionary.append("Domain: "); |
161 dictionary.append(domain); | 175 dictionary.append(domain); |
162 dictionary.append("\n"); | 176 dictionary.append("\n"); |
163 } | 177 } |
164 dictionary.append("\n"); | 178 dictionary.append("\n"); |
165 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 179 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
166 return dictionary; | 180 return dictionary; |
167 } | 181 } |
168 | 182 |
| 183 static std::string NewSdchExpiredDictionary(const std::string& domain) { |
| 184 std::string dictionary; |
| 185 if (!domain.empty()) { |
| 186 dictionary.append("Domain: "); |
| 187 dictionary.append(domain); |
| 188 dictionary.append("\n"); |
| 189 } |
| 190 dictionary.append("Max-Age: 0\n"); |
| 191 dictionary.append("\n"); |
| 192 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 193 return dictionary; |
| 194 } |
| 195 |
169 //------------------------------------------------------------------------------ | 196 //------------------------------------------------------------------------------ |
170 | 197 |
171 TEST_F(SdchFilterTest, EmptyInputOk) { | 198 TEST_F(SdchFilterTest, EmptyInputOk) { |
172 std::vector<Filter::FilterType> filter_types; | 199 std::vector<Filter::FilterType> filter_types; |
173 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 200 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
174 char output_buffer[20]; | 201 char output_buffer[20]; |
175 std::string url_string("http://ignore.com"); | 202 std::string url_string("http://ignore.com"); |
176 filter_context()->SetURL(GURL(url_string)); | 203 filter_context()->SetURL(GURL(url_string)); |
177 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 204 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
178 | 205 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 std::string url_string = "http://" + kSampleDomain; | 477 std::string url_string = "http://" + kSampleDomain; |
451 | 478 |
452 GURL url(url_string); | 479 GURL url(url_string); |
453 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 480 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
454 | 481 |
455 std::string compressed(NewSdchCompressedData(dictionary)); | 482 std::string compressed(NewSdchCompressedData(dictionary)); |
456 | 483 |
457 std::vector<Filter::FilterType> filter_types; | 484 std::vector<Filter::FilterType> filter_types; |
458 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 485 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
459 | 486 |
460 filter_context()->SetURL(url); | 487 SetupFilterContextWithGURL(url); |
461 | 488 |
462 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 489 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
463 | 490 |
464 size_t feed_block_size = 100; | 491 size_t feed_block_size = 100; |
465 size_t output_block_size = 100; | 492 size_t output_block_size = 100; |
466 std::string output; | 493 std::string output; |
467 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 494 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
468 filter.get(), &output)); | 495 filter.get(), &output)); |
469 EXPECT_EQ(output, expanded_); | 496 EXPECT_EQ(output, expanded_); |
470 | 497 |
(...skipping 16 matching lines...) Expand all Loading... |
487 std::string url_string = "http://" + kSampleDomain; | 514 std::string url_string = "http://" + kSampleDomain; |
488 | 515 |
489 GURL url(url_string); | 516 GURL url(url_string); |
490 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 517 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
491 | 518 |
492 std::string compressed(NewSdchCompressedData(dictionary)); | 519 std::string compressed(NewSdchCompressedData(dictionary)); |
493 | 520 |
494 std::vector<Filter::FilterType> filter_types; | 521 std::vector<Filter::FilterType> filter_types; |
495 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 522 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
496 | 523 |
497 filter_context()->SetURL(GURL("https://" + kSampleDomain)); | 524 GURL filter_context_gurl("https://" + kSampleDomain); |
| 525 SetupFilterContextWithGURL(GURL("https://" + kSampleDomain)); |
498 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 526 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
499 | 527 |
500 const size_t feed_block_size(100); | 528 const size_t feed_block_size(100); |
501 const size_t output_block_size(100); | 529 const size_t output_block_size(100); |
502 std::string output; | 530 std::string output; |
503 | 531 |
504 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 532 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
505 filter.get(), &output)); | 533 filter.get(), &output)); |
506 } | 534 } |
507 | 535 |
508 // Current failsafe TODO/hack refuses to decode any content that doesn't use | 536 // Current failsafe TODO/hack refuses to decode any content that doesn't use |
509 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). | 537 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). |
510 // The following tests this blockage. Note that blacklisting results, so we | 538 // The following tests this blockage. Note that blacklisting results, so we |
511 // we need separate tests for each of these. | 539 // we need separate tests for each of these. |
512 TEST_F(SdchFilterTest, NoDecodeFtp) { | 540 TEST_F(SdchFilterTest, NoDecodeFtp) { |
513 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 541 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
514 const std::string kSampleDomain = "sdchtest.com"; | 542 const std::string kSampleDomain = "sdchtest.com"; |
515 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 543 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
516 | 544 |
517 std::string url_string = "http://" + kSampleDomain; | 545 std::string url_string = "http://" + kSampleDomain; |
518 | 546 |
519 GURL url(url_string); | 547 GURL url(url_string); |
520 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 548 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
521 | 549 |
522 std::string compressed(NewSdchCompressedData(dictionary)); | 550 std::string compressed(NewSdchCompressedData(dictionary)); |
523 | 551 |
524 std::vector<Filter::FilterType> filter_types; | 552 std::vector<Filter::FilterType> filter_types; |
525 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 553 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
526 | 554 |
527 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); | 555 SetupFilterContextWithGURL(GURL("ftp://" + kSampleDomain)); |
528 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 556 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
529 | 557 |
530 const size_t feed_block_size(100); | 558 const size_t feed_block_size(100); |
531 const size_t output_block_size(100); | 559 const size_t output_block_size(100); |
532 std::string output; | 560 std::string output; |
533 | 561 |
534 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 562 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
535 filter.get(), &output)); | 563 filter.get(), &output)); |
536 } | 564 } |
537 | 565 |
538 TEST_F(SdchFilterTest, NoDecodeFileColon) { | 566 TEST_F(SdchFilterTest, NoDecodeFileColon) { |
539 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 567 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
540 const std::string kSampleDomain = "sdchtest.com"; | 568 const std::string kSampleDomain = "sdchtest.com"; |
541 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 569 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
542 | 570 |
543 std::string url_string = "http://" + kSampleDomain; | 571 std::string url_string = "http://" + kSampleDomain; |
544 | 572 |
545 GURL url(url_string); | 573 GURL url(url_string); |
546 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 574 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
547 | 575 |
548 std::string compressed(NewSdchCompressedData(dictionary)); | 576 std::string compressed(NewSdchCompressedData(dictionary)); |
549 | 577 |
550 std::vector<Filter::FilterType> filter_types; | 578 std::vector<Filter::FilterType> filter_types; |
551 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 579 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
552 | 580 |
553 filter_context()->SetURL(GURL("file://" + kSampleDomain)); | 581 SetupFilterContextWithGURL(GURL("file://" + kSampleDomain)); |
554 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 582 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
555 | 583 |
556 const size_t feed_block_size(100); | 584 const size_t feed_block_size(100); |
557 const size_t output_block_size(100); | 585 const size_t output_block_size(100); |
558 std::string output; | 586 std::string output; |
559 | 587 |
560 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 588 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
561 filter.get(), &output)); | 589 filter.get(), &output)); |
562 } | 590 } |
563 | 591 |
564 TEST_F(SdchFilterTest, NoDecodeAboutColon) { | 592 TEST_F(SdchFilterTest, NoDecodeAboutColon) { |
565 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 593 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
566 const std::string kSampleDomain = "sdchtest.com"; | 594 const std::string kSampleDomain = "sdchtest.com"; |
567 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 595 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
568 | 596 |
569 std::string url_string = "http://" + kSampleDomain; | 597 std::string url_string = "http://" + kSampleDomain; |
570 | 598 |
571 GURL url(url_string); | 599 GURL url(url_string); |
572 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 600 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
573 | 601 |
574 std::string compressed(NewSdchCompressedData(dictionary)); | 602 std::string compressed(NewSdchCompressedData(dictionary)); |
575 | 603 |
576 std::vector<Filter::FilterType> filter_types; | 604 std::vector<Filter::FilterType> filter_types; |
577 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 605 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
578 | 606 |
579 filter_context()->SetURL(GURL("about://" + kSampleDomain)); | 607 SetupFilterContextWithGURL(GURL("about://" + kSampleDomain)); |
580 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 608 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
581 | 609 |
582 const size_t feed_block_size(100); | 610 const size_t feed_block_size(100); |
583 const size_t output_block_size(100); | 611 const size_t output_block_size(100); |
584 std::string output; | 612 std::string output; |
585 | 613 |
586 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 614 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
587 filter.get(), &output)); | 615 filter.get(), &output)); |
588 } | 616 } |
589 | 617 |
590 TEST_F(SdchFilterTest, NoDecodeJavaScript) { | 618 TEST_F(SdchFilterTest, NoDecodeJavaScript) { |
591 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 619 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
592 const std::string kSampleDomain = "sdchtest.com"; | 620 const std::string kSampleDomain = "sdchtest.com"; |
593 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 621 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
594 | 622 |
595 std::string url_string = "http://" + kSampleDomain; | 623 std::string url_string = "http://" + kSampleDomain; |
596 | 624 |
597 GURL url(url_string); | 625 GURL url(url_string); |
598 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 626 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
599 | 627 |
600 std::string compressed(NewSdchCompressedData(dictionary)); | 628 std::string compressed(NewSdchCompressedData(dictionary)); |
601 | 629 |
602 std::vector<Filter::FilterType> filter_types; | 630 std::vector<Filter::FilterType> filter_types; |
603 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 631 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
604 | 632 |
605 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); | 633 SetupFilterContextWithGURL(GURL("javascript://" + kSampleDomain)); |
606 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 634 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
607 | 635 |
608 const size_t feed_block_size(100); | 636 const size_t feed_block_size(100); |
609 const size_t output_block_size(100); | 637 const size_t output_block_size(100); |
610 std::string output; | 638 std::string output; |
611 | 639 |
612 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 640 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
613 filter.get(), &output)); | 641 filter.get(), &output)); |
614 } | 642 } |
615 | 643 |
616 TEST_F(SdchFilterTest, CanStillDecodeHttp) { | 644 TEST_F(SdchFilterTest, CanStillDecodeHttp) { |
617 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 645 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
618 const std::string kSampleDomain = "sdchtest.com"; | 646 const std::string kSampleDomain = "sdchtest.com"; |
619 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 647 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
620 | 648 |
621 std::string url_string = "http://" + kSampleDomain; | 649 std::string url_string = "http://" + kSampleDomain; |
622 | 650 |
623 GURL url(url_string); | 651 GURL url(url_string); |
624 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 652 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
625 | 653 |
626 std::string compressed(NewSdchCompressedData(dictionary)); | 654 std::string compressed(NewSdchCompressedData(dictionary)); |
627 | 655 |
628 std::vector<Filter::FilterType> filter_types; | 656 std::vector<Filter::FilterType> filter_types; |
629 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 657 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
630 | 658 |
631 filter_context()->SetURL(GURL("http://" + kSampleDomain)); | 659 SetupFilterContextWithGURL(GURL("http://" + kSampleDomain)); |
632 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 660 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
633 | 661 |
634 const size_t feed_block_size(100); | 662 const size_t feed_block_size(100); |
635 const size_t output_block_size(100); | 663 const size_t output_block_size(100); |
636 std::string output; | 664 std::string output; |
637 | 665 |
638 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 666 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
639 filter.get(), &output)); | 667 filter.get(), &output)); |
640 } | 668 } |
641 | 669 |
642 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { | 670 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { |
643 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 671 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
644 const std::string kSampleDomain = "sdchtest.com"; | 672 const std::string kSampleDomain = "sdchtest.com"; |
645 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 673 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
646 | 674 |
647 std::string url_string = "http://" + kSampleDomain; | 675 std::string url_string = "http://" + kSampleDomain; |
648 | 676 |
649 GURL url(url_string); | 677 GURL url(url_string); |
650 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 678 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
651 | 679 |
652 std::string compressed(NewSdchCompressedData(dictionary)); | 680 std::string compressed(NewSdchCompressedData(dictionary)); |
653 | 681 |
654 std::vector<Filter::FilterType> filter_types; | 682 std::vector<Filter::FilterType> filter_types; |
655 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 683 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
656 | 684 |
657 // Decode with content arriving from the "wrong" domain. | 685 // Decode with content arriving from the "wrong" domain. |
658 // This tests SdchManager::CanSet(). | 686 // This tests SdchManager::CanSet(). |
659 GURL wrong_domain_url("http://www.wrongdomain.com"); | 687 GURL wrong_domain_url("http://www.wrongdomain.com"); |
660 filter_context()->SetURL(wrong_domain_url); | 688 SetupFilterContextWithGURL(wrong_domain_url); |
661 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 689 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
662 | 690 |
663 size_t feed_block_size = 100; | 691 size_t feed_block_size = 100; |
664 size_t output_block_size = 100; | 692 size_t output_block_size = 100; |
665 std::string output; | 693 std::string output; |
666 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 694 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
667 filter.get(), &output)); | 695 filter.get(), &output)); |
668 EXPECT_EQ(output.size(), 0u); // No output written. | 696 EXPECT_EQ(output.size(), 0u); // No output written. |
669 | 697 |
670 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 698 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
(...skipping 23 matching lines...) Expand all Loading... |
694 dictionary_with_path.append(dictionary); | 722 dictionary_with_path.append(dictionary); |
695 GURL url2(url_string + path); | 723 GURL url2(url_string + path); |
696 EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2)); | 724 EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2)); |
697 | 725 |
698 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); | 726 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); |
699 | 727 |
700 std::vector<Filter::FilterType> filter_types; | 728 std::vector<Filter::FilterType> filter_types; |
701 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 729 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
702 | 730 |
703 // Test decode the path data, arriving from a valid path. | 731 // Test decode the path data, arriving from a valid path. |
704 filter_context()->SetURL(GURL(url_string + path)); | 732 SetupFilterContextWithGURL(GURL(url_string + path)); |
705 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 733 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
706 | 734 |
707 size_t feed_block_size = 100; | 735 size_t feed_block_size = 100; |
708 size_t output_block_size = 100; | 736 size_t output_block_size = 100; |
709 std::string output; | 737 std::string output; |
710 | 738 |
711 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, | 739 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, |
712 output_block_size, filter.get(), &output)); | 740 output_block_size, filter.get(), &output)); |
713 EXPECT_EQ(output, expanded_); | 741 EXPECT_EQ(output, expanded_); |
714 | 742 |
715 // Test decode the path data, arriving from a invalid path. | 743 // Test decode the path data, arriving from a invalid path. |
716 filter_context()->SetURL(GURL(url_string)); | 744 SetupFilterContextWithGURL(GURL(url_string)); |
717 filter.reset(Filter::Factory(filter_types, *filter_context())); | 745 filter.reset(Filter::Factory(filter_types, *filter_context())); |
718 | 746 |
719 feed_block_size = 100; | 747 feed_block_size = 100; |
720 output_block_size = 100; | 748 output_block_size = 100; |
721 output.clear(); | 749 output.clear(); |
722 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, | 750 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, |
723 output_block_size, filter.get(), &output)); | 751 output_block_size, filter.get(), &output)); |
724 EXPECT_EQ(output.size(), 0u); // No output written. | 752 EXPECT_EQ(output.size(), 0u); // No output written. |
725 | 753 |
726 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 754 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
(...skipping 23 matching lines...) Expand all Loading... |
750 dictionary_with_port.append(dictionary); | 778 dictionary_with_port.append(dictionary); |
751 EXPECT_TRUE(AddSdchDictionary(dictionary_with_port, | 779 EXPECT_TRUE(AddSdchDictionary(dictionary_with_port, |
752 GURL(url_string + ":" + port))); | 780 GURL(url_string + ":" + port))); |
753 | 781 |
754 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); | 782 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); |
755 | 783 |
756 std::vector<Filter::FilterType> filter_types; | 784 std::vector<Filter::FilterType> filter_types; |
757 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 785 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
758 | 786 |
759 // Test decode the port data, arriving from a valid port. | 787 // Test decode the port data, arriving from a valid port. |
760 filter_context()->SetURL(GURL(url_string + ":" + port)); | 788 SetupFilterContextWithGURL(GURL(url_string + ":" + port)); |
761 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 789 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
762 | 790 |
763 size_t feed_block_size = 100; | 791 size_t feed_block_size = 100; |
764 size_t output_block_size = 100; | 792 size_t output_block_size = 100; |
765 std::string output; | 793 std::string output; |
766 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, | 794 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, |
767 output_block_size, filter.get(), &output)); | 795 output_block_size, filter.get(), &output)); |
768 EXPECT_EQ(output, expanded_); | 796 EXPECT_EQ(output, expanded_); |
769 | 797 |
770 // Test decode the port data, arriving from a valid (default) port. | 798 // Test decode the port data, arriving from a valid (default) port. |
771 filter_context()->SetURL(GURL(url_string)); // Default port. | 799 SetupFilterContextWithGURL(GURL(url_string)); // Default port. |
772 filter.reset(Filter::Factory(filter_types, *filter_context())); | 800 filter.reset(Filter::Factory(filter_types, *filter_context())); |
773 | 801 |
774 feed_block_size = 100; | 802 feed_block_size = 100; |
775 output_block_size = 100; | 803 output_block_size = 100; |
776 output.clear(); | 804 output.clear(); |
777 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, | 805 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, |
778 output_block_size, filter.get(), &output)); | 806 output_block_size, filter.get(), &output)); |
779 EXPECT_EQ(output, expanded_); | 807 EXPECT_EQ(output, expanded_); |
780 | 808 |
781 // Test decode the port data, arriving from a invalid port. | 809 // Test decode the port data, arriving from a invalid port. |
782 filter_context()->SetURL(GURL(url_string + ":" + port + "1")); | 810 SetupFilterContextWithGURL(GURL(url_string + ":" + port + "1")); |
783 filter.reset(Filter::Factory(filter_types, *filter_context())); | 811 filter.reset(Filter::Factory(filter_types, *filter_context())); |
784 | 812 |
785 feed_block_size = 100; | 813 feed_block_size = 100; |
786 output_block_size = 100; | 814 output_block_size = 100; |
787 output.clear(); | 815 output.clear(); |
788 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, | 816 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, |
789 output_block_size, filter.get(), &output)); | 817 output_block_size, filter.get(), &output)); |
790 EXPECT_EQ(output.size(), 0u); // No output written. | 818 EXPECT_EQ(output.size(), 0u); // No output written. |
791 | 819 |
792 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 820 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 // Construct a chained filter. | 908 // Construct a chained filter. |
881 std::vector<Filter::FilterType> filter_types; | 909 std::vector<Filter::FilterType> filter_types; |
882 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 910 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
883 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 911 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
884 | 912 |
885 // First try with a large buffer (larger than test input, or compressed data). | 913 // First try with a large buffer (larger than test input, or compressed data). |
886 const size_t kLargeInputBufferSize(1000); // Used internally in filters. | 914 const size_t kLargeInputBufferSize(1000); // Used internally in filters. |
887 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); | 915 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); |
888 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); | 916 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); |
889 CHECK_GT(kLargeInputBufferSize, expanded_.size()); | 917 CHECK_GT(kLargeInputBufferSize, expanded_.size()); |
890 filter_context()->SetURL(url); | 918 SetupFilterContextWithGURL(url); |
891 scoped_ptr<Filter> filter( | 919 scoped_ptr<Filter> filter( |
892 SdchFilterChainingTest::Factory(filter_types, *filter_context(), | 920 SdchFilterChainingTest::Factory(filter_types, *filter_context(), |
893 kLargeInputBufferSize)); | 921 kLargeInputBufferSize)); |
894 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), | 922 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), |
895 filter->stream_buffer_size()); | 923 filter->stream_buffer_size()); |
896 | 924 |
897 // Verify that chained filter is waiting for data. | 925 // Verify that chained filter is waiting for data. |
898 char tiny_output_buffer[10]; | 926 char tiny_output_buffer[10]; |
899 int tiny_output_size = sizeof(tiny_output_buffer); | 927 int tiny_output_size = sizeof(tiny_output_buffer); |
900 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 928 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 | 986 |
959 // Use Gzip to compress the sdch sdch_compressed data. | 987 // Use Gzip to compress the sdch sdch_compressed data. |
960 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 988 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
961 | 989 |
962 // Only claim to have sdch content, but really use the gzipped sdch content. | 990 // Only claim to have sdch content, but really use the gzipped sdch content. |
963 // System should automatically add the missing (optional) gzip. | 991 // System should automatically add the missing (optional) gzip. |
964 std::vector<Filter::FilterType> filter_types; | 992 std::vector<Filter::FilterType> filter_types; |
965 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 993 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
966 | 994 |
967 filter_context()->SetMimeType("anything/mime"); | 995 filter_context()->SetMimeType("anything/mime"); |
968 filter_context()->SetSdchResponse(true); | 996 SetupFilterContextWithGURL(url); |
| 997 |
969 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 998 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
970 ASSERT_EQ(filter_types.size(), 2u); | 999 ASSERT_EQ(filter_types.size(), 2u); |
971 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); | 1000 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); |
972 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1001 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
973 | 1002 |
974 // First try with a large buffer (larger than test input, or compressed data). | 1003 // First try with a large buffer (larger than test input, or compressed data). |
975 filter_context()->SetURL(url); | 1004 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
976 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | |
977 | |
978 | 1005 |
979 // Verify that chained filter is waiting for data. | 1006 // Verify that chained filter is waiting for data. |
980 char tiny_output_buffer[10]; | 1007 char tiny_output_buffer[10]; |
981 int tiny_output_size = sizeof(tiny_output_buffer); | 1008 int tiny_output_size = sizeof(tiny_output_buffer); |
982 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1009 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
983 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1010 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
984 | 1011 |
985 size_t feed_block_size = 100; | 1012 size_t feed_block_size = 100; |
986 size_t output_block_size = 100; | 1013 size_t output_block_size = 100; |
987 std::string output; | 1014 std::string output; |
(...skipping 28 matching lines...) Expand all Loading... |
1016 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1043 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
1017 | 1044 |
1018 // Some proxies strip the content encoding statement down to a mere gzip, but | 1045 // Some proxies strip the content encoding statement down to a mere gzip, but |
1019 // pass through the original content (with full sdch,gzip encoding). | 1046 // pass through the original content (with full sdch,gzip encoding). |
1020 // Only claim to have gzip content, but really use the gzipped sdch content. | 1047 // Only claim to have gzip content, but really use the gzipped sdch content. |
1021 // System should automatically add the missing (optional) sdch. | 1048 // System should automatically add the missing (optional) sdch. |
1022 std::vector<Filter::FilterType> filter_types; | 1049 std::vector<Filter::FilterType> filter_types; |
1023 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 1050 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
1024 | 1051 |
1025 filter_context()->SetMimeType("anything/mime"); | 1052 filter_context()->SetMimeType("anything/mime"); |
1026 filter_context()->SetSdchResponse(true); | 1053 SetupFilterContextWithGURL(url); |
1027 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1054 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
1028 ASSERT_EQ(filter_types.size(), 3u); | 1055 ASSERT_EQ(filter_types.size(), 3u); |
1029 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1056 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
1030 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1057 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
1031 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1058 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
1032 | 1059 |
1033 // First try with a large buffer (larger than test input, or compressed data). | 1060 // First try with a large buffer (larger than test input, or compressed data). |
1034 filter_context()->SetURL(url); | |
1035 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1061 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
1036 | 1062 |
1037 | |
1038 // Verify that chained filter is waiting for data. | 1063 // Verify that chained filter is waiting for data. |
1039 char tiny_output_buffer[10]; | 1064 char tiny_output_buffer[10]; |
1040 int tiny_output_size = sizeof(tiny_output_buffer); | 1065 int tiny_output_size = sizeof(tiny_output_buffer); |
1041 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1066 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
1042 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1067 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
1043 | 1068 |
1044 size_t feed_block_size = 100; | 1069 size_t feed_block_size = 100; |
1045 size_t output_block_size = 100; | 1070 size_t output_block_size = 100; |
1046 std::string output; | 1071 std::string output; |
1047 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, | 1072 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, |
(...skipping 25 matching lines...) Expand all Loading... |
1073 | 1098 |
1074 // Use Gzip to compress the sdch sdch_compressed data. | 1099 // Use Gzip to compress the sdch sdch_compressed data. |
1075 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1100 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
1076 | 1101 |
1077 // Only claim to have non-encoded content, but really use the gzipped sdch | 1102 // Only claim to have non-encoded content, but really use the gzipped sdch |
1078 // content. | 1103 // content. |
1079 // System should automatically add the missing (optional) sdch,gzip. | 1104 // System should automatically add the missing (optional) sdch,gzip. |
1080 std::vector<Filter::FilterType> filter_types; | 1105 std::vector<Filter::FilterType> filter_types; |
1081 | 1106 |
1082 filter_context()->SetMimeType("anything/mime"); | 1107 filter_context()->SetMimeType("anything/mime"); |
1083 filter_context()->SetSdchResponse(true); | 1108 SetupFilterContextWithGURL(url); |
1084 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1109 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
1085 ASSERT_EQ(filter_types.size(), 2u); | 1110 ASSERT_EQ(filter_types.size(), 2u); |
1086 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1111 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
1087 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1112 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
1088 | 1113 |
1089 // First try with a large buffer (larger than test input, or compressed data). | 1114 // First try with a large buffer (larger than test input, or compressed data). |
1090 filter_context()->SetURL(url); | |
1091 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1115 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
1092 | 1116 |
1093 | |
1094 // Verify that chained filter is waiting for data. | 1117 // Verify that chained filter is waiting for data. |
1095 char tiny_output_buffer[10]; | 1118 char tiny_output_buffer[10]; |
1096 int tiny_output_size = sizeof(tiny_output_buffer); | 1119 int tiny_output_size = sizeof(tiny_output_buffer); |
1097 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1120 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
1098 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1121 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
1099 | 1122 |
1100 size_t feed_block_size = 100; | 1123 size_t feed_block_size = 100; |
1101 size_t output_block_size = 100; | 1124 size_t output_block_size = 100; |
1102 std::string output; | 1125 std::string output; |
1103 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, | 1126 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, |
(...skipping 30 matching lines...) Expand all Loading... |
1134 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( | 1157 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( |
1135 sdch_compressed)); | 1158 sdch_compressed)); |
1136 | 1159 |
1137 // Only claim to have gzip content, but really use the double gzipped sdch | 1160 // Only claim to have gzip content, but really use the double gzipped sdch |
1138 // content. | 1161 // content. |
1139 // System should automatically add the missing (optional) sdch, gzip decoders. | 1162 // System should automatically add the missing (optional) sdch, gzip decoders. |
1140 std::vector<Filter::FilterType> filter_types; | 1163 std::vector<Filter::FilterType> filter_types; |
1141 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 1164 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
1142 | 1165 |
1143 filter_context()->SetMimeType("anything/mime"); | 1166 filter_context()->SetMimeType("anything/mime"); |
1144 filter_context()->SetSdchResponse(true); | 1167 SetupFilterContextWithGURL(url); |
1145 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1168 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
1146 ASSERT_EQ(filter_types.size(), 3u); | 1169 ASSERT_EQ(filter_types.size(), 3u); |
1147 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1170 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
1148 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1171 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
1149 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1172 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
1150 | 1173 |
1151 // First try with a large buffer (larger than test input, or compressed data). | 1174 // First try with a large buffer (larger than test input, or compressed data). |
1152 filter_context()->SetURL(url); | |
1153 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1175 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
1154 | 1176 |
1155 // Verify that chained filter is waiting for data. | 1177 // Verify that chained filter is waiting for data. |
1156 char tiny_output_buffer[10]; | 1178 char tiny_output_buffer[10]; |
1157 int tiny_output_size = sizeof(tiny_output_buffer); | 1179 int tiny_output_size = sizeof(tiny_output_buffer); |
1158 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1180 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
1159 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1181 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
1160 | 1182 |
1161 size_t feed_block_size = 100; | 1183 size_t feed_block_size = 100; |
1162 size_t output_block_size = 100; | 1184 size_t output_block_size = 100; |
1163 std::string output; | 1185 std::string output; |
1164 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1186 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
1165 output_block_size, filter.get(), &output)); | 1187 output_block_size, filter.get(), &output)); |
1166 EXPECT_EQ(output, expanded_); | 1188 EXPECT_EQ(output, expanded_); |
1167 | 1189 |
1168 // Next try with a tiny buffer to cover edge effects. | 1190 // Next try with a tiny buffer to cover edge effects. |
1169 filter.reset(Filter::Factory(filter_types, *filter_context())); | 1191 filter.reset(Filter::Factory(filter_types, *filter_context())); |
1170 | 1192 |
1171 feed_block_size = 1; | 1193 feed_block_size = 1; |
1172 output_block_size = 1; | 1194 output_block_size = 1; |
1173 output.clear(); | 1195 output.clear(); |
1174 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1196 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
1175 output_block_size, filter.get(), &output)); | 1197 output_block_size, filter.get(), &output)); |
1176 EXPECT_EQ(output, expanded_); | 1198 EXPECT_EQ(output, expanded_); |
1177 } | 1199 } |
1178 | 1200 |
| 1201 // Test to make sure we decode properly with an unexpected dictionary. |
| 1202 TEST_F(SdchFilterTest, UnexpectedDictionary) { |
| 1203 // Setup a dictionary, add it to the filter context, and create a filter |
| 1204 // based on that dictionary. |
| 1205 const std::string kSampleDomain = "sdchtest.com"; |
| 1206 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 1207 std::string url_string = "http://" + kSampleDomain; |
| 1208 GURL url(url_string); |
| 1209 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 1210 |
| 1211 SetupFilterContextWithGURL(url); |
| 1212 |
| 1213 std::vector<Filter::FilterType> filter_types; |
| 1214 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 1215 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
| 1216 |
| 1217 // Setup another dictionary, expired. Don't add it to the filter context. |
| 1218 // Delete stored dictionaries first to handle platforms which only |
| 1219 // have room for a single dictionary. |
| 1220 sdch_manager_->ClearData(); |
| 1221 std::string expired_dictionary(NewSdchExpiredDictionary(kSampleDomain)); |
| 1222 |
| 1223 // This is "EXPECT_FALSE" because the returned hash list won't change |
| 1224 // because that list doesn't include expired directionaries. |
| 1225 EXPECT_FALSE(AddSdchDictionary(expired_dictionary, url)); |
| 1226 |
| 1227 // Encode output with the second dictionary. |
| 1228 std::string sdch_compressed(NewSdchCompressedData(expired_dictionary)); |
| 1229 |
| 1230 // See if the filter decodes it. |
| 1231 std::string output; |
| 1232 EXPECT_TRUE(FilterTestData(sdch_compressed, 100, 100, filter.get(), &output)); |
| 1233 EXPECT_EQ(expanded_, output); |
| 1234 } |
| 1235 |
1179 } // namespace net | 1236 } // namespace net |
OLD | NEW |