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

Side by Side Diff: content/browser/net/sqlite_persistent_cookie_store_unittest.cc

Issue 876973003: Implement the "first-party-only" cookie flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FirstPartyOnly. Created 5 years, 10 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 (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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 void WaitOnDBEvent() { 152 void WaitOnDBEvent() {
153 db_thread_event_.Wait(); 153 db_thread_event_.Wait();
154 } 154 }
155 155
156 // Adds a persistent cookie to store_. 156 // Adds a persistent cookie to store_.
157 void AddCookie(const std::string& name, 157 void AddCookie(const std::string& name,
158 const std::string& value, 158 const std::string& value,
159 const std::string& domain, 159 const std::string& domain,
160 const std::string& path, 160 const std::string& path,
161 const base::Time& creation) { 161 const base::Time& creation) {
162 store_->AddCookie( 162 store_->AddCookie(net::CanonicalCookie(
163 net::CanonicalCookie(GURL(), name, value, domain, path, creation, 163 GURL(), name, value, domain, path, creation, creation, creation, false,
164 creation, creation, false, false, 164 false, false, net::COOKIE_PRIORITY_DEFAULT));
165 net::COOKIE_PRIORITY_DEFAULT));
166 } 165 }
167 166
168 std::string ReadRawDBContents() { 167 std::string ReadRawDBContents() {
169 std::string contents; 168 std::string contents;
170 if (!base::ReadFileToString(temp_dir_.path().Append(kCookieFilename), 169 if (!base::ReadFileToString(temp_dir_.path().Append(kCookieFilename),
171 &contents)) 170 &contents))
172 return std::string(); 171 return std::string();
173 return contents; 172 return contents;
174 } 173 }
175 174
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // We forced a write, so now the file will be bigger. 353 // We forced a write, so now the file will be bigger.
355 ASSERT_TRUE(base::GetFileInfo(path, &info)); 354 ASSERT_TRUE(base::GetFileInfo(path, &info));
356 ASSERT_GT(info.size, base_size); 355 ASSERT_GT(info.size, base_size);
357 } 356 }
358 357
359 // Test loading old session cookies from the disk. 358 // Test loading old session cookies from the disk.
360 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { 359 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) {
361 InitializeStore(false, true); 360 InitializeStore(false, true);
362 361
363 // Add a session cookie. 362 // Add a session cookie.
364 store_->AddCookie( 363 store_->AddCookie(net::CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
365 net::CanonicalCookie( 364 "/", base::Time::Now(), base::Time(),
366 GURL(), "C", "D", "sessioncookie.com", "/", base::Time::Now(), 365 base::Time::Now(), false, false, false,
367 base::Time(), base::Time::Now(), false, false, 366 net::COOKIE_PRIORITY_DEFAULT));
368 net::COOKIE_PRIORITY_DEFAULT));
369 367
370 // Force the store to write its data to the disk. 368 // Force the store to write its data to the disk.
371 DestroyStore(); 369 DestroyStore();
372 370
373 // Create a store that loads session cookies and test that the session cookie 371 // Create a store that loads session cookies and test that the session cookie
374 // was loaded. 372 // was loaded.
375 CanonicalCookieVector cookies; 373 CanonicalCookieVector cookies;
376 CreateAndLoad(false, true, &cookies); 374 CreateAndLoad(false, true, &cookies);
377 375
378 ASSERT_EQ(1U, cookies.size()); 376 ASSERT_EQ(1U, cookies.size());
379 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); 377 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str());
380 ASSERT_STREQ("C", cookies[0]->Name().c_str()); 378 ASSERT_STREQ("C", cookies[0]->Name().c_str());
381 ASSERT_STREQ("D", cookies[0]->Value().c_str()); 379 ASSERT_STREQ("D", cookies[0]->Value().c_str());
382 ASSERT_EQ(net::COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); 380 ASSERT_EQ(net::COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority());
383 381
384 STLDeleteElements(&cookies); 382 STLDeleteElements(&cookies);
385 } 383 }
386 384
387 // Test loading old session cookies from the disk. 385 // Test loading old session cookies from the disk.
388 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { 386 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) {
389 InitializeStore(false, true); 387 InitializeStore(false, true);
390 388
391 // Add a session cookie. 389 // Add a session cookie.
392 store_->AddCookie( 390 store_->AddCookie(net::CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
393 net::CanonicalCookie( 391 "/", base::Time::Now(), base::Time(),
394 GURL(), "C", "D", "sessioncookie.com", "/", base::Time::Now(), 392 base::Time::Now(), false, false, false,
395 base::Time(), base::Time::Now(), false, false, 393 net::COOKIE_PRIORITY_DEFAULT));
396 net::COOKIE_PRIORITY_DEFAULT));
397 394
398 // Force the store to write its data to the disk. 395 // Force the store to write its data to the disk.
399 DestroyStore(); 396 DestroyStore();
400 397
401 // Create a store that doesn't load old session cookies and test that the 398 // Create a store that doesn't load old session cookies and test that the
402 // session cookie was not loaded. 399 // session cookie was not loaded.
403 CanonicalCookieVector cookies; 400 CanonicalCookieVector cookies;
404 CreateAndLoad(false, false, &cookies); 401 CreateAndLoad(false, false, &cookies);
405 ASSERT_EQ(0U, cookies.size()); 402 ASSERT_EQ(0U, cookies.size());
406 403
407 // The store should also delete the session cookie. Wait until that has been 404 // The store should also delete the session cookie. Wait until that has been
408 // done. 405 // done.
409 DestroyStore(); 406 DestroyStore();
410 407
411 // Create a store that loads old session cookies and test that the session 408 // Create a store that loads old session cookies and test that the session
412 // cookie is gone. 409 // cookie is gone.
413 CreateAndLoad(false, true, &cookies); 410 CreateAndLoad(false, true, &cookies);
414 ASSERT_EQ(0U, cookies.size()); 411 ASSERT_EQ(0U, cookies.size());
415 } 412 }
416 413
417 TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { 414 TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
418 InitializeStore(false, true); 415 InitializeStore(false, true);
419 static const char kSessionName[] = "session"; 416 static const char kSessionName[] = "session";
420 static const char kPersistentName[] = "persistent"; 417 static const char kPersistentName[] = "persistent";
421 418
422 // Add a session cookie. 419 // Add a session cookie.
423 store_->AddCookie( 420 store_->AddCookie(net::CanonicalCookie(
424 net::CanonicalCookie( 421 GURL(), kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(),
425 GURL(), kSessionName, "val", "sessioncookie.com", "/", 422 base::Time(), base::Time::Now(), false, false, false,
426 base::Time::Now(), base::Time(), base::Time::Now(), false, false, 423 net::COOKIE_PRIORITY_DEFAULT));
427 net::COOKIE_PRIORITY_DEFAULT));
428 // Add a persistent cookie. 424 // Add a persistent cookie.
429 store_->AddCookie( 425 store_->AddCookie(net::CanonicalCookie(
430 net::CanonicalCookie( 426 GURL(), kPersistentName, "val", "sessioncookie.com", "/",
431 GURL(), kPersistentName, "val", "sessioncookie.com", "/", 427 base::Time::Now() - base::TimeDelta::FromDays(1),
432 base::Time::Now() - base::TimeDelta::FromDays(1), 428 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(),
433 base::Time::Now() + base::TimeDelta::FromDays(1), 429 false, false, false, net::COOKIE_PRIORITY_DEFAULT));
434 base::Time::Now(), false, false,
435 net::COOKIE_PRIORITY_DEFAULT));
436 430
437 // Force the store to write its data to the disk. 431 // Force the store to write its data to the disk.
438 DestroyStore(); 432 DestroyStore();
439 433
440 // Create a store that loads session cookie and test that the IsPersistent 434 // Create a store that loads session cookie and test that the IsPersistent
441 // attribute is restored. 435 // attribute is restored.
442 CanonicalCookieVector cookies; 436 CanonicalCookieVector cookies;
443 CreateAndLoad(false, true, &cookies); 437 CreateAndLoad(false, true, &cookies);
444 ASSERT_EQ(2U, cookies.size()); 438 ASSERT_EQ(2U, cookies.size());
445 439
(...skipping 20 matching lines...) Expand all
466 static const char kLowName[] = "low"; 460 static const char kLowName[] = "low";
467 static const char kMediumName[] = "medium"; 461 static const char kMediumName[] = "medium";
468 static const char kHighName[] = "high"; 462 static const char kHighName[] = "high";
469 static const char kCookieDomain[] = "sessioncookie.com"; 463 static const char kCookieDomain[] = "sessioncookie.com";
470 static const char kCookieValue[] = "value"; 464 static const char kCookieValue[] = "value";
471 static const char kCookiePath[] = "/"; 465 static const char kCookiePath[] = "/";
472 466
473 InitializeStore(false, true); 467 InitializeStore(false, true);
474 468
475 // Add a low-priority persistent cookie. 469 // Add a low-priority persistent cookie.
476 store_->AddCookie( 470 store_->AddCookie(net::CanonicalCookie(
477 net::CanonicalCookie( 471 GURL(), kLowName, kCookieValue, kCookieDomain, kCookiePath,
478 GURL(), kLowName, kCookieValue, kCookieDomain, kCookiePath, 472 base::Time::Now() - base::TimeDelta::FromMinutes(1),
479 base::Time::Now() - base::TimeDelta::FromMinutes(1), 473 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(),
480 base::Time::Now() + base::TimeDelta::FromDays(1), 474 false, false, false, net::COOKIE_PRIORITY_LOW));
481 base::Time::Now(), false, false,
482 net::COOKIE_PRIORITY_LOW));
483 475
484 // Add a medium-priority persistent cookie. 476 // Add a medium-priority persistent cookie.
485 store_->AddCookie( 477 store_->AddCookie(net::CanonicalCookie(
486 net::CanonicalCookie( 478 GURL(), kMediumName, kCookieValue, kCookieDomain, kCookiePath,
487 GURL(), kMediumName, kCookieValue, kCookieDomain, kCookiePath, 479 base::Time::Now() - base::TimeDelta::FromMinutes(2),
488 base::Time::Now() - base::TimeDelta::FromMinutes(2), 480 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(),
489 base::Time::Now() + base::TimeDelta::FromDays(1), 481 false, false, false, net::COOKIE_PRIORITY_MEDIUM));
490 base::Time::Now(), false, false,
491 net::COOKIE_PRIORITY_MEDIUM));
492 482
493 // Add a high-priority peristent cookie. 483 // Add a high-priority peristent cookie.
494 store_->AddCookie( 484 store_->AddCookie(net::CanonicalCookie(
495 net::CanonicalCookie( 485 GURL(), kHighName, kCookieValue, kCookieDomain, kCookiePath,
496 GURL(), kHighName, kCookieValue, kCookieDomain, kCookiePath, 486 base::Time::Now() - base::TimeDelta::FromMinutes(3),
497 base::Time::Now() - base::TimeDelta::FromMinutes(3), 487 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(),
498 base::Time::Now() + base::TimeDelta::FromDays(1), 488 false, false, false, net::COOKIE_PRIORITY_HIGH));
499 base::Time::Now(), false, false,
500 net::COOKIE_PRIORITY_HIGH));
501 489
502 // Force the store to write its data to the disk. 490 // Force the store to write its data to the disk.
503 DestroyStore(); 491 DestroyStore();
504 492
505 // Create a store that loads session cookie and test that the priority 493 // Create a store that loads session cookie and test that the priority
506 // attribute values are restored. 494 // attribute values are restored.
507 CanonicalCookieVector cookies; 495 CanonicalCookieVector cookies;
508 CreateAndLoad(false, true, &cookies); 496 CreateAndLoad(false, true, &cookies);
509 ASSERT_EQ(3U, cookies.size()); 497 ASSERT_EQ(3U, cookies.size());
510 498
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 EXPECT_EQ(2, resultcount); 585 EXPECT_EQ(2, resultcount);
598 586
599 // Verify that "encrypted_value" is NOT visible in the file. 587 // Verify that "encrypted_value" is NOT visible in the file.
600 contents = ReadRawDBContents(); 588 contents = ReadRawDBContents();
601 EXPECT_NE(0U, contents.length()); 589 EXPECT_NE(0U, contents.length());
602 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); 590 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos);
603 EXPECT_EQ(contents.find("something456ABC"), std::string::npos); 591 EXPECT_EQ(contents.find("something456ABC"), std::string::npos);
604 } 592 }
605 593
606 } // namespace content 594 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/net/sqlite_persistent_cookie_store_perftest.cc ('k') | net/cookies/canonical_cookie.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698