| 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 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 dictionary.append("\n"); | 41 dictionary.append("\n"); |
| 42 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 42 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 43 return dictionary; | 43 return dictionary; |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST_F(SdchManagerTest, DomainSupported) { | 46 TEST_F(SdchManagerTest, DomainSupported) { |
| 47 GURL google_url("http://www.google.com"); | 47 GURL google_url("http://www.google.com"); |
| 48 | 48 |
| 49 net::SdchManager::EnableSdchSupport(false); | 49 net::SdchManager::EnableSdchSupport(false); |
| 50 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 50 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(google_url)); |
| 51 net::SdchManager::EnableSdchSupport(true); | 51 net::SdchManager::EnableSdchSupport(true); |
| 52 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 52 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(google_url)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST_F(SdchManagerTest, DomainBlacklisting) { | 55 TEST_F(SdchManagerTest, DomainBlacklisting) { |
| 56 GURL test_url("http://www.test.com"); | 56 GURL test_url("http://www.test.com"); |
| 57 GURL google_url("http://www.google.com"); | 57 GURL google_url("http://www.google.com"); |
| 58 | 58 |
| 59 SdchManager::BlacklistDomain(test_url); | 59 sdch_manager_->BlacklistDomain(test_url); |
| 60 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); | 60 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(test_url)); |
| 61 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 61 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(google_url)); |
| 62 | 62 |
| 63 SdchManager::BlacklistDomain(google_url); | 63 sdch_manager_->BlacklistDomain(google_url); |
| 64 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 64 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(google_url)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { | 67 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { |
| 68 GURL test_url("http://www.TesT.com"); | 68 GURL test_url("http://www.TesT.com"); |
| 69 GURL test2_url("http://www.tEst.com"); | 69 GURL test2_url("http://www.tEst.com"); |
| 70 | 70 |
| 71 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test_url)); | 71 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(test_url)); |
| 72 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test2_url)); | 72 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(test2_url)); |
| 73 SdchManager::BlacklistDomain(test_url); | 73 sdch_manager_->BlacklistDomain(test_url); |
| 74 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test2_url)); | 74 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(test2_url)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(SdchManagerTest, BlacklistingReset) { | 77 TEST_F(SdchManagerTest, BlacklistingReset) { |
| 78 GURL gurl("http://mytest.DoMain.com"); | 78 GURL gurl("http://mytest.DoMain.com"); |
| 79 std::string domain(gurl.host()); | 79 std::string domain(gurl.host()); |
| 80 | 80 |
| 81 SdchManager::ClearBlacklistings(); | 81 sdch_manager_->ClearBlacklistings(); |
| 82 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); | 82 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), 0); |
| 83 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 0); | 83 EXPECT_EQ(sdch_manager_->BlacklistDomainExponential(domain), 0); |
| 84 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); | 84 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(gurl)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { | 87 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { |
| 88 GURL gurl("http://mytest.DoMain.com"); | 88 GURL gurl("http://mytest.DoMain.com"); |
| 89 std::string domain(gurl.host()); | 89 std::string domain(gurl.host()); |
| 90 SdchManager::ClearBlacklistings(); | 90 sdch_manager_->ClearBlacklistings(); |
| 91 | 91 |
| 92 SdchManager::Global()->BlacklistDomain(gurl); | 92 sdch_manager_->BlacklistDomain(gurl); |
| 93 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 1); | 93 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), 1); |
| 94 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 1); | 94 EXPECT_EQ(sdch_manager_->BlacklistDomainExponential(domain), 1); |
| 95 | 95 |
| 96 // Check that any domain lookup reduces the blacklist counter. | 96 // Check that any domain lookup reduces the blacklist counter. |
| 97 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); | 97 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(gurl)); |
| 98 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); | 98 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), 0); |
| 99 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); | 99 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(gurl)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(SdchManagerTest, BlacklistingExponential) { | 102 TEST_F(SdchManagerTest, BlacklistingExponential) { |
| 103 GURL gurl("http://mytest.DoMain.com"); | 103 GURL gurl("http://mytest.DoMain.com"); |
| 104 std::string domain(gurl.host()); | 104 std::string domain(gurl.host()); |
| 105 SdchManager::ClearBlacklistings(); | 105 sdch_manager_->ClearBlacklistings(); |
| 106 | 106 |
| 107 int exponential = 1; | 107 int exponential = 1; |
| 108 for (int i = 1; i < 100; ++i) { | 108 for (int i = 1; i < 100; ++i) { |
| 109 SdchManager::Global()->BlacklistDomain(gurl); | 109 sdch_manager_->BlacklistDomain(gurl); |
| 110 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), exponential); | 110 EXPECT_EQ(sdch_manager_->BlacklistDomainExponential(domain), exponential); |
| 111 | 111 |
| 112 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential); | 112 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), exponential); |
| 113 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); | 113 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(gurl)); |
| 114 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential - 1); | 114 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), exponential - 1); |
| 115 | 115 |
| 116 // Simulate a large number of domain checks (which eventually remove the | 116 // Simulate a large number of domain checks (which eventually remove the |
| 117 // blacklisting). | 117 // blacklisting). |
| 118 SdchManager::ClearDomainBlacklisting(domain); | 118 sdch_manager_->ClearDomainBlacklisting(domain); |
| 119 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); | 119 EXPECT_EQ(sdch_manager_->BlackListDomainCount(domain), 0); |
| 120 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); | 120 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(gurl)); |
| 121 | 121 |
| 122 // Predict what exponential backoff will be. | 122 // Predict what exponential backoff will be. |
| 123 exponential = 1 + 2 * exponential; | 123 exponential = 1 + 2 * exponential; |
| 124 if (exponential < 0) | 124 if (exponential < 0) |
| 125 exponential = INT_MAX; // We don't wrap. | 125 exponential = INT_MAX; // We don't wrap. |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { | 129 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { |
| 130 std::string dictionary_domain("x.y.z.google.com"); | 130 std::string dictionary_domain("x.y.z.google.com"); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 365 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 366 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); | 366 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 367 | 367 |
| 368 sdch_manager_->SetAllowLatencyExperiment(url2, false); | 368 sdch_manager_->SetAllowLatencyExperiment(url2, false); |
| 369 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 369 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 370 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); | 370 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 } // namespace net | 373 } // namespace net |
| 374 | 374 |
| OLD | NEW |