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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 std::string url_string = "http://" + kSampleDomain; | 388 std::string url_string = "http://" + kSampleDomain; |
389 GURL url(url_string); | 389 GURL url(url_string); |
390 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 390 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
391 | 391 |
392 // Check we can't add it twice. | 392 // Check we can't add it twice. |
393 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 393 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
394 | 394 |
395 const std::string kSampleDomain2 = "sdchtest2.com"; | 395 const std::string kSampleDomain2 = "sdchtest2.com"; |
396 | 396 |
397 // Construct a second SDCH dictionary from a VCDIFF dictionary. | 397 // Don't test adding a second dictionary if our limits are tight. |
398 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); | 398 if (SdchManager::kMaxDictionaryCount > 1) { |
| 399 // Construct a second SDCH dictionary from a VCDIFF dictionary. |
| 400 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); |
399 | 401 |
400 std::string url_string2 = "http://" + kSampleDomain2; | 402 std::string url_string2 = "http://" + kSampleDomain2; |
401 GURL url2(url_string2); | 403 GURL url2(url_string2); |
402 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2)); | 404 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2)); |
| 405 } |
403 } | 406 } |
404 | 407 |
405 TEST_F(SdchFilterTest, BasicDictionary) { | 408 TEST_F(SdchFilterTest, BasicDictionary) { |
406 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 409 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
407 const std::string kSampleDomain = "sdchtest.com"; | 410 const std::string kSampleDomain = "sdchtest.com"; |
408 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 411 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
409 | 412 |
410 std::string url_string = "http://" + kSampleDomain; | 413 std::string url_string = "http://" + kSampleDomain; |
411 | 414 |
412 GURL url(url_string); | 415 GURL url(url_string); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 filter.get(), &output)); | 630 filter.get(), &output)); |
628 EXPECT_EQ(output.size(), 0u); // No output written. | 631 EXPECT_EQ(output.size(), 0u); // No output written. |
629 | 632 |
630 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 633 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
631 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); | 634 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); |
632 sdch_manager_->ClearBlacklistings(); | 635 sdch_manager_->ClearBlacklistings(); |
633 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); | 636 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url)); |
634 } | 637 } |
635 | 638 |
636 TEST_F(SdchFilterTest, DictionaryPathValidation) { | 639 TEST_F(SdchFilterTest, DictionaryPathValidation) { |
| 640 // Can't test path distinction between dictionaries if we aren't allowed |
| 641 // more than one dictionary. |
| 642 if (SdchManager::kMaxDictionaryCount <= 1) |
| 643 return; |
| 644 |
637 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 645 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
638 const std::string kSampleDomain = "sdchtest.com"; | 646 const std::string kSampleDomain = "sdchtest.com"; |
639 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 647 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
640 | 648 |
641 std::string url_string = "http://" + kSampleDomain; | 649 std::string url_string = "http://" + kSampleDomain; |
642 | 650 |
643 GURL url(url_string); | 651 GURL url(url_string); |
644 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 652 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
645 | 653 |
646 // Create a dictionary with a path restriction, by prefixing dictionary. | 654 // Create a dictionary with a path restriction, by prefixing dictionary. |
(...skipping 29 matching lines...) Expand all Loading... |
676 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, | 684 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, |
677 output_block_size, filter.get(), &output)); | 685 output_block_size, filter.get(), &output)); |
678 EXPECT_EQ(output.size(), 0u); // No output written. | 686 EXPECT_EQ(output.size(), 0u); // No output written. |
679 | 687 |
680 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 688 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
681 sdch_manager_->ClearBlacklistings(); | 689 sdch_manager_->ClearBlacklistings(); |
682 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 690 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
683 } | 691 } |
684 | 692 |
685 TEST_F(SdchFilterTest, DictionaryPortValidation) { | 693 TEST_F(SdchFilterTest, DictionaryPortValidation) { |
| 694 // Can't test port distinction between dictionaries if we aren't allowed |
| 695 // more than one dictionary. |
| 696 if (SdchManager::kMaxDictionaryCount <= 1) |
| 697 return; |
| 698 |
686 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 699 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
687 const std::string kSampleDomain = "sdchtest.com"; | 700 const std::string kSampleDomain = "sdchtest.com"; |
688 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 701 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
689 | 702 |
690 std::string url_string = "http://" + kSampleDomain; | 703 std::string url_string = "http://" + kSampleDomain; |
691 | 704 |
692 GURL url(url_string); | 705 GURL url(url_string); |
693 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 706 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
694 | 707 |
695 | 708 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1133 |
1121 feed_block_size = 1; | 1134 feed_block_size = 1; |
1122 output_block_size = 1; | 1135 output_block_size = 1; |
1123 output.clear(); | 1136 output.clear(); |
1124 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1137 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
1125 output_block_size, filter.get(), &output)); | 1138 output_block_size, filter.get(), &output)); |
1126 EXPECT_EQ(output, expanded_); | 1139 EXPECT_EQ(output, expanded_); |
1127 } | 1140 } |
1128 | 1141 |
1129 } // namespace net | 1142 } // namespace net |
OLD | NEW |