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

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: Fix component linkage 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
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_net_log_params.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl) == SDCH_OK;
77 sdch_manager_->GetAvailDictionaryList(gurl, &list);
78 sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
79 std::string list2;
80 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
81
82 // The list of hashes should change iff the addition succeeds.
83 return (list != list2);
84 } 78 }
85 79
86 private: 80 private:
87 scoped_ptr<SdchManager> sdch_manager_; 81 scoped_ptr<SdchManager> sdch_manager_;
88 bool default_support_; 82 bool default_support_;
89 bool default_https_support_; 83 bool default_https_support_;
90 }; 84 };
91 85
92 static std::string NewSdchDictionary(const std::string& domain) { 86 static std::string NewSdchDictionary(const std::string& domain) {
93 std::string dictionary; 87 std::string dictionary;
94 if (!domain.empty()) { 88 if (!domain.empty()) {
95 dictionary.append("Domain: "); 89 dictionary.append("Domain: ");
96 dictionary.append(domain); 90 dictionary.append(domain);
97 dictionary.append("\n"); 91 dictionary.append("\n");
98 } 92 }
99 dictionary.append("\n"); 93 dictionary.append("\n");
100 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 94 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
101 return dictionary; 95 return dictionary;
102 } 96 }
103 97
104 TEST_F(SdchManagerTest, DomainSupported) { 98 TEST_F(SdchManagerTest, DomainSupported) {
105 GURL google_url("http://www.google.com"); 99 GURL google_url("http://www.google.com");
106 100
107 SdchManager::EnableSdchSupport(false); 101 SdchManager::EnableSdchSupport(false);
108 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); 102 EXPECT_EQ(SDCH_DISABLED, sdch_manager()->IsInSupportedDomain(google_url));
109 SdchManager::EnableSdchSupport(true); 103 SdchManager::EnableSdchSupport(true);
110 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 104 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
111 } 105 }
112 106
113 TEST_F(SdchManagerTest, DomainBlacklisting) { 107 TEST_F(SdchManagerTest, DomainBlacklisting) {
114 GURL test_url("http://www.test.com"); 108 GURL test_url("http://www.test.com");
115 GURL google_url("http://www.google.com"); 109 GURL google_url("http://www.google.com");
116 110
117 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); 111 sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
118 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); 112 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
119 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 113 sdch_manager()->IsInSupportedDomain(test_url));
114 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
120 115
121 sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); 116 sdch_manager()->BlacklistDomain(google_url, SDCH_OK);
122 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); 117 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
118 sdch_manager()->IsInSupportedDomain(google_url));
123 } 119 }
124 120
125 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { 121 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) {
126 GURL test_url("http://www.TesT.com"); 122 GURL test_url("http://www.TesT.com");
127 GURL test2_url("http://www.tEst.com"); 123 GURL test2_url("http://www.tEst.com");
128 124
129 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); 125 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test_url));
130 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); 126 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test2_url));
131 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); 127 sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
132 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); 128 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
129 sdch_manager()->IsInSupportedDomain(test2_url));
133 } 130 }
134 131
135 TEST_F(SdchManagerTest, BlacklistingReset) { 132 TEST_F(SdchManagerTest, BlacklistingReset) {
136 GURL gurl("http://mytest.DoMain.com"); 133 GURL gurl("http://mytest.DoMain.com");
137 std::string domain(gurl.host()); 134 std::string domain(gurl.host());
138 135
139 sdch_manager()->ClearBlacklistings(); 136 sdch_manager()->ClearBlacklistings();
140 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 137 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
141 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); 138 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0);
142 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 139 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
143 } 140 }
144 141
145 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { 142 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
146 GURL gurl("http://mytest.DoMain.com"); 143 GURL gurl("http://mytest.DoMain.com");
147 std::string domain(gurl.host()); 144 std::string domain(gurl.host());
148 sdch_manager()->ClearBlacklistings(); 145 sdch_manager()->ClearBlacklistings();
149 146
150 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); 147 sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
151 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); 148 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1);
152 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); 149 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1);
153 150
154 // Check that any domain lookup reduces the blacklist counter. 151 // Check that any domain lookup reduces the blacklist counter.
155 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); 152 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
153 sdch_manager()->IsInSupportedDomain(gurl));
156 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 154 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
157 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 155 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
158 } 156 }
159 157
160 TEST_F(SdchManagerTest, BlacklistingExponential) { 158 TEST_F(SdchManagerTest, BlacklistingExponential) {
161 GURL gurl("http://mytest.DoMain.com"); 159 GURL gurl("http://mytest.DoMain.com");
162 std::string domain(gurl.host()); 160 std::string domain(gurl.host());
163 sdch_manager()->ClearBlacklistings(); 161 sdch_manager()->ClearBlacklistings();
164 162
165 int exponential = 1; 163 int exponential = 1;
166 for (int i = 1; i < 100; ++i) { 164 for (int i = 1; i < 100; ++i) {
167 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); 165 sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
168 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); 166 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential);
169 167
170 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); 168 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential);
171 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); 169 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
170 sdch_manager()->IsInSupportedDomain(gurl));
172 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); 171 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1);
173 172
174 // Simulate a large number of domain checks (which eventually remove the 173 // Simulate a large number of domain checks (which eventually remove the
175 // blacklisting). 174 // blacklisting).
176 sdch_manager()->ClearDomainBlacklisting(domain); 175 sdch_manager()->ClearDomainBlacklisting(domain);
177 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); 176 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
178 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); 177 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
179 178
180 // Predict what exponential backoff will be. 179 // Predict what exponential backoff will be.
181 exponential = 1 + 2 * exponential; 180 exponential = 1 + 2 * exponential;
182 if (exponential < 0) 181 if (exponential < 0)
183 exponential = INT_MAX; // We don't wrap. 182 exponential = INT_MAX; // We don't wrap.
184 } 183 }
185 } 184 }
186 185
187 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { 186 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) {
188 std::string dictionary_domain("x.y.z.google.com"); 187 std::string dictionary_domain("x.y.z.google.com");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // HTTPS target URL should advertise dictionary if secure scheme support is 238 // HTTPS target URL should advertise dictionary if secure scheme support is
240 // enabled. 239 // enabled.
241 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 240 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
242 EXPECT_FALSE(dictionary_list.empty()); 241 EXPECT_FALSE(dictionary_list.empty());
243 242
244 // Dictionary should be available. 243 // Dictionary should be available.
245 scoped_refptr<SdchManager::Dictionary> dictionary; 244 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 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
249 server_hash, target_url, &dictionary));
250 EXPECT_TRUE(dictionary.get() != NULL); 250 EXPECT_TRUE(dictionary.get() != NULL);
251 } 251 }
252 252
253 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 253 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
254 std::string dictionary_domain("x.y.z.google.com"); 254 std::string dictionary_domain("x.y.z.google.com");
255 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 255 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
256 256
257 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 257 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
258 GURL("http://" + dictionary_domain))); 258 GURL("http://" + dictionary_domain)));
259 259
260 GURL target_url("https://" + dictionary_domain + "/test"); 260 GURL target_url("https://" + dictionary_domain + "/test");
261 std::string dictionary_list; 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 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
266 EXPECT_TRUE(dictionary_list.empty()); 266 EXPECT_TRUE(dictionary_list.empty());
267 267
268 scoped_refptr<SdchManager::Dictionary> dictionary; 268 scoped_refptr<SdchManager::Dictionary> dictionary;
269 std::string client_hash; 269 std::string client_hash;
270 std::string server_hash; 270 std::string server_hash;
271 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 271 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
272 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 272 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
273 sdch_manager()->GetVcdiffDictionary(server_hash, target_url,
274 &dictionary));
273 EXPECT_TRUE(dictionary.get() == NULL); 275 EXPECT_TRUE(dictionary.get() == NULL);
274 } 276 }
275 277
276 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { 278 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
277 std::string dictionary_domain("x.y.z.google.com"); 279 std::string dictionary_domain("x.y.z.google.com");
278 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 280 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
279 281
280 SdchManager::EnableSecureSchemeSupport(true); 282 SdchManager::EnableSecureSchemeSupport(true);
281 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 283 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
282 GURL("https://" + dictionary_domain))); 284 GURL("https://" + dictionary_domain)));
283 285
284 GURL target_url("http://" + dictionary_domain + "/test"); 286 GURL target_url("http://" + dictionary_domain + "/test");
285 std::string dictionary_list; 287 std::string dictionary_list;
286 // HTTP target URL should not advertise dictionary acquired over HTTPS even if 288 // HTTP target URL should not advertise dictionary acquired over HTTPS even if
287 // secure scheme support is enabled. 289 // secure scheme support is enabled.
288 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 290 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
289 EXPECT_TRUE(dictionary_list.empty()); 291 EXPECT_TRUE(dictionary_list.empty());
290 292
291 scoped_refptr<SdchManager::Dictionary> dictionary; 293 scoped_refptr<SdchManager::Dictionary> dictionary;
292 std::string client_hash; 294 std::string client_hash;
293 std::string server_hash; 295 std::string server_hash;
294 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 296 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
295 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 297 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
298 sdch_manager()->GetVcdiffDictionary(server_hash, target_url,
299 &dictionary));
296 EXPECT_TRUE(dictionary.get() == NULL); 300 EXPECT_TRUE(dictionary.get() == NULL);
297 } 301 }
298 302
299 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 303 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
300 std::string dictionary_domain("x.y.z.google.com"); 304 std::string dictionary_domain("x.y.z.google.com");
301 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 305 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
302 306
303 // Fail the "domain match" requirement. 307 // Fail the "domain match" requirement.
304 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 308 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
305 GURL("http://y.z.google.com"))); 309 GURL("http://y.z.google.com")));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 std::string server_hash_2; 513 std::string server_hash_2;
510 514
511 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); 515 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
512 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); 516 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
513 517
514 // Confirm that if you add directories to one manager, you 518 // Confirm that if you add directories to one manager, you
515 // can't get them from the other. 519 // can't get them from the other.
516 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, 520 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
517 GURL("http://" + dictionary_domain_1))); 521 GURL("http://" + dictionary_domain_1)));
518 scoped_refptr<SdchManager::Dictionary> dictionary; 522 scoped_refptr<SdchManager::Dictionary> dictionary;
519 sdch_manager()->GetVcdiffDictionary( 523 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
520 server_hash_1, 524 server_hash_1,
521 GURL("http://" + dictionary_domain_1 + "/random_url"), 525 GURL("http://" + dictionary_domain_1 + "/random_url"),
522 &dictionary); 526 &dictionary));
523 EXPECT_TRUE(dictionary.get()); 527 EXPECT_TRUE(dictionary.get());
524 528
525 second_manager.AddSdchDictionary( 529 second_manager.AddSdchDictionary(
526 dictionary_text_2, GURL("http://" + dictionary_domain_2)); 530 dictionary_text_2, GURL("http://" + dictionary_domain_2));
527 second_manager.GetVcdiffDictionary( 531 second_manager.GetVcdiffDictionary(
528 server_hash_2, 532 server_hash_2,
529 GURL("http://" + dictionary_domain_2 + "/random_url"), 533 GURL("http://" + dictionary_domain_2 + "/random_url"),
530 &dictionary); 534 &dictionary);
531 EXPECT_TRUE(dictionary.get()); 535 EXPECT_TRUE(dictionary.get());
532 536
533 sdch_manager()->GetVcdiffDictionary( 537 EXPECT_EQ(
534 server_hash_2, 538 SDCH_DICTIONARY_HASH_NOT_FOUND,
535 GURL("http://" + dictionary_domain_2 + "/random_url"), 539 sdch_manager()->GetVcdiffDictionary(
536 &dictionary); 540 server_hash_2, GURL("http://" + dictionary_domain_2 + "/random_url"),
541 &dictionary));
537 EXPECT_FALSE(dictionary.get()); 542 EXPECT_FALSE(dictionary.get());
538 543
539 second_manager.GetVcdiffDictionary( 544 EXPECT_EQ(
540 server_hash_1, 545 SDCH_DICTIONARY_HASH_NOT_FOUND,
541 GURL("http://" + dictionary_domain_1 + "/random_url"), 546 second_manager.GetVcdiffDictionary(
542 &dictionary); 547 server_hash_1, GURL("http://" + dictionary_domain_1 + "/random_url"),
548 &dictionary));
543 EXPECT_FALSE(dictionary.get()); 549 EXPECT_FALSE(dictionary.get());
544 } 550 }
545 551
546 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { 552 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
547 GURL url("http://www.google.com"); 553 GURL url("http://www.google.com");
548 GURL secure_url("https://www.google.com"); 554 GURL secure_url("https://www.google.com");
549 555
550 bool expect_https_support = true; 556 bool expect_https_support = true;
551 557
552 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 558 SdchProblemCode expected_code =
553 EXPECT_EQ(expect_https_support, 559 expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED;
554 sdch_manager()->IsInSupportedDomain(secure_url)); 560
561 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
562 EXPECT_EQ(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
555 563
556 SdchManager::EnableSecureSchemeSupport(!expect_https_support); 564 SdchManager::EnableSecureSchemeSupport(!expect_https_support);
557 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 565 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
558 EXPECT_NE(expect_https_support, 566 EXPECT_NE(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
559 sdch_manager()->IsInSupportedDomain(secure_url));
560 } 567 }
561 568
562 TEST_F(SdchManagerTest, ClearDictionaryData) { 569 TEST_F(SdchManagerTest, ClearDictionaryData) {
563 std::string dictionary_domain("x.y.z.google.com"); 570 std::string dictionary_domain("x.y.z.google.com");
564 GURL blacklist_url("http://bad.chromium.org"); 571 GURL blacklist_url("http://bad.chromium.org");
565 572
566 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 573 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
567 std::string tmp_hash; 574 std::string tmp_hash;
568 std::string server_hash; 575 std::string server_hash;
569 576
570 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); 577 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
571 578
572 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 579 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
573 GURL("http://" + dictionary_domain))); 580 GURL("http://" + dictionary_domain)));
574 scoped_refptr<SdchManager::Dictionary> dictionary; 581 scoped_refptr<SdchManager::Dictionary> dictionary;
575 sdch_manager()->GetVcdiffDictionary( 582 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
576 server_hash, 583 server_hash,
577 GURL("http://" + dictionary_domain + "/random_url"), 584 GURL("http://" + dictionary_domain + "/random_url"),
578 &dictionary); 585 &dictionary));
579 EXPECT_TRUE(dictionary.get()); 586 EXPECT_TRUE(dictionary.get());
580 587
581 sdch_manager()->BlacklistDomain(GURL(blacklist_url), 588 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK);
582 SdchManager::MIN_PROBLEM_CODE); 589 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
583 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 590 sdch_manager()->IsInSupportedDomain(blacklist_url));
584 591
585 sdch_manager()->ClearData(); 592 sdch_manager()->ClearData();
586 593
587 dictionary = NULL; 594 dictionary = NULL;
588 sdch_manager()->GetVcdiffDictionary( 595 EXPECT_EQ(
589 server_hash, 596 SDCH_DICTIONARY_HASH_NOT_FOUND,
590 GURL("http://" + dictionary_domain + "/random_url"), 597 sdch_manager()->GetVcdiffDictionary(
591 &dictionary); 598 server_hash, GURL("http://" + dictionary_domain + "/random_url"),
599 &dictionary));
592 EXPECT_FALSE(dictionary.get()); 600 EXPECT_FALSE(dictionary.get());
593 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 601 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url));
594 } 602 }
595 603
596 TEST_F(SdchManagerTest, GetDictionaryNotification) { 604 TEST_F(SdchManagerTest, GetDictionaryNotification) {
597 GURL test_request_gurl(GURL("http://www.example.com/data")); 605 GURL test_request_gurl(GURL("http://www.example.com/data"));
598 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); 606 GURL test_dictionary_gurl(GURL("http://www.example.com/dict"));
599 MockSdchObserver observer; 607 MockSdchObserver observer;
600 sdch_manager()->AddObserver(&observer); 608 sdch_manager()->AddObserver(&observer);
601 609
602 EXPECT_EQ(0, observer.get_dictionary_notifications()); 610 EXPECT_EQ(0, observer.get_dictionary_notifications());
603 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); 611 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
604 EXPECT_EQ(1, observer.get_dictionary_notifications()); 612 EXPECT_EQ(1, observer.get_dictionary_notifications());
605 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); 613 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
606 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); 614 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
607 615
608 sdch_manager()->RemoveObserver(&observer); 616 sdch_manager()->RemoveObserver(&observer);
609 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); 617 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
610 EXPECT_EQ(1, observer.get_dictionary_notifications()); 618 EXPECT_EQ(1, observer.get_dictionary_notifications());
611 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); 619 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
612 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); 620 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
613 } 621 }
614 622
615 } // namespace net 623 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_net_log_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698