Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Declare SdchProblemCode Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/net_log.h"
11 #include "net/base/sdch_manager.h" 12 #include "net/base/sdch_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 //------------------------------------------------------------------------------ 17 //------------------------------------------------------------------------------
17 // Provide sample data and compression results with a sample VCDIFF dictionary. 18 // Provide sample data and compression results with a sample VCDIFF dictionary.
18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 19 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
19 static const char kTestVcdiffDictionary[] = "DictionaryFor" 20 static const char kTestVcdiffDictionary[] = "DictionaryFor"
20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; 21 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
(...skipping 15 matching lines...) Expand all
36 // Reset globals back to default state. 37 // Reset globals back to default state.
37 virtual void TearDown() { 38 virtual void TearDown() {
38 SdchManager::EnableSdchSupport(default_support_); 39 SdchManager::EnableSdchSupport(default_support_);
39 SdchManager::EnableSecureSchemeSupport(default_https_support_); 40 SdchManager::EnableSecureSchemeSupport(default_https_support_);
40 } 41 }
41 42
42 // Attempt to add a dictionary to the manager and probe for success or 43 // Attempt to add a dictionary to the manager and probe for success or
43 // failure. 44 // failure.
44 bool AddSdchDictionary(const std::string& dictionary_text, 45 bool AddSdchDictionary(const std::string& dictionary_text,
45 const GURL& gurl) { 46 const GURL& gurl) {
46 std::string list; 47 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl) == SDCH_OK;
47 sdch_manager_->GetAvailDictionaryList(gurl, &list);
48 sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
49 std::string list2;
50 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
51
52 // The list of hashes should change iff the addition succeeds.
53 return (list != list2);
54 } 48 }
55 49
56 private: 50 private:
57 scoped_ptr<SdchManager> sdch_manager_; 51 scoped_ptr<SdchManager> sdch_manager_;
58 bool default_support_; 52 bool default_support_;
59 bool default_https_support_; 53 bool default_https_support_;
60 }; 54 };
61 55
62 //------------------------------------------------------------------------------ 56 //------------------------------------------------------------------------------
63 static std::string NewSdchDictionary(const std::string& domain) { 57 static std::string NewSdchDictionary(const std::string& domain) {
64 std::string dictionary; 58 std::string dictionary;
65 if (!domain.empty()) { 59 if (!domain.empty()) {
66 dictionary.append("Domain: "); 60 dictionary.append("Domain: ");
67 dictionary.append(domain); 61 dictionary.append(domain);
68 dictionary.append("\n"); 62 dictionary.append("\n");
69 } 63 }
70 dictionary.append("\n"); 64 dictionary.append("\n");
71 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 65 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
72 return dictionary; 66 return dictionary;
73 } 67 }
74 68
75 TEST_F(SdchManagerTest, DomainSupported) { 69 TEST_F(SdchManagerTest, DomainSupported) {
76 GURL google_url("http://www.google.com"); 70 GURL google_url("http://www.google.com");
77 71
78 SdchManager::EnableSdchSupport(false); 72 SdchManager::EnableSdchSupport(false);
79 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); 73 EXPECT_EQ(SDCH_DISABLED, sdch_manager()->IsInSupportedDomain(google_url));
80 SdchManager::EnableSdchSupport(true); 74 SdchManager::EnableSdchSupport(true);
81 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 75 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
82 } 76 }
83 77
84 TEST_F(SdchManagerTest, DomainBlacklisting) { 78 TEST_F(SdchManagerTest, DomainBlacklisting) {
85 GURL test_url("http://www.test.com"); 79 GURL test_url("http://www.test.com");
86 GURL google_url("http://www.google.com"); 80 GURL google_url("http://www.google.com");
87 81
88 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); 82 sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
89 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); 83 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
90 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 84 sdch_manager()->IsInSupportedDomain(test_url));
85 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
91 86
92 sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); 87 sdch_manager()->BlacklistDomain(google_url, SDCH_OK);
93 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); 88 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
89 sdch_manager()->IsInSupportedDomain(google_url));
94 } 90 }
95 91
96 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { 92 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) {
97 GURL test_url("http://www.TesT.com"); 93 GURL test_url("http://www.TesT.com");
98 GURL test2_url("http://www.tEst.com"); 94 GURL test2_url("http://www.tEst.com");
99 95
100 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); 96 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test_url));
101 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); 97 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test2_url));
102 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); 98 sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
103 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); 99 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
100 sdch_manager()->IsInSupportedDomain(test2_url));
104 } 101 }
105 102
106 TEST_F(SdchManagerTest, BlacklistingReset) { 103 TEST_F(SdchManagerTest, BlacklistingReset) {
107 GURL gurl("http://mytest.DoMain.com"); 104 GURL gurl("http://mytest.DoMain.com");
108 std::string domain(gurl.host()); 105 std::string domain(gurl.host());
109 106
110 sdch_manager()->ClearBlacklistings(); 107 sdch_manager()->ClearBlacklistings();
111 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 108 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
112 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); 109 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0);
113 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 110 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
114 } 111 }
115 112
116 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { 113 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
117 GURL gurl("http://mytest.DoMain.com"); 114 GURL gurl("http://mytest.DoMain.com");
118 std::string domain(gurl.host()); 115 std::string domain(gurl.host());
119 sdch_manager()->ClearBlacklistings(); 116 sdch_manager()->ClearBlacklistings();
120 117
121 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); 118 sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
122 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); 119 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1);
123 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); 120 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1);
124 121
125 // Check that any domain lookup reduces the blacklist counter. 122 // Check that any domain lookup reduces the blacklist counter.
126 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); 123 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
124 sdch_manager()->IsInSupportedDomain(gurl));
127 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 125 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
128 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 126 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
129 } 127 }
130 128
131 TEST_F(SdchManagerTest, BlacklistingExponential) { 129 TEST_F(SdchManagerTest, BlacklistingExponential) {
132 GURL gurl("http://mytest.DoMain.com"); 130 GURL gurl("http://mytest.DoMain.com");
133 std::string domain(gurl.host()); 131 std::string domain(gurl.host());
134 sdch_manager()->ClearBlacklistings(); 132 sdch_manager()->ClearBlacklistings();
135 133
136 int exponential = 1; 134 int exponential = 1;
137 for (int i = 1; i < 100; ++i) { 135 for (int i = 1; i < 100; ++i) {
138 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); 136 sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
139 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); 137 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential);
140 138
141 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); 139 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential);
142 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); 140 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
141 sdch_manager()->IsInSupportedDomain(gurl));
143 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); 142 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1);
144 143
145 // Simulate a large number of domain checks (which eventually remove the 144 // Simulate a large number of domain checks (which eventually remove the
146 // blacklisting). 145 // blacklisting).
147 sdch_manager()->ClearDomainBlacklisting(domain); 146 sdch_manager()->ClearDomainBlacklisting(domain);
148 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 147 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
149 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 148 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
150 149
151 // Predict what exponential backoff will be. 150 // Predict what exponential backoff will be.
152 exponential = 1 + 2 * exponential; 151 exponential = 1 + 2 * exponential;
153 if (exponential < 0) 152 if (exponential < 0)
154 exponential = INT_MAX; // We don't wrap. 153 exponential = INT_MAX; // We don't wrap.
155 } 154 }
156 } 155 }
157 156
158 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { 157 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) {
159 std::string dictionary_domain("x.y.z.google.com"); 158 std::string dictionary_domain("x.y.z.google.com");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // HTTPS target URL should advertise dictionary if secure scheme support is 209 // HTTPS target URL should advertise dictionary if secure scheme support is
211 // enabled. 210 // enabled.
212 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 211 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
213 EXPECT_FALSE(dictionary_list.empty()); 212 EXPECT_FALSE(dictionary_list.empty());
214 213
215 // Dictionary should be available. 214 // Dictionary should be available.
216 scoped_refptr<SdchManager::Dictionary> dictionary; 215 scoped_refptr<SdchManager::Dictionary> dictionary;
217 std::string client_hash; 216 std::string client_hash;
218 std::string server_hash; 217 std::string server_hash;
219 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 218 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
220 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 219 EXPECT_EQ(SDCH_OK,
220 sdch_manager()->GetVcdiffDictionary(
221 server_hash, target_url, &dictionary));
221 EXPECT_TRUE(dictionary.get() != NULL); 222 EXPECT_TRUE(dictionary.get() != NULL);
222 } 223 }
223 224
224 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 225 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
225 std::string dictionary_domain("x.y.z.google.com"); 226 std::string dictionary_domain("x.y.z.google.com");
226 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 227 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
227 228
228 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 229 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
229 GURL("http://" + dictionary_domain))); 230 GURL("http://" + dictionary_domain)));
230 231
231 GURL target_url("https://" + dictionary_domain + "/test"); 232 GURL target_url("https://" + dictionary_domain + "/test");
232 std::string dictionary_list; 233 std::string dictionary_list;
233 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 234 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
234 // secure scheme support is enabled. 235 // secure scheme support is enabled.
235 SdchManager::EnableSecureSchemeSupport(true); 236 SdchManager::EnableSecureSchemeSupport(true);
236 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 237 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
237 EXPECT_TRUE(dictionary_list.empty()); 238 EXPECT_TRUE(dictionary_list.empty());
238 239
239 scoped_refptr<SdchManager::Dictionary> dictionary; 240 scoped_refptr<SdchManager::Dictionary> dictionary;
240 std::string client_hash; 241 std::string client_hash;
241 std::string server_hash; 242 std::string server_hash;
242 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 243 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
243 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 244 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
245 sdch_manager()->GetVcdiffDictionary(
246 server_hash, target_url, &dictionary));
244 EXPECT_TRUE(dictionary.get() == NULL); 247 EXPECT_TRUE(dictionary.get() == NULL);
245 } 248 }
246 249
247 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { 250 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
248 std::string dictionary_domain("x.y.z.google.com"); 251 std::string dictionary_domain("x.y.z.google.com");
249 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 252 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
250 253
251 SdchManager::EnableSecureSchemeSupport(true); 254 SdchManager::EnableSecureSchemeSupport(true);
252 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 255 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
253 GURL("https://" + dictionary_domain))); 256 GURL("https://" + dictionary_domain)));
254 257
255 GURL target_url("http://" + dictionary_domain + "/test"); 258 GURL target_url("http://" + dictionary_domain + "/test");
256 std::string dictionary_list; 259 std::string dictionary_list;
257 // HTTP target URL should not advertise dictionary acquired over HTTPS even if 260 // HTTP target URL should not advertise dictionary acquired over HTTPS even if
258 // secure scheme support is enabled. 261 // secure scheme support is enabled.
259 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 262 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
260 EXPECT_TRUE(dictionary_list.empty()); 263 EXPECT_TRUE(dictionary_list.empty());
261 264
262 scoped_refptr<SdchManager::Dictionary> dictionary; 265 scoped_refptr<SdchManager::Dictionary> dictionary;
263 std::string client_hash; 266 std::string client_hash;
264 std::string server_hash; 267 std::string server_hash;
265 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 268 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
266 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 269 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
270 sdch_manager()->GetVcdiffDictionary(
271 server_hash, target_url, &dictionary));
267 EXPECT_TRUE(dictionary.get() == NULL); 272 EXPECT_TRUE(dictionary.get() == NULL);
268 } 273 }
269 274
270 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 275 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
271 std::string dictionary_domain("x.y.z.google.com"); 276 std::string dictionary_domain("x.y.z.google.com");
272 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 277 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
273 278
274 // Fail the "domain match" requirement. 279 // Fail the "domain match" requirement.
275 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 280 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
276 GURL("http://y.z.google.com"))); 281 GURL("http://y.z.google.com")));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 std::string server_hash_2; 485 std::string server_hash_2;
481 486
482 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); 487 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
483 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); 488 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
484 489
485 // Confirm that if you add directories to one manager, you 490 // Confirm that if you add directories to one manager, you
486 // can't get them from the other. 491 // can't get them from the other.
487 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, 492 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
488 GURL("http://" + dictionary_domain_1))); 493 GURL("http://" + dictionary_domain_1)));
489 scoped_refptr<SdchManager::Dictionary> dictionary; 494 scoped_refptr<SdchManager::Dictionary> dictionary;
490 sdch_manager()->GetVcdiffDictionary( 495 EXPECT_EQ(SDCH_OK,
491 server_hash_1, 496 sdch_manager()->GetVcdiffDictionary(
492 GURL("http://" + dictionary_domain_1 + "/random_url"), 497 server_hash_1,
493 &dictionary); 498 GURL("http://" + dictionary_domain_1 + "/random_url"),
499 &dictionary));
494 EXPECT_TRUE(dictionary.get()); 500 EXPECT_TRUE(dictionary.get());
495 501
496 second_manager.AddSdchDictionary( 502 second_manager.AddSdchDictionary(
497 dictionary_text_2, GURL("http://" + dictionary_domain_2)); 503 dictionary_text_2, GURL("http://" + dictionary_domain_2));
498 second_manager.GetVcdiffDictionary( 504 second_manager.GetVcdiffDictionary(
499 server_hash_2, 505 server_hash_2,
500 GURL("http://" + dictionary_domain_2 + "/random_url"), 506 GURL("http://" + dictionary_domain_2 + "/random_url"),
501 &dictionary); 507 &dictionary);
502 EXPECT_TRUE(dictionary.get()); 508 EXPECT_TRUE(dictionary.get());
503 509
504 sdch_manager()->GetVcdiffDictionary( 510 EXPECT_EQ(SDCH_OK,
505 server_hash_2, 511 sdch_manager()->GetVcdiffDictionary(
506 GURL("http://" + dictionary_domain_2 + "/random_url"), 512 server_hash_2,
507 &dictionary); 513 GURL("http://" + dictionary_domain_2 + "/random_url"),
514 &dictionary));
508 EXPECT_FALSE(dictionary.get()); 515 EXPECT_FALSE(dictionary.get());
509 516
510 second_manager.GetVcdiffDictionary( 517 EXPECT_EQ(SDCH_OK,
511 server_hash_1, 518 second_manager.GetVcdiffDictionary(
512 GURL("http://" + dictionary_domain_1 + "/random_url"), 519 server_hash_1,
513 &dictionary); 520 GURL("http://" + dictionary_domain_1 + "/random_url"),
521 &dictionary));
514 EXPECT_FALSE(dictionary.get()); 522 EXPECT_FALSE(dictionary.get());
515 } 523 }
516 524
517 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { 525 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
518 GURL url("http://www.google.com"); 526 GURL url("http://www.google.com");
519 GURL secure_url("https://www.google.com"); 527 GURL secure_url("https://www.google.com");
520 528
521 #if !defined(OS_IOS) 529 #if !defined(OS_IOS)
522 // Workaround for http://crbug.com/418975; remove when fixed. 530 // Workaround for http://crbug.com/418975; remove when fixed.
523 bool expect_https_support = true; 531 bool expect_https_support = true;
524 #else 532 #else
525 bool expect_https_support = false; 533 bool expect_https_support = false;
526 #endif 534 #endif
527 535
528 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 536 SdchProblemCode expected_code =
529 EXPECT_EQ(expect_https_support, 537 expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED;
530 sdch_manager()->IsInSupportedDomain(secure_url)); 538
539 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
540 EXPECT_EQ(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
531 541
532 SdchManager::EnableSecureSchemeSupport(!expect_https_support); 542 SdchManager::EnableSecureSchemeSupport(!expect_https_support);
533 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 543 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
534 EXPECT_NE(expect_https_support, 544 EXPECT_NE(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
535 sdch_manager()->IsInSupportedDomain(secure_url));
536 } 545 }
537 546
538 TEST_F(SdchManagerTest, ClearDictionaryData) { 547 TEST_F(SdchManagerTest, ClearDictionaryData) {
539 std::string dictionary_domain("x.y.z.google.com"); 548 std::string dictionary_domain("x.y.z.google.com");
540 GURL blacklist_url("http://bad.chromium.org"); 549 GURL blacklist_url("http://bad.chromium.org");
541 550
542 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 551 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
543 std::string tmp_hash; 552 std::string tmp_hash;
544 std::string server_hash; 553 std::string server_hash;
545 554
546 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); 555 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
547 556
548 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 557 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
549 GURL("http://" + dictionary_domain))); 558 GURL("http://" + dictionary_domain)));
550 scoped_refptr<SdchManager::Dictionary> dictionary; 559 scoped_refptr<SdchManager::Dictionary> dictionary;
551 sdch_manager()->GetVcdiffDictionary( 560 EXPECT_EQ(SDCH_OK,
552 server_hash, 561 sdch_manager()->GetVcdiffDictionary(
553 GURL("http://" + dictionary_domain + "/random_url"), 562 server_hash,
554 &dictionary); 563 GURL("http://" + dictionary_domain + "/random_url"),
564 &dictionary));
555 EXPECT_TRUE(dictionary.get()); 565 EXPECT_TRUE(dictionary.get());
556 566
557 sdch_manager()->BlacklistDomain(GURL(blacklist_url), 567 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK);
558 SdchManager::MIN_PROBLEM_CODE); 568 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
559 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 569 sdch_manager()->IsInSupportedDomain(blacklist_url));
560 570
561 sdch_manager()->ClearData(); 571 sdch_manager()->ClearData();
562 572
563 dictionary = NULL; 573 dictionary = NULL;
564 sdch_manager()->GetVcdiffDictionary( 574 EXPECT_EQ(SDCH_OK,
565 server_hash, 575 sdch_manager()->GetVcdiffDictionary(
566 GURL("http://" + dictionary_domain + "/random_url"), 576 server_hash,
567 &dictionary); 577 GURL("http://" + dictionary_domain + "/random_url"),
578 &dictionary));
568 EXPECT_FALSE(dictionary.get()); 579 EXPECT_FALSE(dictionary.get());
569 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 580 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url));
570 } 581 }
571 582
572 } // namespace net 583 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698