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

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

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt logging for URLReqest-based dict fetcher + cosmetics 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; returns whether or not
67 // the attempt succeeded. 67 // the attempt succeeded.
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 std::string list;
71 sdch_manager_->GetAvailDictionaryList(gurl, &list); 71 sdch_manager_->GetAvailDictionaryList(gurl, &list);
72 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); 72 sdch_manager_->AddSdchDictionary(dictionary_text, gurl, BoundNetLog());
73 std::string list2; 73 std::string list2;
74 sdch_manager_->GetAvailDictionaryList(gurl, &list2); 74 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
75 75
76 // The list of hashes should change iff the addition succeeds. 76 // The list of hashes should change iff the addition succeeds.
77 return (list != list2); 77 return (list != list2);
78 } 78 }
79 79
80 MockFilterContext* filter_context() { return filter_context_.get(); } 80 MockFilterContext* filter_context() { return filter_context_.get(); }
81 81
82 std::string NewSdchCompressedData(const std::string dictionary) { 82 std::string NewSdchCompressedData(const std::string dictionary) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 dictionary_hash_postfix.size()); 405 dictionary_hash_postfix.size());
406 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); 406 filter->FlushStreamBuffer(dictionary_hash_postfix.size());
407 407
408 // With a non-existant dictionary specifier, try to read output. 408 // With a non-existant dictionary specifier, try to read output.
409 output_bytes_or_buffer_size = sizeof(output_buffer); 409 output_bytes_or_buffer_size = sizeof(output_buffer);
410 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); 410 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
411 411
412 EXPECT_EQ(0, output_bytes_or_buffer_size); 412 EXPECT_EQ(0, output_bytes_or_buffer_size);
413 EXPECT_EQ(Filter::FILTER_ERROR, status); 413 EXPECT_EQ(Filter::FILTER_ERROR, status);
414 414
415 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 415 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET,
416 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
416 sdch_manager_->ClearBlacklistings(); 417 sdch_manager_->ClearBlacklistings();
417 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 418 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK,
419 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
418 } 420 }
419 421
420 TEST_F(SdchFilterTest, DictionaryAddOnce) { 422 TEST_F(SdchFilterTest, DictionaryAddOnce) {
421 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 423 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
422 const std::string kSampleDomain = "sdchtest.com"; 424 const std::string kSampleDomain = "sdchtest.com";
423 std::string dictionary(NewSdchDictionary(kSampleDomain)); 425 std::string dictionary(NewSdchDictionary(kSampleDomain));
424 426
425 std::string url_string = "http://" + kSampleDomain; 427 std::string url_string = "http://" + kSampleDomain;
426 GURL url(url_string); 428 GURL url(url_string);
427 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); 429 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 filter_context()->SetURL(wrong_domain_url); 662 filter_context()->SetURL(wrong_domain_url);
661 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 663 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
662 664
663 size_t feed_block_size = 100; 665 size_t feed_block_size = 100;
664 size_t output_block_size = 100; 666 size_t output_block_size = 100;
665 std::string output; 667 std::string output;
666 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 668 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
667 filter.get(), &output)); 669 filter.get(), &output));
668 EXPECT_EQ(output.size(), 0u); // No output written. 670 EXPECT_EQ(output.size(), 0u); // No output written.
669 671
670 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 672 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK,
671 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); 673 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
674 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET,
675 sdch_manager_->IsInSupportedDomain(wrong_domain_url));
672 sdch_manager_->ClearBlacklistings(); 676 sdch_manager_->ClearBlacklistings();
673 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); 677 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK,
678 sdch_manager_->IsInSupportedDomain(wrong_domain_url));
674 } 679 }
675 680
676 TEST_F(SdchFilterTest, DictionaryPathValidation) { 681 TEST_F(SdchFilterTest, DictionaryPathValidation) {
677 // Can't test path distinction between dictionaries if we aren't allowed 682 // Can't test path distinction between dictionaries if we aren't allowed
678 // more than one dictionary. 683 // more than one dictionary.
679 if (SdchManager::kMaxDictionaryCount <= 1) 684 if (SdchManager::kMaxDictionaryCount <= 1)
680 return; 685 return;
681 686
682 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 687 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
683 const std::string kSampleDomain = "sdchtest.com"; 688 const std::string kSampleDomain = "sdchtest.com";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 filter_context()->SetURL(GURL(url_string)); 721 filter_context()->SetURL(GURL(url_string));
717 filter.reset(Filter::Factory(filter_types, *filter_context())); 722 filter.reset(Filter::Factory(filter_types, *filter_context()));
718 723
719 feed_block_size = 100; 724 feed_block_size = 100;
720 output_block_size = 100; 725 output_block_size = 100;
721 output.clear(); 726 output.clear();
722 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 727 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
723 output_block_size, filter.get(), &output)); 728 output_block_size, filter.get(), &output));
724 EXPECT_EQ(output.size(), 0u); // No output written. 729 EXPECT_EQ(output.size(), 0u); // No output written.
725 730
726 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 731 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET,
732 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
727 sdch_manager_->ClearBlacklistings(); 733 sdch_manager_->ClearBlacklistings();
728 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 734 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK,
735 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
729 } 736 }
730 737
731 TEST_F(SdchFilterTest, DictionaryPortValidation) { 738 TEST_F(SdchFilterTest, DictionaryPortValidation) {
732 // Can't test port distinction between dictionaries if we aren't allowed 739 // Can't test port distinction between dictionaries if we aren't allowed
733 // more than one dictionary. 740 // more than one dictionary.
734 if (SdchManager::kMaxDictionaryCount <= 1) 741 if (SdchManager::kMaxDictionaryCount <= 1)
735 return; 742 return;
736 743
737 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 744 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
738 const std::string kSampleDomain = "sdchtest.com"; 745 const std::string kSampleDomain = "sdchtest.com";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 filter_context()->SetURL(GURL(url_string + ":" + port + "1")); 789 filter_context()->SetURL(GURL(url_string + ":" + port + "1"));
783 filter.reset(Filter::Factory(filter_types, *filter_context())); 790 filter.reset(Filter::Factory(filter_types, *filter_context()));
784 791
785 feed_block_size = 100; 792 feed_block_size = 100;
786 output_block_size = 100; 793 output_block_size = 100;
787 output.clear(); 794 output.clear();
788 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 795 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
789 output_block_size, filter.get(), &output)); 796 output_block_size, filter.get(), &output));
790 EXPECT_EQ(output.size(), 0u); // No output written. 797 EXPECT_EQ(output.size(), 0u); // No output written.
791 798
792 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 799 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET,
800 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
793 sdch_manager_->ClearBlacklistings(); 801 sdch_manager_->ClearBlacklistings();
794 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); 802 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK,
803 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
795 } 804 }
796 805
797 //------------------------------------------------------------------------------ 806 //------------------------------------------------------------------------------
798 // Helper function to perform gzip compression of data. 807 // Helper function to perform gzip compression of data.
799 808
800 static std::string gzip_compress(const std::string &input) { 809 static std::string gzip_compress(const std::string &input) {
801 z_stream zlib_stream; 810 z_stream zlib_stream;
802 memset(&zlib_stream, 0, sizeof(zlib_stream)); 811 memset(&zlib_stream, 0, sizeof(zlib_stream));
803 int code; 812 int code;
804 813
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1179
1171 feed_block_size = 1; 1180 feed_block_size = 1;
1172 output_block_size = 1; 1181 output_block_size = 1;
1173 output.clear(); 1182 output.clear();
1174 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1183 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1175 output_block_size, filter.get(), &output)); 1184 output_block_size, filter.get(), &output));
1176 EXPECT_EQ(output, expanded_); 1185 EXPECT_EQ(output, expanded_);
1177 } 1186 }
1178 1187
1179 } // namespace net 1188 } // namespace net
OLDNEW
« net/filter/sdch_filter.cc ('K') | « net/filter/sdch_filter.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698