OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 324 |
325 // Create a store that loads session cookies and test that the session cookie | 325 // Create a store that loads session cookies and test that the session cookie |
326 // was loaded. | 326 // was loaded. |
327 CanonicalCookieVector cookies; | 327 CanonicalCookieVector cookies; |
328 CreateAndLoad(true, &cookies); | 328 CreateAndLoad(true, &cookies); |
329 | 329 |
330 ASSERT_EQ(1U, cookies.size()); | 330 ASSERT_EQ(1U, cookies.size()); |
331 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); | 331 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); |
332 ASSERT_STREQ("C", cookies[0]->Name().c_str()); | 332 ASSERT_STREQ("C", cookies[0]->Name().c_str()); |
333 ASSERT_STREQ("D", cookies[0]->Value().c_str()); | 333 ASSERT_STREQ("D", cookies[0]->Value().c_str()); |
334 ASSERT_EQ(net::PRIORITY_DEFAULT, cookies[0]->Priority()); | |
334 | 335 |
335 STLDeleteElements(&cookies); | 336 STLDeleteElements(&cookies); |
336 } | 337 } |
337 | 338 |
338 // Test loading old session cookies from the disk. | 339 // Test loading old session cookies from the disk. |
339 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { | 340 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { |
340 InitializeStore(true); | 341 InitializeStore(true); |
341 | 342 |
342 // Add a session cookie. | 343 // Add a session cookie. |
343 store_->AddCookie( | 344 store_->AddCookie( |
(...skipping 29 matching lines...) Expand all Loading... | |
373 // Add a session cookie. | 374 // Add a session cookie. |
374 store_->AddCookie( | 375 store_->AddCookie( |
375 net::CanonicalCookie( | 376 net::CanonicalCookie( |
376 GURL(), kSessionName, "val", "sessioncookie.com", "/", | 377 GURL(), kSessionName, "val", "sessioncookie.com", "/", |
377 base::Time::Now(), base::Time(), base::Time::Now(), false, false, | 378 base::Time::Now(), base::Time(), base::Time::Now(), false, false, |
378 net::PRIORITY_DEFAULT)); | 379 net::PRIORITY_DEFAULT)); |
379 // Add a persistent cookie. | 380 // Add a persistent cookie. |
380 store_->AddCookie( | 381 store_->AddCookie( |
381 net::CanonicalCookie( | 382 net::CanonicalCookie( |
382 GURL(), kPersistentName, "val", "sessioncookie.com", "/", | 383 GURL(), kPersistentName, "val", "sessioncookie.com", "/", |
383 base::Time::Now() - base::TimeDelta::FromDays(1), base::Time::Now(), | 384 base::Time::Now() - base::TimeDelta::FromDays(1), |
385 base::Time::Now() + base::TimeDelta::FromDays(1), | |
384 base::Time::Now(), false, false, | 386 base::Time::Now(), false, false, |
385 net::PRIORITY_DEFAULT)); | 387 net::PRIORITY_DEFAULT)); |
386 | 388 |
387 // Create a store that loads session cookie and test that the the IsPersistent | 389 // Force the store to write its data to the disk. |
390 DestroyStore(); | |
Roger McFarlane (Chromium)
2013/04/18 18:54:29
This seemed to be missing from the test (on compar
| |
391 | |
392 // Create a store that loads session cookie and test that the IsPersistent | |
388 // attribute is restored. | 393 // attribute is restored. |
389 CanonicalCookieVector cookies; | 394 CanonicalCookieVector cookies; |
390 CreateAndLoad(true, &cookies); | 395 CreateAndLoad(true, &cookies); |
391 ASSERT_EQ(2U, cookies.size()); | 396 ASSERT_EQ(2U, cookies.size()); |
392 | 397 |
393 std::map<std::string, net::CanonicalCookie*> cookie_map; | 398 std::map<std::string, net::CanonicalCookie*> cookie_map; |
394 for (CanonicalCookieVector::const_iterator it = cookies.begin(); | 399 for (CanonicalCookieVector::const_iterator it = cookies.begin(); |
395 it != cookies.end(); | 400 it != cookies.end(); |
396 ++it) { | 401 ++it) { |
397 cookie_map[(*it)->Name()] = *it; | 402 cookie_map[(*it)->Name()] = *it; |
398 } | 403 } |
399 | 404 |
400 std::map<std::string, net::CanonicalCookie*>::const_iterator it = | 405 std::map<std::string, net::CanonicalCookie*>::const_iterator it = |
401 cookie_map.find(kSessionName); | 406 cookie_map.find(kSessionName); |
402 ASSERT_TRUE(it != cookie_map.end()); | 407 ASSERT_TRUE(it != cookie_map.end()); |
403 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); | 408 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); |
404 | 409 |
405 it = cookie_map.find(kPersistentName); | 410 it = cookie_map.find(kPersistentName); |
406 ASSERT_TRUE(it != cookie_map.end()); | 411 ASSERT_TRUE(it != cookie_map.end()); |
407 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); | 412 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); |
408 | 413 |
409 STLDeleteElements(&cookies); | 414 STLDeleteElements(&cookies); |
410 } | 415 } |
411 | 416 |
417 TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { | |
418 static const char kLowName[] = "low"; | |
419 static const char kMediumName[] = "medium"; | |
420 static const char kHighName[] = "high"; | |
421 static const char kDefaultName[] = "default"; | |
422 static const char kCookieDomain[] = "sessioncookie.com"; | |
423 static const char kCookieValue[] = "value"; | |
424 static const char kCookiePath[] = "/"; | |
425 | |
426 InitializeStore(true); | |
427 | |
428 // Add a low-priority persistent cookie. | |
429 store_->AddCookie( | |
430 net::CanonicalCookie( | |
431 GURL(), kLowName, kCookieValue, kCookieDomain, kCookiePath, | |
432 base::Time::Now() - base::TimeDelta::FromMinutes(1), | |
433 base::Time::Now() + base::TimeDelta::FromDays(1), | |
434 base::Time::Now(), false, false, | |
435 net::PRIORITY_LOW)); | |
436 | |
437 // Add a medium-priority persistent cookie. | |
438 store_->AddCookie( | |
439 net::CanonicalCookie( | |
440 GURL(), kMediumName, kCookieValue, kCookieDomain, kCookiePath, | |
441 base::Time::Now() - base::TimeDelta::FromMinutes(2), | |
442 base::Time::Now() + base::TimeDelta::FromDays(1), | |
443 base::Time::Now(), false, false, | |
444 net::PRIORITY_MEDIUM)); | |
445 | |
446 // Add a high-priority peristent cookie. | |
447 store_->AddCookie( | |
448 net::CanonicalCookie( | |
449 GURL(), kHighName, kCookieValue, kCookieDomain, kCookiePath, | |
450 base::Time::Now() - base::TimeDelta::FromMinutes(3), | |
451 base::Time::Now() + base::TimeDelta::FromDays(1), | |
452 base::Time::Now(), false, false, | |
453 net::PRIORITY_HIGH)); | |
454 | |
455 // Add a default-priority persistent cookie. | |
erikwright (departed)
2013/04/18 19:34:05
I would remove this one - it's not testing anythin
Roger McFarlane (Chromium)
2013/04/19 20:53:03
Done.
| |
456 store_->AddCookie( | |
457 net::CanonicalCookie( | |
458 GURL(), kDefaultName, kCookieValue, kCookieDomain, kCookiePath, | |
459 base::Time::Now() - base::TimeDelta::FromMinutes(4), | |
460 base::Time::Now() + base::TimeDelta::FromDays(1), | |
461 base::Time::Now(), false, false, | |
462 net::PRIORITY_DEFAULT)); | |
463 | |
464 // Force the store to write its data to the disk. | |
465 DestroyStore(); | |
466 | |
467 // Create a store that loads session cookie and test that the priority | |
468 // attribute values are restored. | |
469 CanonicalCookieVector cookies; | |
470 CreateAndLoad(true, &cookies); | |
471 ASSERT_EQ(4U, cookies.size()); | |
472 | |
473 // Put the cookies into a map, by name, so we can easily find them. | |
474 std::map<std::string, net::CanonicalCookie*> cookie_map; | |
475 for (CanonicalCookieVector::const_iterator it = cookies.begin(); | |
476 it != cookies.end(); | |
477 ++it) { | |
478 cookie_map[(*it)->Name()] = *it; | |
479 } | |
480 | |
481 // Validate that each cookie has the correct priority. | |
482 std::map<std::string, net::CanonicalCookie*>::const_iterator it = | |
483 cookie_map.find(kLowName); | |
484 ASSERT_TRUE(it != cookie_map.end()); | |
485 EXPECT_EQ(net::PRIORITY_LOW, cookie_map[kLowName]->Priority()); | |
486 | |
487 it = cookie_map.find(kMediumName); | |
488 ASSERT_TRUE(it != cookie_map.end()); | |
489 EXPECT_EQ(net::PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); | |
490 | |
491 it = cookie_map.find(kHighName); | |
492 ASSERT_TRUE(it != cookie_map.end()); | |
493 EXPECT_EQ(net::PRIORITY_HIGH, cookie_map[kHighName]->Priority()); | |
494 | |
495 it = cookie_map.find(kDefaultName); | |
496 ASSERT_TRUE(it != cookie_map.end()); | |
497 EXPECT_EQ(net::PRIORITY_DEFAULT, cookie_map[kDefaultName]->Priority()); | |
498 | |
499 STLDeleteElements(&cookies); | |
500 } | |
501 | |
412 } // namespace content | 502 } // namespace content |
OLD | NEW |