| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 std::string last_server_hash_; | 93 std::string last_server_hash_; |
| 94 GURL last_dictionary_request_url_; | 94 GURL last_dictionary_request_url_; |
| 95 GURL last_dictionary_url_; | 95 GURL last_dictionary_url_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(MockSdchObserver); | 97 DISALLOW_COPY_AND_ASSIGN(MockSdchObserver); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class SdchManagerTest : public testing::Test { | 100 class SdchManagerTest : public testing::Test { |
| 101 protected: | 101 protected: |
| 102 SdchManagerTest() | 102 SdchManagerTest() |
| 103 : sdch_manager_(new SdchManager), | 103 : sdch_manager_(new SdchManager) {} |
| 104 default_support_(sdch_manager_->sdch_enabled()) { } | |
| 105 | 104 |
| 106 ~SdchManagerTest() override {} | 105 ~SdchManagerTest() override {} |
| 107 | 106 |
| 108 SdchManager* sdch_manager() { return sdch_manager_.get(); } | 107 SdchManager* sdch_manager() { return sdch_manager_.get(); } |
| 109 | 108 |
| 110 // Reset globals back to default state. | |
| 111 void TearDown() override { | |
| 112 SdchManager::EnableSdchSupport(default_support_); | |
| 113 } | |
| 114 | |
| 115 // Attempt to add a dictionary to the manager and probe for success or | 109 // Attempt to add a dictionary to the manager and probe for success or |
| 116 // failure. | 110 // failure. |
| 117 bool AddSdchDictionary(const std::string& dictionary_text, | 111 bool AddSdchDictionary(const std::string& dictionary_text, |
| 118 const GURL& gurl) { | 112 const GURL& gurl) { |
| 119 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl, nullptr) == | 113 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl, nullptr) == |
| 120 SDCH_OK; | 114 SDCH_OK; |
| 121 } | 115 } |
| 122 | 116 |
| 123 private: | 117 private: |
| 124 scoped_ptr<SdchManager> sdch_manager_; | 118 scoped_ptr<SdchManager> sdch_manager_; |
| 125 bool default_support_; | |
| 126 }; | 119 }; |
| 127 | 120 |
| 128 static std::string NewSdchDictionary(const std::string& domain) { | 121 static std::string NewSdchDictionary(const std::string& domain) { |
| 129 std::string dictionary; | 122 std::string dictionary; |
| 130 if (!domain.empty()) { | 123 if (!domain.empty()) { |
| 131 dictionary.append("Domain: "); | 124 dictionary.append("Domain: "); |
| 132 dictionary.append(domain); | 125 dictionary.append(domain); |
| 133 dictionary.append("\n"); | 126 dictionary.append("\n"); |
| 134 } | 127 } |
| 135 dictionary.append("\n"); | 128 dictionary.append("\n"); |
| 136 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 129 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 137 return dictionary; | 130 return dictionary; |
| 138 } | 131 } |
| 139 | 132 |
| 140 TEST_F(SdchManagerTest, DomainSupported) { | 133 TEST_F(SdchManagerTest, DomainSupported) { |
| 141 GURL google_url("http://www.google.com"); | 134 GURL google_url("http://www.google.com"); |
| 142 | 135 |
| 143 SdchManager::EnableSdchSupport(false); | |
| 144 EXPECT_EQ(SDCH_DISABLED, sdch_manager()->IsInSupportedDomain(google_url)); | |
| 145 SdchManager::EnableSdchSupport(true); | |
| 146 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url)); | 136 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url)); |
| 147 } | 137 } |
| 148 | 138 |
| 149 TEST_F(SdchManagerTest, DomainBlacklisting) { | 139 TEST_F(SdchManagerTest, DomainBlacklisting) { |
| 150 GURL test_url("http://www.test.com"); | 140 GURL test_url("http://www.test.com"); |
| 151 GURL google_url("http://www.google.com"); | 141 GURL google_url("http://www.google.com"); |
| 152 | 142 |
| 153 sdch_manager()->BlacklistDomain(test_url, SDCH_OK); | 143 sdch_manager()->BlacklistDomain(test_url, SDCH_OK); |
| 154 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, | 144 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 155 sdch_manager()->IsInSupportedDomain(test_url)); | 145 sdch_manager()->IsInSupportedDomain(test_url)); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash( | 579 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash( |
| 590 target_gurl, server_hash, &problem_code)); | 580 target_gurl, server_hash, &problem_code)); |
| 591 EXPECT_EQ(SDCH_OK, problem_code); | 581 EXPECT_EQ(SDCH_OK, problem_code); |
| 592 } | 582 } |
| 593 | 583 |
| 594 TEST_F(SdchManagerTest, SdchOnByDefault) { | 584 TEST_F(SdchManagerTest, SdchOnByDefault) { |
| 595 GURL google_url("http://www.google.com"); | 585 GURL google_url("http://www.google.com"); |
| 596 scoped_ptr<SdchManager> sdch_manager(new SdchManager); | 586 scoped_ptr<SdchManager> sdch_manager(new SdchManager); |
| 597 | 587 |
| 598 EXPECT_EQ(SDCH_OK, sdch_manager->IsInSupportedDomain(google_url)); | 588 EXPECT_EQ(SDCH_OK, sdch_manager->IsInSupportedDomain(google_url)); |
| 599 SdchManager::EnableSdchSupport(false); | |
| 600 EXPECT_EQ(SDCH_DISABLED, sdch_manager->IsInSupportedDomain(google_url)); | |
| 601 } | 589 } |
| 602 | 590 |
| 603 // Confirm dispatch of notification. | 591 // Confirm dispatch of notification. |
| 604 TEST_F(SdchManagerTest, SdchDictionaryUsed) { | 592 TEST_F(SdchManagerTest, SdchDictionaryUsed) { |
| 605 MockSdchObserver observer; | 593 MockSdchObserver observer; |
| 606 sdch_manager()->AddObserver(&observer); | 594 sdch_manager()->AddObserver(&observer); |
| 607 | 595 |
| 608 EXPECT_EQ(0, observer.dictionary_used_notifications()); | 596 EXPECT_EQ(0, observer.dictionary_used_notifications()); |
| 609 sdch_manager()->OnDictionaryUsed("xyzzy"); | 597 sdch_manager()->OnDictionaryUsed("xyzzy"); |
| 610 EXPECT_EQ(1, observer.dictionary_used_notifications()); | 598 EXPECT_EQ(1, observer.dictionary_used_notifications()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 EXPECT_EQ(server_hash, observer.last_server_hash()); | 632 EXPECT_EQ(server_hash, observer.last_server_hash()); |
| 645 | 633 |
| 646 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); | 634 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); |
| 647 EXPECT_EQ(1, observer.dictionary_removed_notifications()); | 635 EXPECT_EQ(1, observer.dictionary_removed_notifications()); |
| 648 EXPECT_EQ(server_hash, observer.last_server_hash()); | 636 EXPECT_EQ(server_hash, observer.last_server_hash()); |
| 649 | 637 |
| 650 sdch_manager()->RemoveObserver(&observer); | 638 sdch_manager()->RemoveObserver(&observer); |
| 651 } | 639 } |
| 652 | 640 |
| 653 } // namespace net | 641 } // namespace net |
| OLD | NEW |