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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" | 5 #include "net/extras/sqlite/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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 DestroyStore(); | 222 DestroyStore(); |
223 | 223 |
224 // Load up the store and verify that it has good data in it. | 224 // Load up the store and verify that it has good data in it. |
225 CanonicalCookieVector cookies; | 225 CanonicalCookieVector cookies; |
226 CreateAndLoad(false, false, &cookies); | 226 CreateAndLoad(false, false, &cookies); |
227 ASSERT_EQ(1U, cookies.size()); | 227 ASSERT_EQ(1U, cookies.size()); |
228 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 228 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
229 ASSERT_STREQ("A", cookies[0]->Name().c_str()); | 229 ASSERT_STREQ("A", cookies[0]->Name().c_str()); |
230 ASSERT_STREQ("B", cookies[0]->Value().c_str()); | 230 ASSERT_STREQ("B", cookies[0]->Value().c_str()); |
231 DestroyStore(); | 231 DestroyStore(); |
232 STLDeleteElements(&cookies); | 232 base::STLDeleteElements(&cookies); |
233 | 233 |
234 // Now corrupt the meta table. | 234 // Now corrupt the meta table. |
235 { | 235 { |
236 sql::Connection db; | 236 sql::Connection db; |
237 ASSERT_TRUE(db.Open(temp_dir_.path().Append(kCookieFilename))); | 237 ASSERT_TRUE(db.Open(temp_dir_.path().Append(kCookieFilename))); |
238 sql::MetaTable meta_table_; | 238 sql::MetaTable meta_table_; |
239 meta_table_.Init(&db, 1, 1); | 239 meta_table_.Init(&db, 1, 1); |
240 ASSERT_TRUE(db.Execute("DELETE FROM meta")); | 240 ASSERT_TRUE(db.Execute("DELETE FROM meta")); |
241 db.Close(); | 241 db.Close(); |
242 } | 242 } |
243 | 243 |
244 // Upon loading, the database should be reset to a good, blank state. | 244 // Upon loading, the database should be reset to a good, blank state. |
245 CreateAndLoad(false, false, &cookies); | 245 CreateAndLoad(false, false, &cookies); |
246 ASSERT_EQ(0U, cookies.size()); | 246 ASSERT_EQ(0U, cookies.size()); |
247 | 247 |
248 // Verify that, after, recovery, the database persists properly. | 248 // Verify that, after, recovery, the database persists properly. |
249 AddCookie(GURL("http://foo.bar"), "X", "Y", std::string(), "/", | 249 AddCookie(GURL("http://foo.bar"), "X", "Y", std::string(), "/", |
250 base::Time::Now()); | 250 base::Time::Now()); |
251 DestroyStore(); | 251 DestroyStore(); |
252 CreateAndLoad(false, false, &cookies); | 252 CreateAndLoad(false, false, &cookies); |
253 ASSERT_EQ(1U, cookies.size()); | 253 ASSERT_EQ(1U, cookies.size()); |
254 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 254 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
255 ASSERT_STREQ("X", cookies[0]->Name().c_str()); | 255 ASSERT_STREQ("X", cookies[0]->Name().c_str()); |
256 ASSERT_STREQ("Y", cookies[0]->Value().c_str()); | 256 ASSERT_STREQ("Y", cookies[0]->Value().c_str()); |
257 STLDeleteElements(&cookies); | 257 base::STLDeleteElements(&cookies); |
258 } | 258 } |
259 | 259 |
260 // Test if data is stored as expected in the SQLite database. | 260 // Test if data is stored as expected in the SQLite database. |
261 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { | 261 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { |
262 InitializeStore(false, false); | 262 InitializeStore(false, false); |
263 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", | 263 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", |
264 base::Time::Now()); | 264 base::Time::Now()); |
265 // Replace the store effectively destroying the current one and forcing it | 265 // Replace the store effectively destroying the current one and forcing it |
266 // to write its data to disk. Then we can see if after loading it again it | 266 // to write its data to disk. Then we can see if after loading it again it |
267 // is still there. | 267 // is still there. |
268 DestroyStore(); | 268 DestroyStore(); |
269 // Reload and test for persistence | 269 // Reload and test for persistence |
270 CanonicalCookieVector cookies; | 270 CanonicalCookieVector cookies; |
271 CreateAndLoad(false, false, &cookies); | 271 CreateAndLoad(false, false, &cookies); |
272 ASSERT_EQ(1U, cookies.size()); | 272 ASSERT_EQ(1U, cookies.size()); |
273 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 273 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
274 ASSERT_STREQ("A", cookies[0]->Name().c_str()); | 274 ASSERT_STREQ("A", cookies[0]->Name().c_str()); |
275 ASSERT_STREQ("B", cookies[0]->Value().c_str()); | 275 ASSERT_STREQ("B", cookies[0]->Value().c_str()); |
276 | 276 |
277 // Now delete the cookie and check persistence again. | 277 // Now delete the cookie and check persistence again. |
278 store_->DeleteCookie(*cookies[0]); | 278 store_->DeleteCookie(*cookies[0]); |
279 DestroyStore(); | 279 DestroyStore(); |
280 STLDeleteElements(&cookies); | 280 base::STLDeleteElements(&cookies); |
281 | 281 |
282 // Reload and check if the cookie has been removed. | 282 // Reload and check if the cookie has been removed. |
283 CreateAndLoad(false, false, &cookies); | 283 CreateAndLoad(false, false, &cookies); |
284 ASSERT_EQ(0U, cookies.size()); | 284 ASSERT_EQ(0U, cookies.size()); |
285 } | 285 } |
286 | 286 |
287 TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { | 287 TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { |
288 // Initialize the cookie store with 3 persistent cookies, 5 transient | 288 // Initialize the cookie store with 3 persistent cookies, 5 transient |
289 // cookies. | 289 // cookies. |
290 InitializeStore(false, false); | 290 InitializeStore(false, false); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // Now the DB-thread queue contains: | 339 // Now the DB-thread queue contains: |
340 // (active:) | 340 // (active:) |
341 // 1. Wait (on db_event) | 341 // 1. Wait (on db_event) |
342 // (pending:) | 342 // (pending:) |
343 // 2. "Init And Chain-Load First Domain" | 343 // 2. "Init And Chain-Load First Domain" |
344 // 3. Add Cookie (c.com) | 344 // 3. Add Cookie (c.com) |
345 // 4. Flush Cookie (c.com) | 345 // 4. Flush Cookie (c.com) |
346 db_thread_event_.Signal(); | 346 db_thread_event_.Signal(); |
347 event.Wait(); | 347 event.Wait(); |
348 loaded_event_.Wait(); | 348 loaded_event_.Wait(); |
349 STLDeleteElements(&cookies_); | 349 base::STLDeleteElements(&cookies_); |
350 DestroyStore(); | 350 DestroyStore(); |
351 | 351 |
352 // Load the store a third time, this time restoring session cookies. The | 352 // Load the store a third time, this time restoring session cookies. The |
353 // store should contain exactly 4 cookies: the 3 persistent, and "c.com", | 353 // store should contain exactly 4 cookies: the 3 persistent, and "c.com", |
354 // which was added during the second cookie store load. | 354 // which was added during the second cookie store load. |
355 store_ = new SQLitePersistentCookieStore( | 355 store_ = new SQLitePersistentCookieStore( |
356 temp_dir_.path().Append(kCookieFilename), client_task_runner(), | 356 temp_dir_.path().Append(kCookieFilename), client_task_runner(), |
357 background_task_runner(), true, nullptr); | 357 background_task_runner(), true, nullptr); |
358 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, | 358 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
359 base::Unretained(this))); | 359 base::Unretained(this))); |
360 loaded_event_.Wait(); | 360 loaded_event_.Wait(); |
361 ASSERT_EQ(4u, cookies_.size()); | 361 ASSERT_EQ(4u, cookies_.size()); |
362 STLDeleteElements(&cookies_); | 362 base::STLDeleteElements(&cookies_); |
363 } | 363 } |
364 | 364 |
365 // Test that priority load of cookies for a specfic domain key could be | 365 // Test that priority load of cookies for a specfic domain key could be |
366 // completed before the entire store is loaded | 366 // completed before the entire store is loaded |
367 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { | 367 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
368 InitializeStore(false, false); | 368 InitializeStore(false, false); |
369 base::Time t = base::Time::Now(); | 369 base::Time t = base::Time::Now(); |
370 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", t); | 370 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", t); |
371 t += base::TimeDelta::FromInternalValue(10); | 371 t += base::TimeDelta::FromInternalValue(10); |
372 AddCookie(GURL("http://www.aaa.com"), "A", "B", std::string(), "/", t); | 372 AddCookie(GURL("http://www.aaa.com"), "A", "B", std::string(), "/", t); |
(...skipping 29 matching lines...) Expand all Loading... |
402 // 3. Priority Load (aaa.com) | 402 // 3. Priority Load (aaa.com) |
403 // 4. Wait (on db_event) | 403 // 4. Wait (on db_event) |
404 db_thread_event_.Signal(); | 404 db_thread_event_.Signal(); |
405 key_loaded_event_.Wait(); | 405 key_loaded_event_.Wait(); |
406 ASSERT_EQ(loaded_event_.IsSignaled(), false); | 406 ASSERT_EQ(loaded_event_.IsSignaled(), false); |
407 std::set<std::string> cookies_loaded; | 407 std::set<std::string> cookies_loaded; |
408 for (CanonicalCookieVector::const_iterator it = cookies_.begin(); | 408 for (CanonicalCookieVector::const_iterator it = cookies_.begin(); |
409 it != cookies_.end(); ++it) { | 409 it != cookies_.end(); ++it) { |
410 cookies_loaded.insert((*it)->Domain().c_str()); | 410 cookies_loaded.insert((*it)->Domain().c_str()); |
411 } | 411 } |
412 STLDeleteElements(&cookies_); | 412 base::STLDeleteElements(&cookies_); |
413 ASSERT_GT(4U, cookies_loaded.size()); | 413 ASSERT_GT(4U, cookies_loaded.size()); |
414 ASSERT_EQ(true, cookies_loaded.find("www.aaa.com") != cookies_loaded.end()); | 414 ASSERT_EQ(true, cookies_loaded.find("www.aaa.com") != cookies_loaded.end()); |
415 ASSERT_EQ(true, | 415 ASSERT_EQ(true, |
416 cookies_loaded.find("travel.aaa.com") != cookies_loaded.end()); | 416 cookies_loaded.find("travel.aaa.com") != cookies_loaded.end()); |
417 | 417 |
418 db_thread_event_.Signal(); | 418 db_thread_event_.Signal(); |
419 loaded_event_.Wait(); | 419 loaded_event_.Wait(); |
420 for (CanonicalCookieVector::const_iterator it = cookies_.begin(); | 420 for (CanonicalCookieVector::const_iterator it = cookies_.begin(); |
421 it != cookies_.end(); ++it) { | 421 it != cookies_.end(); ++it) { |
422 cookies_loaded.insert((*it)->Domain().c_str()); | 422 cookies_loaded.insert((*it)->Domain().c_str()); |
423 } | 423 } |
424 ASSERT_EQ(4U, cookies_loaded.size()); | 424 ASSERT_EQ(4U, cookies_loaded.size()); |
425 ASSERT_EQ(cookies_loaded.find("foo.bar") != cookies_loaded.end(), true); | 425 ASSERT_EQ(cookies_loaded.find("foo.bar") != cookies_loaded.end(), true); |
426 ASSERT_EQ(cookies_loaded.find("www.bbb.com") != cookies_loaded.end(), true); | 426 ASSERT_EQ(cookies_loaded.find("www.bbb.com") != cookies_loaded.end(), true); |
427 STLDeleteElements(&cookies_); | 427 base::STLDeleteElements(&cookies_); |
428 } | 428 } |
429 | 429 |
430 // Test that we can force the database to be written by calling Flush(). | 430 // Test that we can force the database to be written by calling Flush(). |
431 TEST_F(SQLitePersistentCookieStoreTest, TestFlush) { | 431 TEST_F(SQLitePersistentCookieStoreTest, TestFlush) { |
432 InitializeStore(false, false); | 432 InitializeStore(false, false); |
433 // File timestamps don't work well on all platforms, so we'll determine | 433 // File timestamps don't work well on all platforms, so we'll determine |
434 // whether the DB file has been modified by checking its size. | 434 // whether the DB file has been modified by checking its size. |
435 base::FilePath path = temp_dir_.path().Append(kCookieFilename); | 435 base::FilePath path = temp_dir_.path().Append(kCookieFilename); |
436 base::File::Info info; | 436 base::File::Info info; |
437 ASSERT_TRUE(base::GetFileInfo(path, &info)); | 437 ASSERT_TRUE(base::GetFileInfo(path, &info)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 // was loaded. | 470 // was loaded. |
471 CanonicalCookieVector cookies; | 471 CanonicalCookieVector cookies; |
472 CreateAndLoad(false, true, &cookies); | 472 CreateAndLoad(false, true, &cookies); |
473 | 473 |
474 ASSERT_EQ(1U, cookies.size()); | 474 ASSERT_EQ(1U, cookies.size()); |
475 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); | 475 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); |
476 ASSERT_STREQ("C", cookies[0]->Name().c_str()); | 476 ASSERT_STREQ("C", cookies[0]->Name().c_str()); |
477 ASSERT_STREQ("D", cookies[0]->Value().c_str()); | 477 ASSERT_STREQ("D", cookies[0]->Value().c_str()); |
478 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); | 478 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); |
479 | 479 |
480 STLDeleteElements(&cookies); | 480 base::STLDeleteElements(&cookies); |
481 } | 481 } |
482 | 482 |
483 // Test loading old session cookies from the disk. | 483 // Test loading old session cookies from the disk. |
484 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { | 484 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { |
485 InitializeStore(false, true); | 485 InitializeStore(false, true); |
486 | 486 |
487 // Add a session cookie. | 487 // Add a session cookie. |
488 store_->AddCookie(*CanonicalCookie::Create( | 488 store_->AddCookie(*CanonicalCookie::Create( |
489 GURL("http://sessioncookie.com"), "C", "D", std::string(), "/", | 489 GURL("http://sessioncookie.com"), "C", "D", std::string(), "/", |
490 base::Time::Now(), base::Time(), false, false, | 490 base::Time::Now(), base::Time(), false, false, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 543 |
544 std::map<std::string, CanonicalCookie*>::const_iterator it = | 544 std::map<std::string, CanonicalCookie*>::const_iterator it = |
545 cookie_map.find(kSessionName); | 545 cookie_map.find(kSessionName); |
546 ASSERT_TRUE(it != cookie_map.end()); | 546 ASSERT_TRUE(it != cookie_map.end()); |
547 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); | 547 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); |
548 | 548 |
549 it = cookie_map.find(kPersistentName); | 549 it = cookie_map.find(kPersistentName); |
550 ASSERT_TRUE(it != cookie_map.end()); | 550 ASSERT_TRUE(it != cookie_map.end()); |
551 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); | 551 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); |
552 | 552 |
553 STLDeleteElements(&cookies); | 553 base::STLDeleteElements(&cookies); |
554 } | 554 } |
555 | 555 |
556 TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { | 556 TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { |
557 static const char kURL[] = "http://sessioncookie.com"; | 557 static const char kURL[] = "http://sessioncookie.com"; |
558 static const char kLowName[] = "low"; | 558 static const char kLowName[] = "low"; |
559 static const char kMediumName[] = "medium"; | 559 static const char kMediumName[] = "medium"; |
560 static const char kHighName[] = "high"; | 560 static const char kHighName[] = "high"; |
561 static const char kCookieValue[] = "value"; | 561 static const char kCookieValue[] = "value"; |
562 static const char kCookiePath[] = "/"; | 562 static const char kCookiePath[] = "/"; |
563 | 563 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 EXPECT_EQ(COOKIE_PRIORITY_LOW, cookie_map[kLowName]->Priority()); | 607 EXPECT_EQ(COOKIE_PRIORITY_LOW, cookie_map[kLowName]->Priority()); |
608 | 608 |
609 it = cookie_map.find(kMediumName); | 609 it = cookie_map.find(kMediumName); |
610 ASSERT_TRUE(it != cookie_map.end()); | 610 ASSERT_TRUE(it != cookie_map.end()); |
611 EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); | 611 EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); |
612 | 612 |
613 it = cookie_map.find(kHighName); | 613 it = cookie_map.find(kHighName); |
614 ASSERT_TRUE(it != cookie_map.end()); | 614 ASSERT_TRUE(it != cookie_map.end()); |
615 EXPECT_EQ(COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); | 615 EXPECT_EQ(COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); |
616 | 616 |
617 STLDeleteElements(&cookies); | 617 base::STLDeleteElements(&cookies); |
618 } | 618 } |
619 | 619 |
620 TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { | 620 TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { |
621 const char kURL[] = "http://sessioncookie.com"; | 621 const char kURL[] = "http://sessioncookie.com"; |
622 const char kNoneName[] = "none"; | 622 const char kNoneName[] = "none"; |
623 const char kLaxName[] = "lax"; | 623 const char kLaxName[] = "lax"; |
624 const char kStrictName[] = "strict"; | 624 const char kStrictName[] = "strict"; |
625 const char kCookieValue[] = "value"; | 625 const char kCookieValue[] = "value"; |
626 const char kCookiePath[] = "/"; | 626 const char kCookiePath[] = "/"; |
627 | 627 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 // Validate that each cookie has the correct SameSite. | 665 // Validate that each cookie has the correct SameSite. |
666 ASSERT_EQ(1u, cookie_map.count(kNoneName)); | 666 ASSERT_EQ(1u, cookie_map.count(kNoneName)); |
667 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie_map[kNoneName]->SameSite()); | 667 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie_map[kNoneName]->SameSite()); |
668 | 668 |
669 ASSERT_EQ(1u, cookie_map.count(kLaxName)); | 669 ASSERT_EQ(1u, cookie_map.count(kLaxName)); |
670 EXPECT_EQ(CookieSameSite::LAX_MODE, cookie_map[kLaxName]->SameSite()); | 670 EXPECT_EQ(CookieSameSite::LAX_MODE, cookie_map[kLaxName]->SameSite()); |
671 | 671 |
672 ASSERT_EQ(1u, cookie_map.count(kStrictName)); | 672 ASSERT_EQ(1u, cookie_map.count(kStrictName)); |
673 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie_map[kStrictName]->SameSite()); | 673 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie_map[kStrictName]->SameSite()); |
674 | 674 |
675 STLDeleteElements(&cookies); | 675 base::STLDeleteElements(&cookies); |
676 } | 676 } |
677 | 677 |
678 TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { | 678 TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { |
679 CanonicalCookieVector cookies; | 679 CanonicalCookieVector cookies; |
680 | 680 |
681 // Create unencrypted cookie store and write something to it. | 681 // Create unencrypted cookie store and write something to it. |
682 InitializeStore(false, false); | 682 InitializeStore(false, false); |
683 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", | 683 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", |
684 base::Time::Now()); | 684 base::Time::Now()); |
685 DestroyStore(); | 685 DestroyStore(); |
686 | 686 |
687 // Verify that "value" is visible in the file. This is necessary in order to | 687 // Verify that "value" is visible in the file. This is necessary in order to |
688 // have confidence in a later test that "encrypted_value" is not visible. | 688 // have confidence in a later test that "encrypted_value" is not visible. |
689 std::string contents = ReadRawDBContents(); | 689 std::string contents = ReadRawDBContents(); |
690 EXPECT_NE(0U, contents.length()); | 690 EXPECT_NE(0U, contents.length()); |
691 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); | 691 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); |
692 | 692 |
693 // Create encrypted cookie store and ensure old cookie still reads. | 693 // Create encrypted cookie store and ensure old cookie still reads. |
694 STLDeleteElements(&cookies_); | 694 base::STLDeleteElements(&cookies_); |
695 EXPECT_EQ(0U, cookies_.size()); | 695 EXPECT_EQ(0U, cookies_.size()); |
696 CreateAndLoad(true, false, &cookies); | 696 CreateAndLoad(true, false, &cookies); |
697 EXPECT_EQ(1U, cookies_.size()); | 697 EXPECT_EQ(1U, cookies_.size()); |
698 EXPECT_EQ("name", cookies_[0]->Name()); | 698 EXPECT_EQ("name", cookies_[0]->Name()); |
699 EXPECT_EQ("value123XYZ", cookies_[0]->Value()); | 699 EXPECT_EQ("value123XYZ", cookies_[0]->Value()); |
700 | 700 |
701 // Make sure we can update existing cookie and add new cookie as encrypted. | 701 // Make sure we can update existing cookie and add new cookie as encrypted. |
702 store_->DeleteCookie(*(cookies_[0])); | 702 store_->DeleteCookie(*(cookies_[0])); |
703 AddCookie(GURL("http://foo.bar"), "name", "encrypted_value123XYZ", | 703 AddCookie(GURL("http://foo.bar"), "name", "encrypted_value123XYZ", |
704 std::string(), "/", base::Time::Now()); | 704 std::string(), "/", base::Time::Now()); |
705 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), | 705 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), |
706 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); | 706 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); |
707 DestroyStore(); | 707 DestroyStore(); |
708 STLDeleteElements(&cookies_); | 708 base::STLDeleteElements(&cookies_); |
709 CreateAndLoad(true, false, &cookies); | 709 CreateAndLoad(true, false, &cookies); |
710 EXPECT_EQ(2U, cookies_.size()); | 710 EXPECT_EQ(2U, cookies_.size()); |
711 CanonicalCookie* cookie_name = nullptr; | 711 CanonicalCookie* cookie_name = nullptr; |
712 CanonicalCookie* cookie_other = nullptr; | 712 CanonicalCookie* cookie_other = nullptr; |
713 if (cookies_[0]->Name() == "name") { | 713 if (cookies_[0]->Name() == "name") { |
714 cookie_name = cookies_[0]; | 714 cookie_name = cookies_[0]; |
715 cookie_other = cookies_[1]; | 715 cookie_other = cookies_[1]; |
716 } else { | 716 } else { |
717 cookie_name = cookies_[1]; | 717 cookie_name = cookies_[1]; |
718 cookie_other = cookies_[0]; | 718 cookie_other = cookies_[0]; |
719 } | 719 } |
720 EXPECT_EQ("encrypted_value123XYZ", cookie_name->Value()); | 720 EXPECT_EQ("encrypted_value123XYZ", cookie_name->Value()); |
721 EXPECT_EQ("something456ABC", cookie_other->Value()); | 721 EXPECT_EQ("something456ABC", cookie_other->Value()); |
722 DestroyStore(); | 722 DestroyStore(); |
723 STLDeleteElements(&cookies_); | 723 base::STLDeleteElements(&cookies_); |
724 | 724 |
725 // Examine the real record to make sure plaintext version doesn't exist. | 725 // Examine the real record to make sure plaintext version doesn't exist. |
726 sql::Connection db; | 726 sql::Connection db; |
727 sql::Statement smt; | 727 sql::Statement smt; |
728 int resultcount = 0; | 728 int resultcount = 0; |
729 ASSERT_TRUE(db.Open(temp_dir_.path().Append(kCookieFilename))); | 729 ASSERT_TRUE(db.Open(temp_dir_.path().Append(kCookieFilename))); |
730 smt.Assign(db.GetCachedStatement(SQL_FROM_HERE, | 730 smt.Assign(db.GetCachedStatement(SQL_FROM_HERE, |
731 "SELECT * " | 731 "SELECT * " |
732 "FROM cookies " | 732 "FROM cookies " |
733 "WHERE host_key = 'foo.bar'")); | 733 "WHERE host_key = 'foo.bar'")); |
(...skipping 21 matching lines...) Expand all Loading... |
755 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", | 755 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", |
756 base::Time::Now()); | 756 base::Time::Now()); |
757 DestroyStore(); | 757 DestroyStore(); |
758 | 758 |
759 // Verify that "value" is not visible in the file. | 759 // Verify that "value" is not visible in the file. |
760 std::string contents = ReadRawDBContents(); | 760 std::string contents = ReadRawDBContents(); |
761 EXPECT_NE(0U, contents.length()); | 761 EXPECT_NE(0U, contents.length()); |
762 EXPECT_EQ(contents.find("value123XYZ"), std::string::npos); | 762 EXPECT_EQ(contents.find("value123XYZ"), std::string::npos); |
763 | 763 |
764 // Create encrypted cookie store and ensure old cookie still reads. | 764 // Create encrypted cookie store and ensure old cookie still reads. |
765 STLDeleteElements(&cookies_); | 765 base::STLDeleteElements(&cookies_); |
766 EXPECT_EQ(0U, cookies_.size()); | 766 EXPECT_EQ(0U, cookies_.size()); |
767 CreateAndLoad(true, false, &cookies); | 767 CreateAndLoad(true, false, &cookies); |
768 EXPECT_EQ(1U, cookies_.size()); | 768 EXPECT_EQ(1U, cookies_.size()); |
769 EXPECT_EQ("name", cookies_[0]->Name()); | 769 EXPECT_EQ("name", cookies_[0]->Name()); |
770 EXPECT_EQ("value123XYZ", cookies_[0]->Value()); | 770 EXPECT_EQ("value123XYZ", cookies_[0]->Value()); |
771 | 771 |
772 // Make sure we can update existing cookie and it writes unencrypted. | 772 // Make sure we can update existing cookie and it writes unencrypted. |
773 cookie_crypto_delegate_->should_encrypt_ = false; | 773 cookie_crypto_delegate_->should_encrypt_ = false; |
774 store_->DeleteCookie(*(cookies_[0])); | 774 store_->DeleteCookie(*(cookies_[0])); |
775 AddCookie(GURL("http://foo.bar"), "name", "plaintext_value123XYZ", | 775 AddCookie(GURL("http://foo.bar"), "name", "plaintext_value123XYZ", |
776 std::string(), "/", base::Time::Now()); | 776 std::string(), "/", base::Time::Now()); |
777 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), | 777 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), |
778 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); | 778 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); |
779 DestroyStore(); | 779 DestroyStore(); |
780 STLDeleteElements(&cookies_); | 780 base::STLDeleteElements(&cookies_); |
781 CreateAndLoad(true, false, &cookies); | 781 CreateAndLoad(true, false, &cookies); |
782 EXPECT_EQ(2U, cookies_.size()); | 782 EXPECT_EQ(2U, cookies_.size()); |
783 CanonicalCookie* cookie_name = nullptr; | 783 CanonicalCookie* cookie_name = nullptr; |
784 CanonicalCookie* cookie_other = nullptr; | 784 CanonicalCookie* cookie_other = nullptr; |
785 if (cookies_[0]->Name() == "name") { | 785 if (cookies_[0]->Name() == "name") { |
786 cookie_name = cookies_[0]; | 786 cookie_name = cookies_[0]; |
787 cookie_other = cookies_[1]; | 787 cookie_other = cookies_[1]; |
788 } else { | 788 } else { |
789 cookie_name = cookies_[1]; | 789 cookie_name = cookies_[1]; |
790 cookie_other = cookies_[0]; | 790 cookie_other = cookies_[0]; |
791 } | 791 } |
792 EXPECT_EQ("plaintext_value123XYZ", cookie_name->Value()); | 792 EXPECT_EQ("plaintext_value123XYZ", cookie_name->Value()); |
793 EXPECT_EQ("something456ABC", cookie_other->Value()); | 793 EXPECT_EQ("something456ABC", cookie_other->Value()); |
794 DestroyStore(); | 794 DestroyStore(); |
795 STLDeleteElements(&cookies_); | 795 base::STLDeleteElements(&cookies_); |
796 | 796 |
797 // Verify that "value" is now visible in the file. | 797 // Verify that "value" is now visible in the file. |
798 contents = ReadRawDBContents(); | 798 contents = ReadRawDBContents(); |
799 EXPECT_NE(0U, contents.length()); | 799 EXPECT_NE(0U, contents.length()); |
800 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); | 800 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); |
801 } | 801 } |
802 | 802 |
803 namespace { | 803 namespace { |
804 void WasCalledWithNoCookies(bool* was_called_with_no_cookies, | 804 void WasCalledWithNoCookies(bool* was_called_with_no_cookies, |
805 const std::vector<CanonicalCookie*>& cookies) { | 805 const std::vector<CanonicalCookie*>& cookies) { |
(...skipping 19 matching lines...) Expand all Loading... |
825 EXPECT_TRUE(was_called_with_no_cookies); | 825 EXPECT_TRUE(was_called_with_no_cookies); |
826 | 826 |
827 // Same with trying to load a specific cookie. | 827 // Same with trying to load a specific cookie. |
828 was_called_with_no_cookies = false; | 828 was_called_with_no_cookies = false; |
829 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, | 829 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, |
830 &was_called_with_no_cookies)); | 830 &was_called_with_no_cookies)); |
831 EXPECT_TRUE(was_called_with_no_cookies); | 831 EXPECT_TRUE(was_called_with_no_cookies); |
832 } | 832 } |
833 | 833 |
834 } // namespace net | 834 } // namespace net |
OLD | NEW |