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

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

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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/sdch_manager.h" 11 #include "net/base/sdch_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 //------------------------------------------------------------------------------ 16 //------------------------------------------------------------------------------
17 // Provide sample data and compression results with a sample VCDIFF dictionary. 17 // Provide sample data and compression results with a sample VCDIFF dictionary.
18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
19 static const char kTestVcdiffDictionary[] = "DictionaryFor" 19 static const char kTestVcdiffDictionary[] =
20 "DictionaryFor"
20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; 21 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
21 22
22 //------------------------------------------------------------------------------ 23 //------------------------------------------------------------------------------
23 24
24 class SdchManagerTest : public testing::Test { 25 class SdchManagerTest : public testing::Test {
25 protected: 26 protected:
26 SdchManagerTest() 27 SdchManagerTest()
27 : sdch_manager_(new SdchManager), 28 : sdch_manager_(new SdchManager),
28 default_support_(false), 29 default_support_(false),
29 default_https_support_(false) { 30 default_https_support_(false) {
30 default_support_ = sdch_manager_->sdch_enabled(); 31 default_support_ = sdch_manager_->sdch_enabled();
31 default_https_support_ = sdch_manager_->secure_scheme_supported(); 32 default_https_support_ = sdch_manager_->secure_scheme_supported();
32 } 33 }
33 34
34 SdchManager* sdch_manager() { return sdch_manager_.get(); } 35 SdchManager* sdch_manager() { return sdch_manager_.get(); }
35 36
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, const GURL& gurl) {
45 const GURL& gurl) {
46 std::string list; 46 std::string list;
47 sdch_manager_->GetAvailDictionaryList(gurl, &list); 47 sdch_manager_->GetAvailDictionaryList(gurl, &list);
48 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); 48 sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
49 std::string list2; 49 std::string list2;
50 sdch_manager_->GetAvailDictionaryList(gurl, &list2); 50 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
51 51
52 // The list of hashes should change iff the addition succeeds. 52 // The list of hashes should change iff the addition succeeds.
53 return (list != list2); 53 return (list != list2);
54 } 54 }
55 55
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (exponential < 0) 153 if (exponential < 0)
154 exponential = INT_MAX; // We don't wrap. 154 exponential = INT_MAX; // We don't wrap.
155 } 155 }
156 } 156 }
157 157
158 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { 158 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) {
159 std::string dictionary_domain("x.y.z.google.com"); 159 std::string dictionary_domain("x.y.z.google.com");
160 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 160 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
161 161
162 // Perfect match should work. 162 // Perfect match should work.
163 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 163 EXPECT_TRUE(
164 GURL("http://" + dictionary_domain))); 164 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
165 } 165 }
166 166
167 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { 167 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) {
168 std::string dictionary_domain("x.y.z.google.com"); 168 std::string dictionary_domain("x.y.z.google.com");
169 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 169 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
170 170
171 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 171 EXPECT_TRUE(
172 GURL("http://" + dictionary_domain))); 172 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
173 173
174 std::string dictionary_list; 174 std::string dictionary_list;
175 // HTTP target URL can advertise dictionary. 175 // HTTP target URL can advertise dictionary.
176 sdch_manager()->GetAvailDictionaryList( 176 sdch_manager()->GetAvailDictionaryList(
177 GURL("http://" + dictionary_domain + "/test"), 177 GURL("http://" + dictionary_domain + "/test"), &dictionary_list);
178 &dictionary_list);
179 EXPECT_FALSE(dictionary_list.empty()); 178 EXPECT_FALSE(dictionary_list.empty());
180 } 179 }
181 180
182 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { 181 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) {
183 std::string dictionary_domain("x.y.z.google.com"); 182 std::string dictionary_domain("x.y.z.google.com");
184 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 183 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
185 184
186 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 185 EXPECT_TRUE(
187 GURL("http://" + dictionary_domain))); 186 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
188 187
189 std::string dictionary_list; 188 std::string dictionary_list;
190 // HTTPS target URL should NOT advertise dictionary. 189 // HTTPS target URL should NOT advertise dictionary.
191 sdch_manager()->GetAvailDictionaryList( 190 sdch_manager()->GetAvailDictionaryList(
192 GURL("https://" + dictionary_domain + "/test"), 191 GURL("https://" + dictionary_domain + "/test"), &dictionary_list);
193 &dictionary_list);
194 EXPECT_TRUE(dictionary_list.empty()); 192 EXPECT_TRUE(dictionary_list.empty());
195 } 193 }
196 194
197 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 195 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
198 std::string dictionary_domain("x.y.z.google.com"); 196 std::string dictionary_domain("x.y.z.google.com");
199 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 197 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
200 198
201 SdchManager::EnableSecureSchemeSupport(false); 199 SdchManager::EnableSecureSchemeSupport(false);
202 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 200 EXPECT_FALSE(
203 GURL("https://" + dictionary_domain))); 201 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain)));
204 SdchManager::EnableSecureSchemeSupport(true); 202 SdchManager::EnableSecureSchemeSupport(true);
205 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 203 EXPECT_TRUE(
206 GURL("https://" + dictionary_domain))); 204 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain)));
207 205
208 GURL target_url("https://" + dictionary_domain + "/test"); 206 GURL target_url("https://" + dictionary_domain + "/test");
209 std::string dictionary_list; 207 std::string dictionary_list;
210 // HTTPS target URL should advertise dictionary if secure scheme support is 208 // HTTPS target URL should advertise dictionary if secure scheme support is
211 // enabled. 209 // enabled.
212 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 210 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
213 EXPECT_FALSE(dictionary_list.empty()); 211 EXPECT_FALSE(dictionary_list.empty());
214 212
215 // Dictionary should be available. 213 // Dictionary should be available.
216 scoped_refptr<SdchManager::Dictionary> dictionary; 214 scoped_refptr<SdchManager::Dictionary> dictionary;
217 std::string client_hash; 215 std::string client_hash;
218 std::string server_hash; 216 std::string server_hash;
219 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 217 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
220 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 218 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
221 EXPECT_TRUE(dictionary.get() != NULL); 219 EXPECT_TRUE(dictionary.get() != NULL);
222 } 220 }
223 221
224 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 222 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
225 std::string dictionary_domain("x.y.z.google.com"); 223 std::string dictionary_domain("x.y.z.google.com");
226 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 224 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
227 225
228 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 226 EXPECT_TRUE(
229 GURL("http://" + dictionary_domain))); 227 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
230 228
231 GURL target_url("https://" + dictionary_domain + "/test"); 229 GURL target_url("https://" + dictionary_domain + "/test");
232 std::string dictionary_list; 230 std::string dictionary_list;
233 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 231 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
234 // secure scheme support is enabled. 232 // secure scheme support is enabled.
235 SdchManager::EnableSecureSchemeSupport(true); 233 SdchManager::EnableSecureSchemeSupport(true);
236 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 234 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
237 EXPECT_TRUE(dictionary_list.empty()); 235 EXPECT_TRUE(dictionary_list.empty());
238 236
239 scoped_refptr<SdchManager::Dictionary> dictionary; 237 scoped_refptr<SdchManager::Dictionary> dictionary;
240 std::string client_hash; 238 std::string client_hash;
241 std::string server_hash; 239 std::string server_hash;
242 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 240 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
243 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 241 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
244 EXPECT_TRUE(dictionary.get() == NULL); 242 EXPECT_TRUE(dictionary.get() == NULL);
245 } 243 }
246 244
247 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { 245 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
248 std::string dictionary_domain("x.y.z.google.com"); 246 std::string dictionary_domain("x.y.z.google.com");
249 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 247 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
250 248
251 SdchManager::EnableSecureSchemeSupport(true); 249 SdchManager::EnableSecureSchemeSupport(true);
252 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 250 EXPECT_TRUE(
253 GURL("https://" + dictionary_domain))); 251 AddSdchDictionary(dictionary_text, GURL("https://" + dictionary_domain)));
254 252
255 GURL target_url("http://" + dictionary_domain + "/test"); 253 GURL target_url("http://" + dictionary_domain + "/test");
256 std::string dictionary_list; 254 std::string dictionary_list;
257 // HTTP target URL should not advertise dictionary acquired over HTTPS even if 255 // HTTP target URL should not advertise dictionary acquired over HTTPS even if
258 // secure scheme support is enabled. 256 // secure scheme support is enabled.
259 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 257 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
260 EXPECT_TRUE(dictionary_list.empty()); 258 EXPECT_TRUE(dictionary_list.empty());
261 259
262 scoped_refptr<SdchManager::Dictionary> dictionary; 260 scoped_refptr<SdchManager::Dictionary> dictionary;
263 std::string client_hash; 261 std::string client_hash;
264 std::string server_hash; 262 std::string server_hash;
265 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 263 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
266 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 264 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
267 EXPECT_TRUE(dictionary.get() == NULL); 265 EXPECT_TRUE(dictionary.get() == NULL);
268 } 266 }
269 267
270 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 268 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
271 std::string dictionary_domain("x.y.z.google.com"); 269 std::string dictionary_domain("x.y.z.google.com");
272 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 270 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
273 271
274 // Fail the "domain match" requirement. 272 // Fail the "domain match" requirement.
275 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 273 EXPECT_FALSE(
276 GURL("http://y.z.google.com"))); 274 AddSdchDictionary(dictionary_text, GURL("http://y.z.google.com")));
277 } 275 }
278 276
279 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { 277 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) {
280 std::string dictionary_domain("x.y.z.google.com"); 278 std::string dictionary_domain("x.y.z.google.com");
281 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 279 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
282 280
283 // Fail the HD with D being the domain and H having a dot requirement. 281 // Fail the HD with D being the domain and H having a dot requirement.
284 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 282 EXPECT_FALSE(
285 GURL("http://w.x.y.z.google.com"))); 283 AddSdchDictionary(dictionary_text, GURL("http://w.x.y.z.google.com")));
286 } 284 }
287 285
288 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) { 286 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) {
289 std::string dictionary_domain("x.y.z.google.com"); 287 std::string dictionary_domain("x.y.z.google.com");
290 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 288 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
291 289
292 // Fail the HD with D being the domain and H having a dot requirement. 290 // Fail the HD with D being the domain and H having a dot requirement.
293 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 291 EXPECT_FALSE(
294 GURL("http://w.x.y.z.google.com."))); 292 AddSdchDictionary(dictionary_text, GURL("http://w.x.y.z.google.com.")));
295 } 293 }
296 294
297 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { 295 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) {
298 // Make sure that a prefix that matches the domain postfix won't confuse 296 // Make sure that a prefix that matches the domain postfix won't confuse
299 // the validation checks. 297 // the validation checks.
300 std::string dictionary_domain("www.google.com"); 298 std::string dictionary_domain("www.google.com");
301 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 299 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
302 300
303 // Fail the HD with D being the domain and H having a dot requirement. 301 // Fail the HD with D being the domain and H having a dot requirement.
304 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 302 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
305 GURL("http://www.google.com.www.google.com"))); 303 GURL("http://www.google.com.www.google.com")));
306 } 304 }
307 305
308 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { 306 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) {
309 // Make sure that a prefix that matches the domain postfix won't confuse 307 // Make sure that a prefix that matches the domain postfix won't confuse
310 // the validation checks. 308 // the validation checks.
311 std::string dictionary_domain(".google.com"); 309 std::string dictionary_domain(".google.com");
312 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 310 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
313 311
314 // Verify that a leading dot in the domain is acceptable, as long as the host 312 // Verify that a leading dot in the domain is acceptable, as long as the host
315 // name does not contain any dots preceding the matched domain name. 313 // name does not contain any dots preceding the matched domain name.
316 EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))) ; 314 EXPECT_TRUE(
315 AddSdchDictionary(dictionary_text, GURL("http://www.google.com")));
317 } 316 }
318 317
319 TEST_F(SdchManagerTest, 318 TEST_F(SdchManagerTest,
320 CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) { 319 CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) {
321 // Make sure that a prefix that matches the domain postfix won't confuse 320 // Make sure that a prefix that matches the domain postfix won't confuse
322 // the validation checks. 321 // the validation checks.
323 std::string dictionary_domain(".google.com"); 322 std::string dictionary_domain(".google.com");
324 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 323 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
325 324
326 // Verify that a leading dot in the domain is acceptable, as long as the host 325 // Verify that a leading dot in the domain is acceptable, as long as the host
327 // name does not contain any dots preceding the matched domain name. 326 // name does not contain any dots preceding the matched domain name.
328 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 327 EXPECT_TRUE(
329 GURL("http://www.google.com."))); 328 AddSdchDictionary(dictionary_text, GURL("http://www.google.com.")));
330 } 329 }
331 330
332 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) { 331 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) {
333 // Make sure that a prefix that matches the domain postfix won't confuse 332 // Make sure that a prefix that matches the domain postfix won't confuse
334 // the validation checks. 333 // the validation checks.
335 std::string dictionary_domain(".google.com"); 334 std::string dictionary_domain(".google.com");
336 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 335 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
337 336
338 // Verify that a leading dot in the domain does not affect the name containing 337 // Verify that a leading dot in the domain does not affect the name containing
339 // dots failure. 338 // dots failure.
(...skipping 12 matching lines...) Expand all
352 GURL("http://www.subdomain.google.com."))); 351 GURL("http://www.subdomain.google.com.")));
353 } 352 }
354 353
355 // Make sure the order of the tests is not helping us or confusing things. 354 // Make sure the order of the tests is not helping us or confusing things.
356 // See test CanSetExactMatchDictionary above for first try. 355 // See test CanSetExactMatchDictionary above for first try.
357 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { 356 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) {
358 std::string dictionary_domain("x.y.z.google.com"); 357 std::string dictionary_domain("x.y.z.google.com");
359 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 358 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
360 359
361 // Perfect match should *STILL* work. 360 // Perfect match should *STILL* work.
362 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 361 EXPECT_TRUE(
363 GURL("http://" + dictionary_domain))); 362 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
364 } 363 }
365 364
366 // Make sure the DOS protection precludes the addition of too many dictionaries. 365 // Make sure the DOS protection precludes the addition of too many dictionaries.
367 TEST_F(SdchManagerTest, TooManyDictionaries) { 366 TEST_F(SdchManagerTest, TooManyDictionaries) {
368 std::string dictionary_domain(".google.com"); 367 std::string dictionary_domain(".google.com");
369 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 368 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
370 369
371 for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) { 370 for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) {
372 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 371 EXPECT_TRUE(
373 GURL("http://www.google.com"))); 372 AddSdchDictionary(dictionary_text, GURL("http://www.google.com")));
374 dictionary_text += " "; // Create dictionary with different SHA signature. 373 dictionary_text += " "; // Create dictionary with different SHA signature.
375 } 374 }
376 EXPECT_FALSE( 375 EXPECT_FALSE(
377 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); 376 AddSdchDictionary(dictionary_text, GURL("http://www.google.com")));
378 } 377 }
379 378
380 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { 379 TEST_F(SdchManagerTest, DictionaryNotTooLarge) {
381 std::string dictionary_domain(".google.com"); 380 std::string dictionary_domain(".google.com");
382 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 381 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
383 382
384 dictionary_text.append( 383 dictionary_text.append(
385 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); 384 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' ');
386 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 385 EXPECT_TRUE(
387 GURL("http://" + dictionary_domain))); 386 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
388 } 387 }
389 388
390 TEST_F(SdchManagerTest, DictionaryTooLarge) { 389 TEST_F(SdchManagerTest, DictionaryTooLarge) {
391 std::string dictionary_domain(".google.com"); 390 std::string dictionary_domain(".google.com");
392 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 391 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
393 392
394 dictionary_text.append( 393 dictionary_text.append(
395 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); 394 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' ');
396 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 395 EXPECT_FALSE(
397 GURL("http://" + dictionary_domain))); 396 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
398 } 397 }
399 398
400 TEST_F(SdchManagerTest, PathMatch) { 399 TEST_F(SdchManagerTest, PathMatch) {
401 bool (*PathMatch)(const std::string& path, const std::string& restriction) = 400 bool (*PathMatch)(const std::string& path, const std::string& restriction) =
402 SdchManager::Dictionary::PathMatch; 401 SdchManager::Dictionary::PathMatch;
403 // Perfect match is supported. 402 // Perfect match is supported.
404 EXPECT_TRUE(PathMatch("/search", "/search")); 403 EXPECT_TRUE(PathMatch("/search", "/search"));
405 EXPECT_TRUE(PathMatch("/search/", "/search/")); 404 EXPECT_TRUE(PathMatch("/search/", "/search/"));
406 405
407 // Prefix only works if last character of restriction is a slash, or first 406 // Prefix only works if last character of restriction is a slash, or first
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // can't get them from the other. 485 // can't get them from the other.
487 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, 486 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
488 GURL("http://" + dictionary_domain_1))); 487 GURL("http://" + dictionary_domain_1)));
489 scoped_refptr<SdchManager::Dictionary> dictionary; 488 scoped_refptr<SdchManager::Dictionary> dictionary;
490 sdch_manager()->GetVcdiffDictionary( 489 sdch_manager()->GetVcdiffDictionary(
491 server_hash_1, 490 server_hash_1,
492 GURL("http://" + dictionary_domain_1 + "/random_url"), 491 GURL("http://" + dictionary_domain_1 + "/random_url"),
493 &dictionary); 492 &dictionary);
494 EXPECT_TRUE(dictionary.get()); 493 EXPECT_TRUE(dictionary.get());
495 494
496 second_manager.AddSdchDictionary( 495 second_manager.AddSdchDictionary(dictionary_text_2,
497 dictionary_text_2, GURL("http://" + dictionary_domain_2)); 496 GURL("http://" + dictionary_domain_2));
498 second_manager.GetVcdiffDictionary( 497 second_manager.GetVcdiffDictionary(
499 server_hash_2, 498 server_hash_2,
500 GURL("http://" + dictionary_domain_2 + "/random_url"), 499 GURL("http://" + dictionary_domain_2 + "/random_url"),
501 &dictionary); 500 &dictionary);
502 EXPECT_TRUE(dictionary.get()); 501 EXPECT_TRUE(dictionary.get());
503 502
504 sdch_manager()->GetVcdiffDictionary( 503 sdch_manager()->GetVcdiffDictionary(
505 server_hash_2, 504 server_hash_2,
506 GURL("http://" + dictionary_domain_2 + "/random_url"), 505 GURL("http://" + dictionary_domain_2 + "/random_url"),
507 &dictionary); 506 &dictionary);
(...skipping 21 matching lines...) Expand all
529 TEST_F(SdchManagerTest, ClearDictionaryData) { 528 TEST_F(SdchManagerTest, ClearDictionaryData) {
530 std::string dictionary_domain("x.y.z.google.com"); 529 std::string dictionary_domain("x.y.z.google.com");
531 GURL blacklist_url("http://bad.chromium.org"); 530 GURL blacklist_url("http://bad.chromium.org");
532 531
533 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 532 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
534 std::string tmp_hash; 533 std::string tmp_hash;
535 std::string server_hash; 534 std::string server_hash;
536 535
537 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); 536 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
538 537
539 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 538 EXPECT_TRUE(
540 GURL("http://" + dictionary_domain))); 539 AddSdchDictionary(dictionary_text, GURL("http://" + dictionary_domain)));
541 scoped_refptr<SdchManager::Dictionary> dictionary; 540 scoped_refptr<SdchManager::Dictionary> dictionary;
542 sdch_manager()->GetVcdiffDictionary( 541 sdch_manager()->GetVcdiffDictionary(
543 server_hash, 542 server_hash,
544 GURL("http://" + dictionary_domain + "/random_url"), 543 GURL("http://" + dictionary_domain + "/random_url"),
545 &dictionary); 544 &dictionary);
546 EXPECT_TRUE(dictionary.get()); 545 EXPECT_TRUE(dictionary.get());
547 546
548 sdch_manager()->BlacklistDomain(GURL(blacklist_url), 547 sdch_manager()->BlacklistDomain(GURL(blacklist_url),
549 SdchManager::MIN_PROBLEM_CODE); 548 SdchManager::MIN_PROBLEM_CODE);
550 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 549 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url));
551 550
552 sdch_manager()->ClearData(); 551 sdch_manager()->ClearData();
553 552
554 dictionary = NULL; 553 dictionary = NULL;
555 sdch_manager()->GetVcdiffDictionary( 554 sdch_manager()->GetVcdiffDictionary(
556 server_hash, 555 server_hash,
557 GURL("http://" + dictionary_domain + "/random_url"), 556 GURL("http://" + dictionary_domain + "/random_url"),
558 &dictionary); 557 &dictionary);
559 EXPECT_FALSE(dictionary.get()); 558 EXPECT_FALSE(dictionary.get());
560 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 559 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
561 } 560 }
562 561
563 } // namespace net 562 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698