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

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

Issue 704493002: Revert "Sdch view for net-internals" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/filter/sdch_filter.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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 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 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl) == SDCH_OK; 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);
71 } 78 }
72 79
73 MockFilterContext* filter_context() { return filter_context_.get(); } 80 MockFilterContext* filter_context() { return filter_context_.get(); }
74 81
75 std::string NewSdchCompressedData(const std::string dictionary) { 82 std::string NewSdchCompressedData(const std::string dictionary) {
76 std::string client_hash; 83 std::string client_hash;
77 std::string server_hash; 84 std::string server_hash;
78 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); 85 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
79 86
80 // Build compressed data that refers to our dictionary. 87 // Build compressed data that refers to our dictionary.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 dictionary_hash_postfix.size()); 405 dictionary_hash_postfix.size());
399 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); 406 filter->FlushStreamBuffer(dictionary_hash_postfix.size());
400 407
401 // With a non-existant dictionary specifier, try to read output. 408 // With a non-existant dictionary specifier, try to read output.
402 output_bytes_or_buffer_size = sizeof(output_buffer); 409 output_bytes_or_buffer_size = sizeof(output_buffer);
403 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); 410 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
404 411
405 EXPECT_EQ(0, output_bytes_or_buffer_size); 412 EXPECT_EQ(0, output_bytes_or_buffer_size);
406 EXPECT_EQ(Filter::FILTER_ERROR, status); 413 EXPECT_EQ(Filter::FILTER_ERROR, status);
407 414
408 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, 415 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
409 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
410 sdch_manager_->ClearBlacklistings(); 416 sdch_manager_->ClearBlacklistings();
411 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); 417 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
412 } 418 }
413 419
414 TEST_F(SdchFilterTest, DictionaryAddOnce) { 420 TEST_F(SdchFilterTest, DictionaryAddOnce) {
415 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 421 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
416 const std::string kSampleDomain = "sdchtest.com"; 422 const std::string kSampleDomain = "sdchtest.com";
417 std::string dictionary(NewSdchDictionary(kSampleDomain)); 423 std::string dictionary(NewSdchDictionary(kSampleDomain));
418 424
419 std::string url_string = "http://" + kSampleDomain; 425 std::string url_string = "http://" + kSampleDomain;
420 GURL url(url_string); 426 GURL url(url_string);
421 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); 427 EXPECT_TRUE(AddSdchDictionary(dictionary, url));
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 filter_context()->SetURL(wrong_domain_url); 660 filter_context()->SetURL(wrong_domain_url);
655 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); 661 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
656 662
657 size_t feed_block_size = 100; 663 size_t feed_block_size = 100;
658 size_t output_block_size = 100; 664 size_t output_block_size = 100;
659 std::string output; 665 std::string output;
660 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 666 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
661 filter.get(), &output)); 667 filter.get(), &output));
662 EXPECT_EQ(output.size(), 0u); // No output written. 668 EXPECT_EQ(output.size(), 0u); // No output written.
663 669
664 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); 670 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
665 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, 671 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url));
666 sdch_manager_->IsInSupportedDomain(wrong_domain_url));
667 sdch_manager_->ClearBlacklistings(); 672 sdch_manager_->ClearBlacklistings();
668 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(wrong_domain_url)); 673 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url));
669 } 674 }
670 675
671 TEST_F(SdchFilterTest, DictionaryPathValidation) { 676 TEST_F(SdchFilterTest, DictionaryPathValidation) {
672 // Can't test path distinction between dictionaries if we aren't allowed 677 // Can't test path distinction between dictionaries if we aren't allowed
673 // more than one dictionary. 678 // more than one dictionary.
674 if (SdchManager::kMaxDictionaryCount <= 1) 679 if (SdchManager::kMaxDictionaryCount <= 1)
675 return; 680 return;
676 681
677 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 682 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
678 const std::string kSampleDomain = "sdchtest.com"; 683 const std::string kSampleDomain = "sdchtest.com";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 filter_context()->SetURL(GURL(url_string)); 716 filter_context()->SetURL(GURL(url_string));
712 filter.reset(Filter::Factory(filter_types, *filter_context())); 717 filter.reset(Filter::Factory(filter_types, *filter_context()));
713 718
714 feed_block_size = 100; 719 feed_block_size = 100;
715 output_block_size = 100; 720 output_block_size = 100;
716 output.clear(); 721 output.clear();
717 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 722 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
718 output_block_size, filter.get(), &output)); 723 output_block_size, filter.get(), &output));
719 EXPECT_EQ(output.size(), 0u); // No output written. 724 EXPECT_EQ(output.size(), 0u); // No output written.
720 725
721 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, 726 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
722 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
723 sdch_manager_->ClearBlacklistings(); 727 sdch_manager_->ClearBlacklistings();
724 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); 728 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
725 } 729 }
726 730
727 TEST_F(SdchFilterTest, DictionaryPortValidation) { 731 TEST_F(SdchFilterTest, DictionaryPortValidation) {
728 // Can't test port distinction between dictionaries if we aren't allowed 732 // Can't test port distinction between dictionaries if we aren't allowed
729 // more than one dictionary. 733 // more than one dictionary.
730 if (SdchManager::kMaxDictionaryCount <= 1) 734 if (SdchManager::kMaxDictionaryCount <= 1)
731 return; 735 return;
732 736
733 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 737 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
734 const std::string kSampleDomain = "sdchtest.com"; 738 const std::string kSampleDomain = "sdchtest.com";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 filter_context()->SetURL(GURL(url_string + ":" + port + "1")); 782 filter_context()->SetURL(GURL(url_string + ":" + port + "1"));
779 filter.reset(Filter::Factory(filter_types, *filter_context())); 783 filter.reset(Filter::Factory(filter_types, *filter_context()));
780 784
781 feed_block_size = 100; 785 feed_block_size = 100;
782 output_block_size = 100; 786 output_block_size = 100;
783 output.clear(); 787 output.clear();
784 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 788 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
785 output_block_size, filter.get(), &output)); 789 output_block_size, filter.get(), &output));
786 EXPECT_EQ(output.size(), 0u); // No output written. 790 EXPECT_EQ(output.size(), 0u); // No output written.
787 791
788 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, 792 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
789 sdch_manager_->IsInSupportedDomain(GURL(url_string)));
790 sdch_manager_->ClearBlacklistings(); 793 sdch_manager_->ClearBlacklistings();
791 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); 794 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
792 } 795 }
793 796
794 //------------------------------------------------------------------------------ 797 //------------------------------------------------------------------------------
795 // Helper function to perform gzip compression of data. 798 // Helper function to perform gzip compression of data.
796 799
797 static std::string gzip_compress(const std::string &input) { 800 static std::string gzip_compress(const std::string &input) {
798 z_stream zlib_stream; 801 z_stream zlib_stream;
799 memset(&zlib_stream, 0, sizeof(zlib_stream)); 802 memset(&zlib_stream, 0, sizeof(zlib_stream));
800 int code; 803 int code;
801 804
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 1170
1168 feed_block_size = 1; 1171 feed_block_size = 1;
1169 output_block_size = 1; 1172 output_block_size = 1;
1170 output.clear(); 1173 output.clear();
1171 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1174 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1172 output_block_size, filter.get(), &output)); 1175 output_block_size, filter.get(), &output));
1173 EXPECT_EQ(output, expanded_); 1176 EXPECT_EQ(output, expanded_);
1174 } 1177 }
1175 1178
1176 } // namespace net 1179 } // namespace net
OLDNEW
« no previous file with comments | « net/filter/sdch_filter.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698