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

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