| 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 "net/base/sdch_manager.h" | 11 #include "net/base/sdch_manager.h" |
| 12 #include "net/base/sdch_observer.h" | 12 #include "net/base/sdch_observer.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 //------------------------------------------------------------------------------ | 18 //------------------------------------------------------------------------------ |
| 19 // Provide sample data and compression results with a sample VCDIFF dictionary. | 19 // Provide sample data and compression results with a sample VCDIFF dictionary. |
| 20 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 20 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
| 21 static const char kTestVcdiffDictionary[] = "DictionaryFor" | 21 static const char kTestVcdiffDictionary[] = |
| 22 "DictionaryFor" |
| 22 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; | 23 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; |
| 23 | 24 |
| 24 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
| 25 | 26 |
| 26 class MockSdchObserver : public SdchObserver { | 27 class MockSdchObserver : public SdchObserver { |
| 27 public: | 28 public: |
| 28 MockSdchObserver() : get_dictionary_notifications_(0) {} | 29 MockSdchObserver() : get_dictionary_notifications_(0) {} |
| 29 | 30 |
| 30 const GURL& last_dictionary_request_url() { | 31 const GURL& last_dictionary_request_url() { |
| 31 return last_dictionary_request_url_; | 32 return last_dictionary_request_url_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 SdchManager* sdch_manager() { return sdch_manager_.get(); } | 65 SdchManager* sdch_manager() { return sdch_manager_.get(); } |
| 65 | 66 |
| 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, const GURL& gurl) { |
| 75 const GURL& gurl) { | |
| 76 std::string list; | 76 std::string list; |
| 77 sdch_manager_->GetAvailDictionaryList(gurl, &list); | 77 sdch_manager_->GetAvailDictionaryList(gurl, &list); |
| 78 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); | 78 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); |
| 79 std::string list2; | 79 std::string list2; |
| 80 sdch_manager_->GetAvailDictionaryList(gurl, &list2); | 80 sdch_manager_->GetAvailDictionaryList(gurl, &list2); |
| 81 | 81 |
| 82 // The list of hashes should change iff the addition succeeds. | 82 // The list of hashes should change iff the addition succeeds. |
| 83 return (list != list2); | 83 return (list != list2); |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (exponential < 0) | 182 if (exponential < 0) |
| 183 exponential = INT_MAX; // We don't wrap. | 183 exponential = INT_MAX; // We don't wrap. |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { | 187 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { |
| 188 std::string dictionary_domain("x.y.z.google.com"); | 188 std::string dictionary_domain("x.y.z.google.com"); |
| 189 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 189 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 190 | 190 |
| 191 // Perfect match should work. | 191 // Perfect match should work. |
| 192 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 192 EXPECT_TRUE( |
| 193 GURL("http://" + dictionary_domain))); | 193 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { | 196 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { |
| 197 std::string dictionary_domain("x.y.z.google.com"); | 197 std::string dictionary_domain("x.y.z.google.com"); |
| 198 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 198 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 199 | 199 |
| 200 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 200 EXPECT_TRUE( |
| 201 GURL("http://" + dictionary_domain))); | 201 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 202 | 202 |
| 203 std::string dictionary_list; | 203 std::string dictionary_list; |
| 204 // HTTP target URL can advertise dictionary. | 204 // HTTP target URL can advertise dictionary. |
| 205 sdch_manager()->GetAvailDictionaryList( | 205 sdch_manager()->GetAvailDictionaryList( |
| 206 GURL("http://" + dictionary_domain + "/test"), | 206 GURL("http://" + dictionary_domain + "/test"), &dictionary_list); |
| 207 &dictionary_list); | |
| 208 EXPECT_FALSE(dictionary_list.empty()); | 207 EXPECT_FALSE(dictionary_list.empty()); |
| 209 } | 208 } |
| 210 | 209 |
| 211 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { | 210 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { |
| 212 std::string dictionary_domain("x.y.z.google.com"); | 211 std::string dictionary_domain("x.y.z.google.com"); |
| 213 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 212 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 214 | 213 |
| 215 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 214 EXPECT_TRUE( |
| 216 GURL("http://" + dictionary_domain))); | 215 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 217 | 216 |
| 218 std::string dictionary_list; | 217 std::string dictionary_list; |
| 219 // HTTPS target URL should NOT advertise dictionary. | 218 // HTTPS target URL should NOT advertise dictionary. |
| 220 sdch_manager()->GetAvailDictionaryList( | 219 sdch_manager()->GetAvailDictionaryList( |
| 221 GURL("https://" + dictionary_domain + "/test"), | 220 GURL("https://" + dictionary_domain + "/test"), &dictionary_list); |
| 222 &dictionary_list); | |
| 223 EXPECT_TRUE(dictionary_list.empty()); | 221 EXPECT_TRUE(dictionary_list.empty()); |
| 224 } | 222 } |
| 225 | 223 |
| 226 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { | 224 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
| 227 std::string dictionary_domain("x.y.z.google.com"); | 225 std::string dictionary_domain("x.y.z.google.com"); |
| 228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 226 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 229 | 227 |
| 230 SdchManager::EnableSecureSchemeSupport(false); | 228 SdchManager::EnableSecureSchemeSupport(false); |
| 231 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 229 EXPECT_FALSE( |
| 232 GURL("https://" + dictionary_domain))); | 230 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain))); |
| 233 SdchManager::EnableSecureSchemeSupport(true); | 231 SdchManager::EnableSecureSchemeSupport(true); |
| 234 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 232 EXPECT_TRUE( |
| 235 GURL("https://" + dictionary_domain))); | 233 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain))); |
| 236 | 234 |
| 237 GURL target_url("https://" + dictionary_domain + "/test"); | 235 GURL target_url("https://" + dictionary_domain + "/test"); |
| 238 std::string dictionary_list; | 236 std::string dictionary_list; |
| 239 // HTTPS target URL should advertise dictionary if secure scheme support is | 237 // HTTPS target URL should advertise dictionary if secure scheme support is |
| 240 // enabled. | 238 // enabled. |
| 241 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 239 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 242 EXPECT_FALSE(dictionary_list.empty()); | 240 EXPECT_FALSE(dictionary_list.empty()); |
| 243 | 241 |
| 244 // Dictionary should be available. | 242 // Dictionary should be available. |
| 245 scoped_refptr<SdchManager::Dictionary> dictionary; | 243 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 246 std::string client_hash; | 244 std::string client_hash; |
| 247 std::string server_hash; | 245 std::string server_hash; |
| 248 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 246 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 249 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 247 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| 250 EXPECT_TRUE(dictionary.get() != NULL); | 248 EXPECT_TRUE(dictionary.get() != NULL); |
| 251 } | 249 } |
| 252 | 250 |
| 253 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { | 251 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| 254 std::string dictionary_domain("x.y.z.google.com"); | 252 std::string dictionary_domain("x.y.z.google.com"); |
| 255 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 253 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 256 | 254 |
| 257 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 255 EXPECT_TRUE( |
| 258 GURL("http://" + dictionary_domain))); | 256 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 259 | 257 |
| 260 GURL target_url("https://" + dictionary_domain + "/test"); | 258 GURL target_url("https://" + dictionary_domain + "/test"); |
| 261 std::string dictionary_list; | 259 std::string dictionary_list; |
| 262 // HTTPS target URL should not advertise dictionary acquired over HTTP even if | 260 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
| 263 // secure scheme support is enabled. | 261 // secure scheme support is enabled. |
| 264 SdchManager::EnableSecureSchemeSupport(true); | 262 SdchManager::EnableSecureSchemeSupport(true); |
| 265 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 263 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 266 EXPECT_TRUE(dictionary_list.empty()); | 264 EXPECT_TRUE(dictionary_list.empty()); |
| 267 | 265 |
| 268 scoped_refptr<SdchManager::Dictionary> dictionary; | 266 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 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| 273 EXPECT_TRUE(dictionary.get() == NULL); | 271 EXPECT_TRUE(dictionary.get() == NULL); |
| 274 } | 272 } |
| 275 | 273 |
| 276 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { | 274 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
| 277 std::string dictionary_domain("x.y.z.google.com"); | 275 std::string dictionary_domain("x.y.z.google.com"); |
| 278 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 276 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 279 | 277 |
| 280 SdchManager::EnableSecureSchemeSupport(true); | 278 SdchManager::EnableSecureSchemeSupport(true); |
| 281 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 279 EXPECT_TRUE( |
| 282 GURL("https://" + dictionary_domain))); | 280 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain))); |
| 283 | 281 |
| 284 GURL target_url("http://" + dictionary_domain + "/test"); | 282 GURL target_url("http://" + dictionary_domain + "/test"); |
| 285 std::string dictionary_list; | 283 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 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 289 EXPECT_TRUE(dictionary_list.empty()); | 287 EXPECT_TRUE(dictionary_list.empty()); |
| 290 | 288 |
| 291 scoped_refptr<SdchManager::Dictionary> dictionary; | 289 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 292 std::string client_hash; | 290 std::string client_hash; |
| 293 std::string server_hash; | 291 std::string server_hash; |
| 294 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 292 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 295 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 293 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| 296 EXPECT_TRUE(dictionary.get() == NULL); | 294 EXPECT_TRUE(dictionary.get() == NULL); |
| 297 } | 295 } |
| 298 | 296 |
| 299 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { | 297 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
| 300 std::string dictionary_domain("x.y.z.google.com"); | 298 std::string dictionary_domain("x.y.z.google.com"); |
| 301 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 299 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 302 | 300 |
| 303 // Fail the "domain match" requirement. | 301 // Fail the "domain match" requirement. |
| 304 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 302 EXPECT_FALSE( |
| 305 GURL("http://y.z.google.com"))); | 303 AddSdchDictionary(dictionary_text, GURL("http://y.z.google.com"))); |
| 306 } | 304 } |
| 307 | 305 |
| 308 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { | 306 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { |
| 309 std::string dictionary_domain("x.y.z.google.com"); | 307 std::string dictionary_domain("x.y.z.google.com"); |
| 310 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 308 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 311 | 309 |
| 312 // Fail the HD with D being the domain and H having a dot requirement. | 310 // Fail the HD with D being the domain and H having a dot requirement. |
| 313 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 311 EXPECT_FALSE( |
| 314 GURL("http://w.x.y.z.google.com"))); | 312 AddSdchDictionary(dictionary_text, GURL("http://w.x.y.z.google.com"))); |
| 315 } | 313 } |
| 316 | 314 |
| 317 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) { | 315 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) { |
| 318 std::string dictionary_domain("x.y.z.google.com"); | 316 std::string dictionary_domain("x.y.z.google.com"); |
| 319 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 317 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 320 | 318 |
| 321 // Fail the HD with D being the domain and H having a dot requirement. | 319 // Fail the HD with D being the domain and H having a dot requirement. |
| 322 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 320 EXPECT_FALSE( |
| 323 GURL("http://w.x.y.z.google.com."))); | 321 AddSdchDictionary(dictionary_text, GURL("http://w.x.y.z.google.com."))); |
| 324 } | 322 } |
| 325 | 323 |
| 326 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { | 324 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { |
| 327 // Make sure that a prefix that matches the domain postfix won't confuse | 325 // Make sure that a prefix that matches the domain postfix won't confuse |
| 328 // the validation checks. | 326 // the validation checks. |
| 329 std::string dictionary_domain("www.google.com"); | 327 std::string dictionary_domain("www.google.com"); |
| 330 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 328 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 331 | 329 |
| 332 // Fail the HD with D being the domain and H having a dot requirement. | 330 // Fail the HD with D being the domain and H having a dot requirement. |
| 333 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 331 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
| 334 GURL("http://www.google.com.www.google.com"))); | 332 GURL("http://www.google.com.www.google.com"))); |
| 335 } | 333 } |
| 336 | 334 |
| 337 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { | 335 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { |
| 338 // Make sure that a prefix that matches the domain postfix won't confuse | 336 // Make sure that a prefix that matches the domain postfix won't confuse |
| 339 // the validation checks. | 337 // the validation checks. |
| 340 std::string dictionary_domain(".google.com"); | 338 std::string dictionary_domain(".google.com"); |
| 341 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 339 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 342 | 340 |
| 343 // Verify that a leading dot in the domain is acceptable, as long as the host | 341 // Verify that a leading dot in the domain is acceptable, as long as the host |
| 344 // name does not contain any dots preceding the matched domain name. | 342 // name does not contain any dots preceding the matched domain name. |
| 345 EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com")))
; | 343 EXPECT_TRUE( |
| 344 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); |
| 346 } | 345 } |
| 347 | 346 |
| 348 TEST_F(SdchManagerTest, | 347 TEST_F(SdchManagerTest, |
| 349 CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) { | 348 CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) { |
| 350 // Make sure that a prefix that matches the domain postfix won't confuse | 349 // Make sure that a prefix that matches the domain postfix won't confuse |
| 351 // the validation checks. | 350 // the validation checks. |
| 352 std::string dictionary_domain(".google.com"); | 351 std::string dictionary_domain(".google.com"); |
| 353 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 352 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 354 | 353 |
| 355 // Verify that a leading dot in the domain is acceptable, as long as the host | 354 // Verify that a leading dot in the domain is acceptable, as long as the host |
| 356 // name does not contain any dots preceding the matched domain name. | 355 // name does not contain any dots preceding the matched domain name. |
| 357 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 356 EXPECT_TRUE( |
| 358 GURL("http://www.google.com."))); | 357 AddSdchDictionary(dictionary_text, GURL("http://www.google.com."))); |
| 359 } | 358 } |
| 360 | 359 |
| 361 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) { | 360 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) { |
| 362 // Make sure that a prefix that matches the domain postfix won't confuse | 361 // Make sure that a prefix that matches the domain postfix won't confuse |
| 363 // the validation checks. | 362 // the validation checks. |
| 364 std::string dictionary_domain(".google.com"); | 363 std::string dictionary_domain(".google.com"); |
| 365 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 364 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 366 | 365 |
| 367 // Verify that a leading dot in the domain does not affect the name containing | 366 // Verify that a leading dot in the domain does not affect the name containing |
| 368 // dots failure. | 367 // dots failure. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 381 GURL("http://www.subdomain.google.com."))); | 380 GURL("http://www.subdomain.google.com."))); |
| 382 } | 381 } |
| 383 | 382 |
| 384 // Make sure the order of the tests is not helping us or confusing things. | 383 // Make sure the order of the tests is not helping us or confusing things. |
| 385 // See test CanSetExactMatchDictionary above for first try. | 384 // See test CanSetExactMatchDictionary above for first try. |
| 386 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { | 385 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { |
| 387 std::string dictionary_domain("x.y.z.google.com"); | 386 std::string dictionary_domain("x.y.z.google.com"); |
| 388 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 387 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 389 | 388 |
| 390 // Perfect match should *STILL* work. | 389 // Perfect match should *STILL* work. |
| 391 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 390 EXPECT_TRUE( |
| 392 GURL("http://" + dictionary_domain))); | 391 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 393 } | 392 } |
| 394 | 393 |
| 395 // Make sure the DOS protection precludes the addition of too many dictionaries. | 394 // Make sure the DOS protection precludes the addition of too many dictionaries. |
| 396 TEST_F(SdchManagerTest, TooManyDictionaries) { | 395 TEST_F(SdchManagerTest, TooManyDictionaries) { |
| 397 std::string dictionary_domain(".google.com"); | 396 std::string dictionary_domain(".google.com"); |
| 398 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 397 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 399 | 398 |
| 400 for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) { | 399 for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) { |
| 401 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 400 EXPECT_TRUE( |
| 402 GURL("http://www.google.com"))); | 401 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); |
| 403 dictionary_text += " "; // Create dictionary with different SHA signature. | 402 dictionary_text += " "; // Create dictionary with different SHA signature. |
| 404 } | 403 } |
| 405 EXPECT_FALSE( | 404 EXPECT_FALSE( |
| 406 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); | 405 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); |
| 407 } | 406 } |
| 408 | 407 |
| 409 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { | 408 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { |
| 410 std::string dictionary_domain(".google.com"); | 409 std::string dictionary_domain(".google.com"); |
| 411 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 410 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 412 | 411 |
| 413 dictionary_text.append( | 412 dictionary_text.append( |
| 414 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); | 413 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); |
| 415 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 414 EXPECT_TRUE( |
| 416 GURL("http://" + dictionary_domain))); | 415 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 417 } | 416 } |
| 418 | 417 |
| 419 TEST_F(SdchManagerTest, DictionaryTooLarge) { | 418 TEST_F(SdchManagerTest, DictionaryTooLarge) { |
| 420 std::string dictionary_domain(".google.com"); | 419 std::string dictionary_domain(".google.com"); |
| 421 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 420 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 422 | 421 |
| 423 dictionary_text.append( | 422 dictionary_text.append( |
| 424 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); | 423 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); |
| 425 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 424 EXPECT_FALSE( |
| 426 GURL("http://" + dictionary_domain))); | 425 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 427 } | 426 } |
| 428 | 427 |
| 429 TEST_F(SdchManagerTest, PathMatch) { | 428 TEST_F(SdchManagerTest, PathMatch) { |
| 430 bool (*PathMatch)(const std::string& path, const std::string& restriction) = | 429 bool (*PathMatch)(const std::string& path, const std::string& restriction) = |
| 431 SdchManager::Dictionary::PathMatch; | 430 SdchManager::Dictionary::PathMatch; |
| 432 // Perfect match is supported. | 431 // Perfect match is supported. |
| 433 EXPECT_TRUE(PathMatch("/search", "/search")); | 432 EXPECT_TRUE(PathMatch("/search", "/search")); |
| 434 EXPECT_TRUE(PathMatch("/search/", "/search/")); | 433 EXPECT_TRUE(PathMatch("/search/", "/search/")); |
| 435 | 434 |
| 436 // Prefix only works if last character of restriction is a slash, or first | 435 // Prefix only works if last character of restriction is a slash, or first |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 509 |
| 511 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); | 510 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); |
| 512 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); | 511 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); |
| 513 | 512 |
| 514 // Confirm that if you add directories to one manager, you | 513 // Confirm that if you add directories to one manager, you |
| 515 // can't get them from the other. | 514 // can't get them from the other. |
| 516 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, | 515 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
| 517 GURL("http://" + dictionary_domain_1))); | 516 GURL("http://" + dictionary_domain_1))); |
| 518 scoped_refptr<SdchManager::Dictionary> dictionary; | 517 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 519 sdch_manager()->GetVcdiffDictionary( | 518 sdch_manager()->GetVcdiffDictionary( |
| 520 server_hash_1, | 519 server_hash_1, GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 521 GURL("http://" + dictionary_domain_1 + "/random_url"), | |
| 522 &dictionary); | 520 &dictionary); |
| 523 EXPECT_TRUE(dictionary.get()); | 521 EXPECT_TRUE(dictionary.get()); |
| 524 | 522 |
| 525 second_manager.AddSdchDictionary( | 523 second_manager.AddSdchDictionary(dictionary_text_2, |
| 526 dictionary_text_2, GURL("http://" + dictionary_domain_2)); | 524 GURL("http://" + dictionary_domain_2)); |
| 527 second_manager.GetVcdiffDictionary( | 525 second_manager.GetVcdiffDictionary( |
| 528 server_hash_2, | 526 server_hash_2, GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 529 GURL("http://" + dictionary_domain_2 + "/random_url"), | |
| 530 &dictionary); | 527 &dictionary); |
| 531 EXPECT_TRUE(dictionary.get()); | 528 EXPECT_TRUE(dictionary.get()); |
| 532 | 529 |
| 533 sdch_manager()->GetVcdiffDictionary( | 530 sdch_manager()->GetVcdiffDictionary( |
| 534 server_hash_2, | 531 server_hash_2, GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 535 GURL("http://" + dictionary_domain_2 + "/random_url"), | |
| 536 &dictionary); | 532 &dictionary); |
| 537 EXPECT_FALSE(dictionary.get()); | 533 EXPECT_FALSE(dictionary.get()); |
| 538 | 534 |
| 539 second_manager.GetVcdiffDictionary( | 535 second_manager.GetVcdiffDictionary( |
| 540 server_hash_1, | 536 server_hash_1, GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 541 GURL("http://" + dictionary_domain_1 + "/random_url"), | |
| 542 &dictionary); | 537 &dictionary); |
| 543 EXPECT_FALSE(dictionary.get()); | 538 EXPECT_FALSE(dictionary.get()); |
| 544 } | 539 } |
| 545 | 540 |
| 546 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { | 541 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { |
| 547 GURL url("http://www.google.com"); | 542 GURL url("http://www.google.com"); |
| 548 GURL secure_url("https://www.google.com"); | 543 GURL secure_url("https://www.google.com"); |
| 549 | 544 |
| 550 bool expect_https_support = true; | 545 bool expect_https_support = true; |
| 551 | 546 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 562 TEST_F(SdchManagerTest, ClearDictionaryData) { | 557 TEST_F(SdchManagerTest, ClearDictionaryData) { |
| 563 std::string dictionary_domain("x.y.z.google.com"); | 558 std::string dictionary_domain("x.y.z.google.com"); |
| 564 GURL blacklist_url("http://bad.chromium.org"); | 559 GURL blacklist_url("http://bad.chromium.org"); |
| 565 | 560 |
| 566 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 561 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 567 std::string tmp_hash; | 562 std::string tmp_hash; |
| 568 std::string server_hash; | 563 std::string server_hash; |
| 569 | 564 |
| 570 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); | 565 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); |
| 571 | 566 |
| 572 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 567 EXPECT_TRUE( |
| 573 GURL("http://" + dictionary_domain))); | 568 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain))); |
| 574 scoped_refptr<SdchManager::Dictionary> dictionary; | 569 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 575 sdch_manager()->GetVcdiffDictionary( | 570 sdch_manager()->GetVcdiffDictionary( |
| 576 server_hash, | 571 server_hash, GURL("http://" + dictionary_domain + "/random_url"), |
| 577 GURL("http://" + dictionary_domain + "/random_url"), | |
| 578 &dictionary); | 572 &dictionary); |
| 579 EXPECT_TRUE(dictionary.get()); | 573 EXPECT_TRUE(dictionary.get()); |
| 580 | 574 |
| 581 sdch_manager()->BlacklistDomain(GURL(blacklist_url), | 575 sdch_manager()->BlacklistDomain(GURL(blacklist_url), |
| 582 SdchManager::MIN_PROBLEM_CODE); | 576 SdchManager::MIN_PROBLEM_CODE); |
| 583 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 577 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 584 | 578 |
| 585 sdch_manager()->ClearData(); | 579 sdch_manager()->ClearData(); |
| 586 | 580 |
| 587 dictionary = NULL; | 581 dictionary = NULL; |
| 588 sdch_manager()->GetVcdiffDictionary( | 582 sdch_manager()->GetVcdiffDictionary( |
| 589 server_hash, | 583 server_hash, GURL("http://" + dictionary_domain + "/random_url"), |
| 590 GURL("http://" + dictionary_domain + "/random_url"), | |
| 591 &dictionary); | 584 &dictionary); |
| 592 EXPECT_FALSE(dictionary.get()); | 585 EXPECT_FALSE(dictionary.get()); |
| 593 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 586 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 594 } | 587 } |
| 595 | 588 |
| 596 TEST_F(SdchManagerTest, GetDictionaryNotification) { | 589 TEST_F(SdchManagerTest, GetDictionaryNotification) { |
| 597 GURL test_request_gurl(GURL("http://www.example.com/data")); | 590 GURL test_request_gurl(GURL("http://www.example.com/data")); |
| 598 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); | 591 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); |
| 599 MockSdchObserver observer; | 592 MockSdchObserver observer; |
| 600 sdch_manager()->AddObserver(&observer); | 593 sdch_manager()->AddObserver(&observer); |
| 601 | 594 |
| 602 EXPECT_EQ(0, observer.get_dictionary_notifications()); | 595 EXPECT_EQ(0, observer.get_dictionary_notifications()); |
| 603 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); | 596 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); |
| 604 EXPECT_EQ(1, observer.get_dictionary_notifications()); | 597 EXPECT_EQ(1, observer.get_dictionary_notifications()); |
| 605 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); | 598 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); |
| 606 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); | 599 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); |
| 607 | 600 |
| 608 sdch_manager()->RemoveObserver(&observer); | 601 sdch_manager()->RemoveObserver(&observer); |
| 609 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); | 602 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); |
| 610 EXPECT_EQ(1, observer.get_dictionary_notifications()); | 603 EXPECT_EQ(1, observer.get_dictionary_notifications()); |
| 611 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); | 604 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); |
| 612 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); | 605 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); |
| 613 } | 606 } |
| 614 | 607 |
| 615 } // namespace net | 608 } // namespace net |
| OLD | NEW |