| 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 dictionary_hash_postfix.size()); | 365 dictionary_hash_postfix.size()); |
| 366 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); | 366 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); |
| 367 | 367 |
| 368 // With a non-existant dictionary specifier, try to read output. | 368 // With a non-existant dictionary specifier, try to read output. |
| 369 output_bytes_or_buffer_size = sizeof(output_buffer); | 369 output_bytes_or_buffer_size = sizeof(output_buffer); |
| 370 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); | 370 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); |
| 371 | 371 |
| 372 EXPECT_EQ(0, output_bytes_or_buffer_size); | 372 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 373 EXPECT_EQ(Filter::FILTER_ERROR, status); | 373 EXPECT_EQ(Filter::FILTER_ERROR, status); |
| 374 | 374 |
| 375 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 375 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 376 SdchManager::ClearBlacklistings(); | 376 sdch_manager_->ClearBlacklistings(); |
| 377 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 377 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 378 } | 378 } |
| 379 | 379 |
| 380 TEST_F(SdchFilterTest, DictionaryAddOnce) { | 380 TEST_F(SdchFilterTest, DictionaryAddOnce) { |
| 381 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 381 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 382 const std::string kSampleDomain = "sdchtest.com"; | 382 const std::string kSampleDomain = "sdchtest.com"; |
| 383 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 383 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 384 | 384 |
| 385 std::string url_string = "http://" + kSampleDomain; | 385 std::string url_string = "http://" + kSampleDomain; |
| 386 GURL url(url_string); | 386 GURL url(url_string); |
| 387 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 387 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 filter_context.SetURL(wrong_domain_url); | 625 filter_context.SetURL(wrong_domain_url); |
| 626 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 626 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 627 | 627 |
| 628 size_t feed_block_size = 100; | 628 size_t feed_block_size = 100; |
| 629 size_t output_block_size = 100; | 629 size_t output_block_size = 100; |
| 630 std::string output; | 630 std::string output; |
| 631 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 631 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 632 filter.get(), &output)); | 632 filter.get(), &output)); |
| 633 EXPECT_EQ(output.size(), 0u); // No output written. | 633 EXPECT_EQ(output.size(), 0u); // No output written. |
| 634 | 634 |
| 635 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 635 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 636 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); | 636 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); |
| 637 SdchManager::ClearBlacklistings(); | 637 sdch_manager_->ClearBlacklistings(); |
| 638 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); | 638 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); |
| 639 } | 639 } |
| 640 | 640 |
| 641 TEST_F(SdchFilterTest, DictionaryPathValidation) { | 641 TEST_F(SdchFilterTest, DictionaryPathValidation) { |
| 642 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 642 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 643 const std::string kSampleDomain = "sdchtest.com"; | 643 const std::string kSampleDomain = "sdchtest.com"; |
| 644 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 644 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 645 | 645 |
| 646 std::string url_string = "http://" + kSampleDomain; | 646 std::string url_string = "http://" + kSampleDomain; |
| 647 | 647 |
| 648 GURL url(url_string); | 648 GURL url(url_string); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 676 filter_context.SetURL(GURL(url_string)); | 676 filter_context.SetURL(GURL(url_string)); |
| 677 filter.reset(Filter::Factory(filter_types, filter_context)); | 677 filter.reset(Filter::Factory(filter_types, filter_context)); |
| 678 | 678 |
| 679 feed_block_size = 100; | 679 feed_block_size = 100; |
| 680 output_block_size = 100; | 680 output_block_size = 100; |
| 681 output.clear(); | 681 output.clear(); |
| 682 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, | 682 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, |
| 683 output_block_size, filter.get(), &output)); | 683 output_block_size, filter.get(), &output)); |
| 684 EXPECT_EQ(output.size(), 0u); // No output written. | 684 EXPECT_EQ(output.size(), 0u); // No output written. |
| 685 | 685 |
| 686 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 686 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 687 SdchManager::ClearBlacklistings(); | 687 sdch_manager_->ClearBlacklistings(); |
| 688 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 688 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 689 } | 689 } |
| 690 | 690 |
| 691 TEST_F(SdchFilterTest, DictionaryPortValidation) { | 691 TEST_F(SdchFilterTest, DictionaryPortValidation) { |
| 692 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 692 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 693 const std::string kSampleDomain = "sdchtest.com"; | 693 const std::string kSampleDomain = "sdchtest.com"; |
| 694 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 694 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 695 | 695 |
| 696 std::string url_string = "http://" + kSampleDomain; | 696 std::string url_string = "http://" + kSampleDomain; |
| 697 | 697 |
| 698 GURL url(url_string); | 698 GURL url(url_string); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 filter_context.SetURL(GURL(url_string + ":" + port + "1")); | 739 filter_context.SetURL(GURL(url_string + ":" + port + "1")); |
| 740 filter.reset(Filter::Factory(filter_types, filter_context)); | 740 filter.reset(Filter::Factory(filter_types, filter_context)); |
| 741 | 741 |
| 742 feed_block_size = 100; | 742 feed_block_size = 100; |
| 743 output_block_size = 100; | 743 output_block_size = 100; |
| 744 output.clear(); | 744 output.clear(); |
| 745 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, | 745 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, |
| 746 output_block_size, filter.get(), &output)); | 746 output_block_size, filter.get(), &output)); |
| 747 EXPECT_EQ(output.size(), 0u); // No output written. | 747 EXPECT_EQ(output.size(), 0u); // No output written. |
| 748 | 748 |
| 749 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 749 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 750 SdchManager::ClearBlacklistings(); | 750 sdch_manager_->ClearBlacklistings(); |
| 751 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); | 751 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 752 } | 752 } |
| 753 | 753 |
| 754 //------------------------------------------------------------------------------ | 754 //------------------------------------------------------------------------------ |
| 755 // Helper function to perform gzip compression of data. | 755 // Helper function to perform gzip compression of data. |
| 756 | 756 |
| 757 static std::string gzip_compress(const std::string &input) { | 757 static std::string gzip_compress(const std::string &input) { |
| 758 z_stream zlib_stream; | 758 z_stream zlib_stream; |
| 759 memset(&zlib_stream, 0, sizeof(zlib_stream)); | 759 memset(&zlib_stream, 0, sizeof(zlib_stream)); |
| 760 int code; | 760 int code; |
| 761 | 761 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 | 1132 |
| 1133 feed_block_size = 1; | 1133 feed_block_size = 1; |
| 1134 output_block_size = 1; | 1134 output_block_size = 1; |
| 1135 output.clear(); | 1135 output.clear(); |
| 1136 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1136 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
| 1137 output_block_size, filter.get(), &output)); | 1137 output_block_size, filter.get(), &output)); |
| 1138 EXPECT_EQ(output, expanded_); | 1138 EXPECT_EQ(output, expanded_); |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 } // namespace net | 1141 } // namespace net |
| OLD | NEW |