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

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

Issue 6347033: net: Add namespace net to Sdch* classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
11 #if defined(USE_SYSTEM_ZLIB) 11 #if defined(USE_SYSTEM_ZLIB)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 //------------------------------------------------------------------------------ 51 //------------------------------------------------------------------------------
52 52
53 class SdchFilterTest : public testing::Test { 53 class SdchFilterTest : public testing::Test {
54 protected: 54 protected:
55 SdchFilterTest() 55 SdchFilterTest()
56 : test_vcdiff_dictionary_(kTestVcdiffDictionary, 56 : test_vcdiff_dictionary_(kTestVcdiffDictionary,
57 sizeof(kTestVcdiffDictionary) - 1), 57 sizeof(kTestVcdiffDictionary) - 1),
58 vcdiff_compressed_data_(kSdchCompressedTestData, 58 vcdiff_compressed_data_(kSdchCompressedTestData,
59 sizeof(kSdchCompressedTestData) - 1), 59 sizeof(kSdchCompressedTestData) - 1),
60 expanded_(kTestData, sizeof(kTestData) - 1), 60 expanded_(kTestData, sizeof(kTestData) - 1),
61 sdch_manager_(new SdchManager) { 61 sdch_manager_(new net::SdchManager) {
62 sdch_manager_->EnableSdchSupport(""); 62 sdch_manager_->EnableSdchSupport("");
63 } 63 }
64 64
65 std::string NewSdchCompressedData(const std::string dictionary); 65 std::string NewSdchCompressedData(const std::string dictionary);
66 66
67 const std::string test_vcdiff_dictionary_; 67 const std::string test_vcdiff_dictionary_;
68 const std::string vcdiff_compressed_data_; 68 const std::string vcdiff_compressed_data_;
69 const std::string expanded_; // Desired final, decompressed data. 69 const std::string expanded_; // Desired final, decompressed data.
70 70
71 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. 71 scoped_ptr<net::SdchManager> sdch_manager_; // A singleton database.
72 }; 72 };
73 73
74 std::string SdchFilterTest::NewSdchCompressedData( 74 std::string SdchFilterTest::NewSdchCompressedData(
75 const std::string dictionary) { 75 const std::string dictionary) {
76 std::string client_hash; 76 std::string client_hash;
77 std::string server_hash; 77 std::string server_hash;
78 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); 78 net::SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
79 79
80 // Build compressed data that refers to our dictionary. 80 // Build compressed data that refers to our dictionary.
81 std::string compressed(server_hash); 81 std::string compressed(server_hash);
82 compressed.append("\0", 1); 82 compressed.append("\0", 1);
83 compressed.append(vcdiff_compressed_data_); 83 compressed.append(vcdiff_compressed_data_);
84 return compressed; 84 return compressed;
85 } 85 }
86 86
87 //------------------------------------------------------------------------------ 87 //------------------------------------------------------------------------------
88 88
89 89
90 TEST_F(SdchFilterTest, Hashing) { 90 TEST_F(SdchFilterTest, Hashing) {
91 std::string client_hash, server_hash; 91 std::string client_hash, server_hash;
92 std::string dictionary("test contents"); 92 std::string dictionary("test contents");
93 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); 93 net::SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
94 94
95 EXPECT_EQ(client_hash, "lMQBjS3P"); 95 EXPECT_EQ(client_hash, "lMQBjS3P");
96 EXPECT_EQ(server_hash, "MyciMVll"); 96 EXPECT_EQ(server_hash, "MyciMVll");
97 } 97 }
98 98
99 99
100 //------------------------------------------------------------------------------ 100 //------------------------------------------------------------------------------
101 // Provide a generic helper function for trying to filter data. 101 // Provide a generic helper function for trying to filter data.
102 // This function repeatedly calls the filter to process data, until the entire 102 // This function repeatedly calls the filter to process data, until the entire
103 // source is consumed. The return value from the filter is appended to output. 103 // source is consumed. The return value from the filter is appended to output.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 dictionary_hash_postfix.size()); 381 dictionary_hash_postfix.size());
382 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); 382 filter->FlushStreamBuffer(dictionary_hash_postfix.size());
383 383
384 // With a non-existant dictionary specifier, try to read output. 384 // With a non-existant dictionary specifier, try to read output.
385 output_bytes_or_buffer_size = sizeof(output_buffer); 385 output_bytes_or_buffer_size = sizeof(output_buffer);
386 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); 386 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
387 387
388 EXPECT_EQ(0, output_bytes_or_buffer_size); 388 EXPECT_EQ(0, output_bytes_or_buffer_size);
389 EXPECT_EQ(Filter::FILTER_ERROR, status); 389 EXPECT_EQ(Filter::FILTER_ERROR, status);
390 390
391 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 391 EXPECT_FALSE(
392 SdchManager::ClearBlacklistings(); 392 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
393 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 393 net::SdchManager::ClearBlacklistings();
394 EXPECT_TRUE(
395 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
394 } 396 }
395 397
396 TEST_F(SdchFilterTest, DictionaryAddOnce) { 398 TEST_F(SdchFilterTest, DictionaryAddOnce) {
397 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 399 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
398 const std::string kSampleDomain = "sdchtest.com"; 400 const std::string kSampleDomain = "sdchtest.com";
399 std::string dictionary(NewSdchDictionary(kSampleDomain)); 401 std::string dictionary(NewSdchDictionary(kSampleDomain));
400 402
401 std::string url_string = "http://" + kSampleDomain; 403 std::string url_string = "http://" + kSampleDomain;
402 GURL url(url_string); 404 GURL url(url_string);
403 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 405 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 GURL url(url_string); 639 GURL url(url_string);
638 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 640 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
639 641
640 std::string compressed(NewSdchCompressedData(dictionary)); 642 std::string compressed(NewSdchCompressedData(dictionary));
641 643
642 std::vector<Filter::FilterType> filter_types; 644 std::vector<Filter::FilterType> filter_types;
643 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 645 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
644 const int kInputBufferSize(100); 646 const int kInputBufferSize(100);
645 647
646 // Decode with content arriving from the "wrong" domain. 648 // Decode with content arriving from the "wrong" domain.
647 // This tests SdchManager::CanSet(). 649 // This tests net::SdchManager::CanSet().
648 net::MockFilterContext filter_context(kInputBufferSize); 650 net::MockFilterContext filter_context(kInputBufferSize);
649 GURL wrong_domain_url("http://www.wrongdomain.com"); 651 GURL wrong_domain_url("http://www.wrongdomain.com");
650 filter_context.SetURL(wrong_domain_url); 652 filter_context.SetURL(wrong_domain_url);
651 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); 653 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context)));
652 654
653 size_t feed_block_size = 100; 655 size_t feed_block_size = 100;
654 size_t output_block_size = 100; 656 size_t output_block_size = 100;
655 std::string output; 657 std::string output;
656 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 658 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
657 filter.get(), &output)); 659 filter.get(), &output));
658 EXPECT_EQ(output.size(), 0u); // No output written. 660 EXPECT_EQ(output.size(), 0u); // No output written.
659 661
660 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 662 EXPECT_TRUE(
661 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); 663 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
662 SdchManager::ClearBlacklistings(); 664 EXPECT_FALSE(
663 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); 665 net::SdchManager::Global()->IsInSupportedDomain(wrong_domain_url));
666 net::SdchManager::ClearBlacklistings();
667 EXPECT_TRUE(
668 net::SdchManager::Global()->IsInSupportedDomain(wrong_domain_url));
664 } 669 }
665 670
666 TEST_F(SdchFilterTest, DictionaryPathValidation) { 671 TEST_F(SdchFilterTest, DictionaryPathValidation) {
667 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 672 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
668 const std::string kSampleDomain = "sdchtest.com"; 673 const std::string kSampleDomain = "sdchtest.com";
669 std::string dictionary(NewSdchDictionary(kSampleDomain)); 674 std::string dictionary(NewSdchDictionary(kSampleDomain));
670 675
671 std::string url_string = "http://" + kSampleDomain; 676 std::string url_string = "http://" + kSampleDomain;
672 677
673 GURL url(url_string); 678 GURL url(url_string);
(...skipping 28 matching lines...) Expand all
702 filter_context.SetURL(GURL(url_string)); 707 filter_context.SetURL(GURL(url_string));
703 filter.reset((Filter::Factory(filter_types, filter_context))); 708 filter.reset((Filter::Factory(filter_types, filter_context)));
704 709
705 feed_block_size = 100; 710 feed_block_size = 100;
706 output_block_size = 100; 711 output_block_size = 100;
707 output.clear(); 712 output.clear();
708 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 713 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
709 output_block_size, filter.get(), &output)); 714 output_block_size, filter.get(), &output));
710 EXPECT_EQ(output.size(), 0u); // No output written. 715 EXPECT_EQ(output.size(), 0u); // No output written.
711 716
712 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 717 EXPECT_FALSE(
713 SdchManager::ClearBlacklistings(); 718 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
714 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 719 net::SdchManager::ClearBlacklistings();
720 EXPECT_TRUE(
721 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
715 } 722 }
716 723
717 TEST_F(SdchFilterTest, DictionaryPortValidation) { 724 TEST_F(SdchFilterTest, DictionaryPortValidation) {
718 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 725 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
719 const std::string kSampleDomain = "sdchtest.com"; 726 const std::string kSampleDomain = "sdchtest.com";
720 std::string dictionary(NewSdchDictionary(kSampleDomain)); 727 std::string dictionary(NewSdchDictionary(kSampleDomain));
721 728
722 std::string url_string = "http://" + kSampleDomain; 729 std::string url_string = "http://" + kSampleDomain;
723 730
724 GURL url(url_string); 731 GURL url(url_string);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 filter_context.SetURL(GURL(url_string + ":" + port + "1")); 773 filter_context.SetURL(GURL(url_string + ":" + port + "1"));
767 filter.reset((Filter::Factory(filter_types, filter_context))); 774 filter.reset((Filter::Factory(filter_types, filter_context)));
768 775
769 feed_block_size = 100; 776 feed_block_size = 100;
770 output_block_size = 100; 777 output_block_size = 100;
771 output.clear(); 778 output.clear();
772 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 779 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
773 output_block_size, filter.get(), &output)); 780 output_block_size, filter.get(), &output));
774 EXPECT_EQ(output.size(), 0u); // No output written. 781 EXPECT_EQ(output.size(), 0u); // No output written.
775 782
776 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 783 EXPECT_FALSE(
777 SdchManager::ClearBlacklistings(); 784 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
778 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 785 net::SdchManager::ClearBlacklistings();
786 EXPECT_TRUE(
787 net::SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
779 } 788 }
780 789
781 //------------------------------------------------------------------------------ 790 //------------------------------------------------------------------------------
782 // Helper function to perform gzip compression of data. 791 // Helper function to perform gzip compression of data.
783 792
784 static std::string gzip_compress(const std::string &input) { 793 static std::string gzip_compress(const std::string &input) {
785 z_stream zlib_stream; 794 z_stream zlib_stream;
786 memset(&zlib_stream, 0, sizeof(zlib_stream)); 795 memset(&zlib_stream, 0, sizeof(zlib_stream));
787 int code; 796 int code;
788 797
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 output.clear(); 1159 output.clear();
1151 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1160 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1152 output_block_size, filter.get(), &output)); 1161 output_block_size, filter.get(), &output));
1153 EXPECT_EQ(output, expanded_); 1162 EXPECT_EQ(output, expanded_);
1154 } 1163 }
1155 1164
1156 TEST_F(SdchFilterTest, DomainSupported) { 1165 TEST_F(SdchFilterTest, DomainSupported) {
1157 GURL test_url("http://www.test.com"); 1166 GURL test_url("http://www.test.com");
1158 GURL google_url("http://www.google.com"); 1167 GURL google_url("http://www.google.com");
1159 1168
1160 EXPECT_TRUE(SdchManager::sdch_enabled()); 1169 EXPECT_TRUE(net::SdchManager::sdch_enabled());
1161 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test_url)); 1170 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(test_url));
1162 sdch_manager_->EnableSdchSupport(".google.com"); 1171 sdch_manager_->EnableSdchSupport(".google.com");
1163 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); 1172 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(test_url));
1164 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); 1173 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(google_url));
1165 } 1174 }
1166 1175
1167 TEST_F(SdchFilterTest, DomainBlacklisting) { 1176 TEST_F(SdchFilterTest, DomainBlacklisting) {
1168 GURL test_url("http://www.test.com"); 1177 GURL test_url("http://www.test.com");
1169 GURL google_url("http://www.google.com"); 1178 GURL google_url("http://www.google.com");
1170 1179
1171 SdchManager::BlacklistDomain(test_url); 1180 net::SdchManager::BlacklistDomain(test_url);
1172 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); 1181 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(test_url));
1173 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); 1182 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(google_url));
1174 1183
1175 SdchManager::BlacklistDomain(google_url); 1184 net::SdchManager::BlacklistDomain(google_url);
1176 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); 1185 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(google_url));
1177 } 1186 }
1178 1187
1179 TEST_F(SdchFilterTest, DomainBlacklistingCaseSensitivity) { 1188 TEST_F(SdchFilterTest, DomainBlacklistingCaseSensitivity) {
1180 GURL test_url("http://www.TesT.com"); 1189 GURL test_url("http://www.TesT.com");
1181 GURL test2_url("http://www.tEst.com"); 1190 GURL test2_url("http://www.tEst.com");
1182 1191
1183 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test_url)); 1192 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(test_url));
1184 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test2_url)); 1193 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(test2_url));
1185 SdchManager::BlacklistDomain(test_url); 1194 net::SdchManager::BlacklistDomain(test_url);
1186 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test2_url)); 1195 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(test2_url));
1187 } 1196 }
1188 1197
1189 TEST_F(SdchFilterTest, BlacklistingReset) { 1198 TEST_F(SdchFilterTest, BlacklistingReset) {
1190 GURL gurl("http://mytest.DoMain.com"); 1199 GURL gurl("http://mytest.DoMain.com");
1191 std::string domain(gurl.host()); 1200 std::string domain(gurl.host());
1192 1201
1193 SdchManager::ClearBlacklistings(); 1202 net::SdchManager::ClearBlacklistings();
1194 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 1203 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), 0);
1195 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 0); 1204 EXPECT_EQ(net::SdchManager::BlacklistDomainExponential(domain), 0);
1196 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 1205 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(gurl));
1197 } 1206 }
1198 1207
1199 TEST_F(SdchFilterTest, BlacklistingSingleBlacklist) { 1208 TEST_F(SdchFilterTest, BlacklistingSingleBlacklist) {
1200 GURL gurl("http://mytest.DoMain.com"); 1209 GURL gurl("http://mytest.DoMain.com");
1201 std::string domain(gurl.host()); 1210 std::string domain(gurl.host());
1202 SdchManager::ClearBlacklistings(); 1211 net::SdchManager::ClearBlacklistings();
1203 1212
1204 SdchManager::Global()->BlacklistDomain(gurl); 1213 net::SdchManager::Global()->BlacklistDomain(gurl);
1205 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 1); 1214 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), 1);
1206 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 1); 1215 EXPECT_EQ(net::SdchManager::BlacklistDomainExponential(domain), 1);
1207 1216
1208 // Check that any domain lookup reduces the blacklist counter. 1217 // Check that any domain lookup reduces the blacklist counter.
1209 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); 1218 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(gurl));
1210 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 1219 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), 0);
1211 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 1220 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(gurl));
1212 } 1221 }
1213 1222
1214 TEST_F(SdchFilterTest, BlacklistingExponential) { 1223 TEST_F(SdchFilterTest, BlacklistingExponential) {
1215 GURL gurl("http://mytest.DoMain.com"); 1224 GURL gurl("http://mytest.DoMain.com");
1216 std::string domain(gurl.host()); 1225 std::string domain(gurl.host());
1217 SdchManager::ClearBlacklistings(); 1226 net::SdchManager::ClearBlacklistings();
1218 1227
1219 int exponential = 1; 1228 int exponential = 1;
1220 for (int i = 1; i < 100; ++i) { 1229 for (int i = 1; i < 100; ++i) {
1221 SdchManager::Global()->BlacklistDomain(gurl); 1230 net::SdchManager::Global()->BlacklistDomain(gurl);
1222 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), exponential); 1231 EXPECT_EQ(
1232 net::SdchManager::BlacklistDomainExponential(domain), exponential);
1223 1233
1224 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential); 1234 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), exponential);
1225 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); 1235 EXPECT_FALSE(net::SdchManager::Global()->IsInSupportedDomain(gurl));
1226 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential - 1); 1236 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), exponential - 1);
1227 1237
1228 // Simulate a large number of domain checks (which eventually remove the 1238 // Simulate a large number of domain checks (which eventually remove the
1229 // blacklisting). 1239 // blacklisting).
1230 SdchManager::ClearDomainBlacklisting(domain); 1240 net::SdchManager::ClearDomainBlacklisting(domain);
1231 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 1241 EXPECT_EQ(net::SdchManager::BlackListDomainCount(domain), 0);
1232 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 1242 EXPECT_TRUE(net::SdchManager::Global()->IsInSupportedDomain(gurl));
1233 1243
1234 // Predict what exponential backoff will be. 1244 // Predict what exponential backoff will be.
1235 exponential = 1 + 2 * exponential; 1245 exponential = 1 + 2 * exponential;
1236 if (exponential < 0) 1246 if (exponential < 0)
1237 exponential = INT_MAX; // We don't wrap. 1247 exponential = INT_MAX; // We don't wrap.
1238 } 1248 }
1239 } 1249 }
1240 1250
1241 TEST_F(SdchFilterTest, CanSetExactMatchDictionary) { 1251 TEST_F(SdchFilterTest, CanSetExactMatchDictionary) {
1242 std::string dictionary_domain("x.y.z.google.com"); 1252 std::string dictionary_domain("x.y.z.google.com");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 1308 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text,
1299 GURL("http://" + dictionary_domain))); 1309 GURL("http://" + dictionary_domain)));
1300 } 1310 }
1301 1311
1302 // Make sure the DOS protection precludes the addition of too many dictionaries. 1312 // Make sure the DOS protection precludes the addition of too many dictionaries.
1303 TEST_F(SdchFilterTest, TooManyDictionaries) { 1313 TEST_F(SdchFilterTest, TooManyDictionaries) {
1304 std::string dictionary_domain(".google.com"); 1314 std::string dictionary_domain(".google.com");
1305 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 1315 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
1306 1316
1307 size_t count = 0; 1317 size_t count = 0;
1308 while (count <= SdchManager::kMaxDictionaryCount + 1) { 1318 while (count <= net::SdchManager::kMaxDictionaryCount + 1) {
1309 if (!sdch_manager_->AddSdchDictionary(dictionary_text, 1319 if (!sdch_manager_->AddSdchDictionary(dictionary_text,
1310 GURL("http://www.google.com"))) 1320 GURL("http://www.google.com")))
1311 break; 1321 break;
1312 1322
1313 dictionary_text += " "; // Create dictionary with different SHA signature. 1323 dictionary_text += " "; // Create dictionary with different SHA signature.
1314 ++count; 1324 ++count;
1315 } 1325 }
1316 EXPECT_EQ(SdchManager::kMaxDictionaryCount, count); 1326 EXPECT_EQ(net::SdchManager::kMaxDictionaryCount, count);
1317 } 1327 }
1318 1328
1319 TEST_F(SdchFilterTest, DictionaryNotTooLarge) { 1329 TEST_F(SdchFilterTest, DictionaryNotTooLarge) {
1320 std::string dictionary_domain(".google.com"); 1330 std::string dictionary_domain(".google.com");
1321 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 1331 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
1322 1332
1323 dictionary_text.append( 1333 dictionary_text.append(
1324 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); 1334 net::SdchManager::kMaxDictionarySize - dictionary_text.size(), ' ');
1325 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 1335 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text,
1326 GURL("http://" + dictionary_domain))); 1336 GURL("http://" + dictionary_domain)));
1327 } 1337 }
1328 1338
1329 TEST_F(SdchFilterTest, DictionaryTooLarge) { 1339 TEST_F(SdchFilterTest, DictionaryTooLarge) {
1330 std::string dictionary_domain(".google.com"); 1340 std::string dictionary_domain(".google.com");
1331 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 1341 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
1332 1342
1333 dictionary_text.append( 1343 dictionary_text.append(
1334 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); 1344 net::SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' ');
1335 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, 1345 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text,
1336 GURL("http://" + dictionary_domain))); 1346 GURL("http://" + dictionary_domain)));
1337 } 1347 }
1338 1348
1339 TEST_F(SdchFilterTest, PathMatch) { 1349 TEST_F(SdchFilterTest, PathMatch) {
1340 bool (*PathMatch)(const std::string& path, const std::string& restriction) = 1350 bool (*PathMatch)(const std::string& path, const std::string& restriction) =
1341 SdchManager::Dictionary::PathMatch; 1351 net::SdchManager::Dictionary::PathMatch;
tfarina 2011/01/31 02:23:00 Guys, any glue how to fix this? See trybot errors
1342 // Perfect match is supported. 1352 // Perfect match is supported.
1343 EXPECT_TRUE(PathMatch("/search", "/search")); 1353 EXPECT_TRUE(PathMatch("/search", "/search"));
1344 EXPECT_TRUE(PathMatch("/search/", "/search/")); 1354 EXPECT_TRUE(PathMatch("/search/", "/search/"));
1345 1355
1346 // Prefix only works if last character of restriction is a slash, or first 1356 // Prefix only works if last character of restriction is a slash, or first
1347 // character in path after a match is a slash. Validate each case separately. 1357 // character in path after a match is a slash. Validate each case separately.
1348 1358
1349 // Rely on the slash in the path (not at the end of the restriction). 1359 // Rely on the slash in the path (not at the end of the restriction).
1350 EXPECT_TRUE(PathMatch("/search/something", "/search")); 1360 EXPECT_TRUE(PathMatch("/search/something", "/search"));
1351 EXPECT_TRUE(PathMatch("/search/s", "/search")); 1361 EXPECT_TRUE(PathMatch("/search/s", "/search"));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 1407
1398 // And can reset them to false. 1408 // And can reset them to false.
1399 sdch_manager_->SetAllowLatencyExperiment(url, false); 1409 sdch_manager_->SetAllowLatencyExperiment(url, false);
1400 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 1410 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
1401 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); 1411 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2));
1402 1412
1403 sdch_manager_->SetAllowLatencyExperiment(url2, false); 1413 sdch_manager_->SetAllowLatencyExperiment(url2, false);
1404 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 1414 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
1405 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 1415 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2));
1406 } 1416 }
OLDNEW
« no previous file with comments | « net/base/sdch_filter.cc ('k') | net/base/sdch_manager.h » ('j') | net/base/sdch_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698