| 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" |
| 11 #include "base/strings/stringprintf.h" |
| 11 #include "net/base/sdch_manager.h" | 12 #include "net/base/sdch_manager.h" |
| 12 #include "net/base/sdch_observer.h" | 13 #include "net/base/sdch_observer.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 //------------------------------------------------------------------------------ | 19 //------------------------------------------------------------------------------ |
| 19 // Provide sample data and compression results with a sample VCDIFF dictionary. | 20 // Provide sample data and compression results with a sample VCDIFF dictionary. |
| 20 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 21 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Reset globals back to default state. | 67 // Reset globals back to default state. |
| 67 void TearDown() override { | 68 void TearDown() override { |
| 68 SdchManager::EnableSdchSupport(default_support_); | 69 SdchManager::EnableSdchSupport(default_support_); |
| 69 SdchManager::EnableSecureSchemeSupport(default_https_support_); | 70 SdchManager::EnableSecureSchemeSupport(default_https_support_); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Attempt to add a dictionary to the manager and probe for success or | 73 // Attempt to add a dictionary to the manager and probe for success or |
| 73 // failure. | 74 // failure. |
| 74 bool AddSdchDictionary(const std::string& dictionary_text, | 75 bool AddSdchDictionary(const std::string& dictionary_text, |
| 75 const GURL& gurl) { | 76 const GURL& gurl) { |
| 76 std::string list; | 77 scoped_ptr<SdchManager::DictionarySet> set1( |
| 77 sdch_manager_->GetAvailDictionaryList(gurl, &list); | 78 sdch_manager_->GetDictionarySet(gurl)); |
| 79 std::string set1_hashes; |
| 80 if (set1) |
| 81 set1->GetDictionaryClientHashList(&set1_hashes); |
| 82 |
| 78 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); | 83 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); |
| 79 std::string list2; | 84 scoped_ptr<SdchManager::DictionarySet> set2( |
| 80 sdch_manager_->GetAvailDictionaryList(gurl, &list2); | 85 sdch_manager_->GetDictionarySet(gurl)); |
| 86 std::string set2_hashes; |
| 87 if (set2) |
| 88 set2->GetDictionaryClientHashList(&set2_hashes); |
| 81 | 89 |
| 82 // The list of hashes should change iff the addition succeeds. | 90 // The list of hashes should change iff the addition succeeds. |
| 83 return (list != list2); | 91 return (set1_hashes != set2_hashes); |
| 84 } | 92 } |
| 85 | 93 |
| 86 private: | 94 private: |
| 87 scoped_ptr<SdchManager> sdch_manager_; | 95 scoped_ptr<SdchManager> sdch_manager_; |
| 88 bool default_support_; | 96 bool default_support_; |
| 89 bool default_https_support_; | 97 bool default_https_support_; |
| 90 }; | 98 }; |
| 91 | 99 |
| 92 static std::string NewSdchDictionary(const std::string& domain) { | 100 static std::string NewSdchDictionary(const std::string& domain) { |
| 93 std::string dictionary; | 101 std::string dictionary; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 SdchManager::EnableSdchSupport(false); | 115 SdchManager::EnableSdchSupport(false); |
| 108 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 116 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); |
| 109 SdchManager::EnableSdchSupport(true); | 117 SdchManager::EnableSdchSupport(true); |
| 110 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 118 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); |
| 111 } | 119 } |
| 112 | 120 |
| 113 TEST_F(SdchManagerTest, DomainBlacklisting) { | 121 TEST_F(SdchManagerTest, DomainBlacklisting) { |
| 114 GURL test_url("http://www.test.com"); | 122 GURL test_url("http://www.test.com"); |
| 115 GURL google_url("http://www.google.com"); | 123 GURL google_url("http://www.google.com"); |
| 116 | 124 |
| 117 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 125 sdch_manager()->BlacklistDomain(test_url, SdchManager::OK); |
| 118 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); | 126 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); |
| 119 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 127 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); |
| 120 | 128 |
| 121 sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); | 129 sdch_manager()->BlacklistDomain(google_url, SdchManager::OK); |
| 122 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 130 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); |
| 123 } | 131 } |
| 124 | 132 |
| 125 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { | 133 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { |
| 126 GURL test_url("http://www.TesT.com"); | 134 GURL test_url("http://www.TesT.com"); |
| 127 GURL test2_url("http://www.tEst.com"); | 135 GURL test2_url("http://www.tEst.com"); |
| 128 | 136 |
| 129 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); | 137 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); |
| 130 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); | 138 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); |
| 131 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 139 sdch_manager()->BlacklistDomain(test_url, SdchManager::OK); |
| 132 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); | 140 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); |
| 133 } | 141 } |
| 134 | 142 |
| 135 TEST_F(SdchManagerTest, BlacklistingReset) { | 143 TEST_F(SdchManagerTest, BlacklistingReset) { |
| 136 GURL gurl("http://mytest.DoMain.com"); | 144 GURL gurl("http://mytest.DoMain.com"); |
| 137 std::string domain(gurl.host()); | 145 std::string domain(gurl.host()); |
| 138 | 146 |
| 139 sdch_manager()->ClearBlacklistings(); | 147 sdch_manager()->ClearBlacklistings(); |
| 140 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 148 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| 141 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); | 149 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); |
| 142 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 150 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); |
| 143 } | 151 } |
| 144 | 152 |
| 145 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { | 153 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { |
| 146 GURL gurl("http://mytest.DoMain.com"); | 154 GURL gurl("http://mytest.DoMain.com"); |
| 147 std::string domain(gurl.host()); | 155 std::string domain(gurl.host()); |
| 148 sdch_manager()->ClearBlacklistings(); | 156 sdch_manager()->ClearBlacklistings(); |
| 149 | 157 |
| 150 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 158 sdch_manager()->BlacklistDomain(gurl, SdchManager::OK); |
| 151 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); | 159 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); |
| 152 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); | 160 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); |
| 153 | 161 |
| 154 // Check that any domain lookup reduces the blacklist counter. | 162 // Check that any domain lookup reduces the blacklist counter. |
| 155 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 163 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); |
| 156 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 164 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| 157 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 165 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); |
| 158 } | 166 } |
| 159 | 167 |
| 160 TEST_F(SdchManagerTest, BlacklistingExponential) { | 168 TEST_F(SdchManagerTest, BlacklistingExponential) { |
| 161 GURL gurl("http://mytest.DoMain.com"); | 169 GURL gurl("http://mytest.DoMain.com"); |
| 162 std::string domain(gurl.host()); | 170 std::string domain(gurl.host()); |
| 163 sdch_manager()->ClearBlacklistings(); | 171 sdch_manager()->ClearBlacklistings(); |
| 164 | 172 |
| 165 int exponential = 1; | 173 int exponential = 1; |
| 166 for (int i = 1; i < 100; ++i) { | 174 for (int i = 1; i < 100; ++i) { |
| 167 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 175 sdch_manager()->BlacklistDomain(gurl, SdchManager::OK); |
| 168 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); | 176 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); |
| 169 | 177 |
| 170 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); | 178 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); |
| 171 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 179 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); |
| 172 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); | 180 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); |
| 173 | 181 |
| 174 // Simulate a large number of domain checks (which eventually remove the | 182 // Simulate a large number of domain checks (which eventually remove the |
| 175 // blacklisting). | 183 // blacklisting). |
| 176 sdch_manager()->ClearDomainBlacklisting(domain); | 184 sdch_manager()->ClearDomainBlacklisting(domain); |
| 177 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 185 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 193 GURL("http://" + dictionary_domain))); | 201 GURL("http://" + dictionary_domain))); |
| 194 } | 202 } |
| 195 | 203 |
| 196 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { | 204 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { |
| 197 std::string dictionary_domain("x.y.z.google.com"); | 205 std::string dictionary_domain("x.y.z.google.com"); |
| 198 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 206 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 199 | 207 |
| 200 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 208 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 201 GURL("http://" + dictionary_domain))); | 209 GURL("http://" + dictionary_domain))); |
| 202 | 210 |
| 203 std::string dictionary_list; | |
| 204 // HTTP target URL can advertise dictionary. | 211 // HTTP target URL can advertise dictionary. |
| 205 sdch_manager()->GetAvailDictionaryList( | 212 EXPECT_TRUE(sdch_manager()->GetDictionarySet( |
| 206 GURL("http://" + dictionary_domain + "/test"), | 213 GURL("http://" + dictionary_domain + "/test"))); |
| 207 &dictionary_list); | |
| 208 EXPECT_FALSE(dictionary_list.empty()); | |
| 209 } | 214 } |
| 210 | 215 |
| 211 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { | 216 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { |
| 212 std::string dictionary_domain("x.y.z.google.com"); | 217 std::string dictionary_domain("x.y.z.google.com"); |
| 213 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 218 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 214 | 219 |
| 215 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 220 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 216 GURL("http://" + dictionary_domain))); | 221 GURL("http://" + dictionary_domain))); |
| 217 | 222 |
| 218 std::string dictionary_list; | |
| 219 // HTTPS target URL should NOT advertise dictionary. | 223 // HTTPS target URL should NOT advertise dictionary. |
| 220 sdch_manager()->GetAvailDictionaryList( | 224 EXPECT_FALSE(sdch_manager()->GetDictionarySet( |
| 221 GURL("https://" + dictionary_domain + "/test"), | 225 GURL("https://" + dictionary_domain + "/test"))); |
| 222 &dictionary_list); | |
| 223 EXPECT_TRUE(dictionary_list.empty()); | |
| 224 } | 226 } |
| 225 | 227 |
| 226 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { | 228 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
| 227 std::string dictionary_domain("x.y.z.google.com"); | 229 std::string dictionary_domain("x.y.z.google.com"); |
| 228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 230 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 229 | 231 |
| 230 SdchManager::EnableSecureSchemeSupport(false); | 232 SdchManager::EnableSecureSchemeSupport(false); |
| 231 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 233 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
| 232 GURL("https://" + dictionary_domain))); | 234 GURL("https://" + dictionary_domain))); |
| 233 SdchManager::EnableSecureSchemeSupport(true); | 235 SdchManager::EnableSecureSchemeSupport(true); |
| 234 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 236 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 235 GURL("https://" + dictionary_domain))); | 237 GURL("https://" + dictionary_domain))); |
| 236 | 238 |
| 237 GURL target_url("https://" + dictionary_domain + "/test"); | 239 GURL target_url("https://" + dictionary_domain + "/test"); |
| 238 std::string dictionary_list; | |
| 239 // HTTPS target URL should advertise dictionary if secure scheme support is | 240 // HTTPS target URL should advertise dictionary if secure scheme support is |
| 240 // enabled. | 241 // enabled. |
| 241 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 242 EXPECT_TRUE(sdch_manager()->GetDictionarySet(target_url)); |
| 242 EXPECT_FALSE(dictionary_list.empty()); | |
| 243 | 243 |
| 244 // Dictionary should be available. | 244 // Dictionary should be available. |
| 245 scoped_refptr<SdchManager::Dictionary> dictionary; | |
| 246 std::string client_hash; | 245 std::string client_hash; |
| 247 std::string server_hash; | 246 std::string server_hash; |
| 248 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 247 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 249 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 248 scoped_ptr<SdchManager::DictionarySet> dict_set( |
| 250 EXPECT_TRUE(dictionary.get() != NULL); | 249 sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| 250 EXPECT_TRUE(dict_set.get()); |
| 251 EXPECT_TRUE(dict_set->Dictionary(server_hash)); |
| 251 } | 252 } |
| 252 | 253 |
| 253 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { | 254 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| 254 std::string dictionary_domain("x.y.z.google.com"); | 255 std::string dictionary_domain("x.y.z.google.com"); |
| 255 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 256 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 256 | 257 |
| 257 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 258 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 258 GURL("http://" + dictionary_domain))); | 259 GURL("http://" + dictionary_domain))); |
| 259 | 260 |
| 260 GURL target_url("https://" + dictionary_domain + "/test"); | 261 GURL target_url("https://" + dictionary_domain + "/test"); |
| 261 std::string dictionary_list; | |
| 262 // HTTPS target URL should not advertise dictionary acquired over HTTP even if | 262 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
| 263 // secure scheme support is enabled. | 263 // secure scheme support is enabled. |
| 264 SdchManager::EnableSecureSchemeSupport(true); | 264 SdchManager::EnableSecureSchemeSupport(true); |
| 265 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 265 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url)); |
| 266 EXPECT_TRUE(dictionary_list.empty()); | |
| 267 | 266 |
| 268 scoped_refptr<SdchManager::Dictionary> dictionary; | |
| 269 std::string client_hash; | 267 std::string client_hash; |
| 270 std::string server_hash; | 268 std::string server_hash; |
| 271 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 269 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 272 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 270 scoped_ptr<SdchManager::DictionarySet> dict_set( |
| 273 EXPECT_TRUE(dictionary.get() == NULL); | 271 sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| 272 EXPECT_FALSE(dict_set.get()); |
| 274 } | 273 } |
| 275 | 274 |
| 276 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { | 275 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
| 277 std::string dictionary_domain("x.y.z.google.com"); | 276 std::string dictionary_domain("x.y.z.google.com"); |
| 278 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 277 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 279 | 278 |
| 280 SdchManager::EnableSecureSchemeSupport(true); | 279 SdchManager::EnableSecureSchemeSupport(true); |
| 281 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 280 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 282 GURL("https://" + dictionary_domain))); | 281 GURL("https://" + dictionary_domain))); |
| 283 | 282 |
| 284 GURL target_url("http://" + dictionary_domain + "/test"); | 283 GURL target_url("http://" + dictionary_domain + "/test"); |
| 285 std::string dictionary_list; | |
| 286 // HTTP target URL should not advertise dictionary acquired over HTTPS even if | 284 // HTTP target URL should not advertise dictionary acquired over HTTPS even if |
| 287 // secure scheme support is enabled. | 285 // secure scheme support is enabled. |
| 288 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 286 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url)); |
| 289 EXPECT_TRUE(dictionary_list.empty()); | |
| 290 | 287 |
| 291 scoped_refptr<SdchManager::Dictionary> dictionary; | |
| 292 std::string client_hash; | 288 std::string client_hash; |
| 293 std::string server_hash; | 289 std::string server_hash; |
| 294 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 290 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 295 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 291 scoped_ptr<SdchManager::DictionarySet> dict_set( |
| 296 EXPECT_TRUE(dictionary.get() == NULL); | 292 sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| 293 EXPECT_FALSE(dict_set.get()); |
| 297 } | 294 } |
| 298 | 295 |
| 299 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { | 296 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
| 300 std::string dictionary_domain("x.y.z.google.com"); | 297 std::string dictionary_domain("x.y.z.google.com"); |
| 301 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 298 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 302 | 299 |
| 303 // Fail the "domain match" requirement. | 300 // Fail the "domain match" requirement. |
| 304 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 301 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
| 305 GURL("http://y.z.google.com"))); | 302 GURL("http://y.z.google.com"))); |
| 306 } | 303 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 std::string server_hash_1; | 505 std::string server_hash_1; |
| 509 std::string server_hash_2; | 506 std::string server_hash_2; |
| 510 | 507 |
| 511 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); | 508 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); |
| 512 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); | 509 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); |
| 513 | 510 |
| 514 // Confirm that if you add directories to one manager, you | 511 // Confirm that if you add directories to one manager, you |
| 515 // can't get them from the other. | 512 // can't get them from the other. |
| 516 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, | 513 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
| 517 GURL("http://" + dictionary_domain_1))); | 514 GURL("http://" + dictionary_domain_1))); |
| 518 scoped_refptr<SdchManager::Dictionary> dictionary; | 515 scoped_ptr<SdchManager::DictionarySet> dict_set; |
| 519 sdch_manager()->GetVcdiffDictionary( | 516 |
| 520 server_hash_1, | 517 dict_set = sdch_manager()->GetDictionarySetByHash( |
| 521 GURL("http://" + dictionary_domain_1 + "/random_url"), | 518 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 522 &dictionary); | 519 server_hash_1); |
| 523 EXPECT_TRUE(dictionary.get()); | 520 EXPECT_TRUE(dict_set.get()); |
| 521 EXPECT_TRUE(dict_set->Dictionary(server_hash_1)); |
| 524 | 522 |
| 525 second_manager.AddSdchDictionary( | 523 second_manager.AddSdchDictionary( |
| 526 dictionary_text_2, GURL("http://" + dictionary_domain_2)); | 524 dictionary_text_2, GURL("http://" + dictionary_domain_2)); |
| 527 second_manager.GetVcdiffDictionary( | 525 dict_set = second_manager.GetDictionarySetByHash( |
| 528 server_hash_2, | |
| 529 GURL("http://" + dictionary_domain_2 + "/random_url"), | 526 GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 530 &dictionary); | 527 server_hash_2); |
| 531 EXPECT_TRUE(dictionary.get()); | 528 EXPECT_TRUE(dict_set.get()); |
| 529 EXPECT_TRUE(dict_set->Dictionary(server_hash_2)); |
| 532 | 530 |
| 533 sdch_manager()->GetVcdiffDictionary( | 531 dict_set = sdch_manager()->GetDictionarySetByHash( |
| 534 server_hash_2, | |
| 535 GURL("http://" + dictionary_domain_2 + "/random_url"), | 532 GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 536 &dictionary); | 533 server_hash_2); |
| 537 EXPECT_FALSE(dictionary.get()); | 534 EXPECT_FALSE(dict_set.get()); |
| 538 | 535 |
| 539 second_manager.GetVcdiffDictionary( | 536 dict_set = second_manager.GetDictionarySetByHash( |
| 540 server_hash_1, | |
| 541 GURL("http://" + dictionary_domain_1 + "/random_url"), | 537 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 542 &dictionary); | 538 server_hash_1); |
| 543 EXPECT_FALSE(dictionary.get()); | 539 EXPECT_FALSE(dict_set.get()); |
| 544 } | 540 } |
| 545 | 541 |
| 546 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { | 542 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { |
| 547 GURL url("http://www.google.com"); | 543 GURL url("http://www.google.com"); |
| 548 GURL secure_url("https://www.google.com"); | 544 GURL secure_url("https://www.google.com"); |
| 549 | 545 |
| 550 bool expect_https_support = true; | 546 bool expect_https_support = true; |
| 551 | 547 |
| 552 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); | 548 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); |
| 553 EXPECT_EQ(expect_https_support, | 549 EXPECT_EQ(expect_https_support, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 564 GURL blacklist_url("http://bad.chromium.org"); | 560 GURL blacklist_url("http://bad.chromium.org"); |
| 565 | 561 |
| 566 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 562 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 567 std::string tmp_hash; | 563 std::string tmp_hash; |
| 568 std::string server_hash; | 564 std::string server_hash; |
| 569 | 565 |
| 570 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); | 566 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); |
| 571 | 567 |
| 572 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 568 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 573 GURL("http://" + dictionary_domain))); | 569 GURL("http://" + dictionary_domain))); |
| 574 scoped_refptr<SdchManager::Dictionary> dictionary; | 570 |
| 575 sdch_manager()->GetVcdiffDictionary( | 571 scoped_ptr<SdchManager::DictionarySet> dict_set; |
| 576 server_hash, | 572 |
| 573 dict_set = sdch_manager()->GetDictionarySetByHash( |
| 577 GURL("http://" + dictionary_domain + "/random_url"), | 574 GURL("http://" + dictionary_domain + "/random_url"), |
| 578 &dictionary); | 575 server_hash); |
| 579 EXPECT_TRUE(dictionary.get()); | 576 EXPECT_TRUE(dict_set.get()); |
| 577 EXPECT_TRUE(dict_set->Dictionary(server_hash)); |
| 580 | 578 |
| 581 sdch_manager()->BlacklistDomain(GURL(blacklist_url), | 579 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SdchManager::OK); |
| 582 SdchManager::MIN_PROBLEM_CODE); | |
| 583 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 580 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 584 | 581 |
| 585 sdch_manager()->ClearData(); | 582 sdch_manager()->ClearData(); |
| 586 | 583 |
| 587 dictionary = NULL; | 584 dict_set = sdch_manager()->GetDictionarySetByHash( |
| 588 sdch_manager()->GetVcdiffDictionary( | |
| 589 server_hash, | |
| 590 GURL("http://" + dictionary_domain + "/random_url"), | 585 GURL("http://" + dictionary_domain + "/random_url"), |
| 591 &dictionary); | 586 server_hash); |
| 592 EXPECT_FALSE(dictionary.get()); | 587 EXPECT_FALSE(dict_set.get()); |
| 593 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 588 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 594 } | 589 } |
| 595 | 590 |
| 596 TEST_F(SdchManagerTest, GetDictionaryNotification) { | 591 TEST_F(SdchManagerTest, GetDictionaryNotification) { |
| 597 GURL test_request_gurl(GURL("http://www.example.com/data")); | 592 GURL test_request_gurl(GURL("http://www.example.com/data")); |
| 598 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); | 593 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); |
| 599 MockSdchObserver observer; | 594 MockSdchObserver observer; |
| 600 sdch_manager()->AddObserver(&observer); | 595 sdch_manager()->AddObserver(&observer); |
| 601 | 596 |
| 602 EXPECT_EQ(0, observer.get_dictionary_notifications()); | 597 EXPECT_EQ(0, observer.get_dictionary_notifications()); |
| 603 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); | 598 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); |
| 604 EXPECT_EQ(1, observer.get_dictionary_notifications()); | 599 EXPECT_EQ(1, observer.get_dictionary_notifications()); |
| 605 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); | 600 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); |
| 606 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); | 601 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); |
| 607 | 602 |
| 608 sdch_manager()->RemoveObserver(&observer); | 603 sdch_manager()->RemoveObserver(&observer); |
| 609 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); | 604 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); |
| 610 EXPECT_EQ(1, observer.get_dictionary_notifications()); | 605 EXPECT_EQ(1, observer.get_dictionary_notifications()); |
| 611 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); | 606 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); |
| 612 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); | 607 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); |
| 613 } | 608 } |
| 614 | 609 |
| 610 TEST_F(SdchManagerTest, ExpirationCheckedProperly) { |
| 611 // Create an SDCH dictionary with an expiration time in the past. |
| 612 std::string dictionary_domain("x.y.z.google.com"); |
| 613 std::string dictionary_text(base::StringPrintf( |
| 614 "Domain: %s\nMax-age: 0\n\n", dictionary_domain.c_str())); |
| 615 dictionary_text.append( |
| 616 kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 617 std::string client_hash; |
| 618 std::string server_hash; |
| 619 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 620 GURL target_gurl("http://" + dictionary_domain); |
| 621 AddSdchDictionary(dictionary_text, target_gurl); |
| 622 |
| 623 // Make sure it's not visible for advertisement, but is visible |
| 624 // if looked up by hash. |
| 625 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_gurl)); |
| 626 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash(target_gurl, server_hash)); |
| 627 } |
| 628 |
| 615 } // namespace net | 629 } // namespace net |
| OLD | NEW |