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

Side by Side Diff: webkit/database/database_tracker_unittest.cc

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 6 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 | Annotate | Revision Log
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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/platform_file.h" 9 #include "base/platform_file.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 crashed_renderer_connections.AddConnection(kOriginId, kName); 521 crashed_renderer_connections.AddConnection(kOriginId, kName);
522 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, 100)); 522 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, 100));
523 tracker->CloseDatabases(crashed_renderer_connections); 523 tracker->CloseDatabases(crashed_renderer_connections);
524 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100)); 524 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100));
525 525
526 // Cleanup. 526 // Cleanup.
527 crashed_renderer_connections.RemoveAllConnections(); 527 crashed_renderer_connections.RemoveAllConnections();
528 test_quota_proxy->SimulateQuotaManagerDestroyed(); 528 test_quota_proxy->SimulateQuotaManagerDestroyed();
529 } 529 }
530 530
531 static void DatabaseTrackerClearLocalStateOnExit() {
532 int64 database_size = 0;
533 const string16 kOrigin1 =
534 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
535 const string16 kOrigin2 =
536 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
537 const string16 kDB1 = ASCIIToUTF16("db1");
538 const string16 kDB2 = ASCIIToUTF16("db2");
539 const string16 kDB3 = ASCIIToUTF16("db3");
540 const string16 kDescription = ASCIIToUTF16("database_description");
541
542 // Initialize the tracker database.
543 ScopedTempDir temp_dir;
544 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
545 FilePath origin1_db_dir;
546 {
547 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
548 new quota::MockSpecialStoragePolicy;
549 special_storage_policy->AddProtected(GURL(kOrigin2Url));
550 scoped_refptr<DatabaseTracker> tracker(
551 new DatabaseTracker(
552 temp_dir.path(), false,
553 special_storage_policy, NULL,
554 base::MessageLoopProxy::current()));
555 tracker->SetClearLocalStateOnExit(true);
556
557 // Open three new databases.
558 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
559 &database_size);
560 EXPECT_EQ(0, database_size);
561 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
562 &database_size);
563 EXPECT_EQ(0, database_size);
564 tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0,
565 &database_size);
566 EXPECT_EQ(0, database_size);
567
568 // Write some data to each file.
569 FilePath db_file;
570 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
571 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
572 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
573
574 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
575 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
576 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
577
578 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB3);
579 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
580 EXPECT_TRUE(EnsureFileOfSize(db_file, 3));
581
582 // Store the origin database directory as long as it still exists.
583 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB3).DirName();
584
585 tracker->DatabaseModified(kOrigin1, kDB1);
586 tracker->DatabaseModified(kOrigin2, kDB2);
587 tracker->DatabaseModified(kOrigin1, kDB3);
588
589 // Close all databases but one database.
590 tracker->DatabaseClosed(kOrigin1, kDB1);
591 tracker->DatabaseClosed(kOrigin2, kDB2);
592
593 // Keep an open file handle to the last database.
594 base::PlatformFile file_handle = base::CreatePlatformFile(
595 tracker->GetFullDBFilePath(kOrigin1, kDB3),
596 base::PLATFORM_FILE_READ |
597 base::PLATFORM_FILE_WRITE |
598 base::PLATFORM_FILE_EXCLUSIVE_READ |
599 base::PLATFORM_FILE_EXCLUSIVE_WRITE |
600 base::PLATFORM_FILE_OPEN_ALWAYS |
601 base::PLATFORM_FILE_SHARE_DELETE,
602 NULL, NULL);
603
604 tracker->Shutdown();
605
606 base::ClosePlatformFile(file_handle);
607 tracker->DatabaseClosed(kOrigin1, kDB3);
608 }
609
610 // At this point, the database tracker should be gone. Create a new one.
611 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
612 new quota::MockSpecialStoragePolicy;
613 special_storage_policy->AddProtected(GURL(kOrigin2Url));
614 scoped_refptr<DatabaseTracker> tracker(
615 new DatabaseTracker(temp_dir.path(), false,
616 special_storage_policy, NULL, NULL));
617
618 // Get all data for all origins.
619 std::vector<OriginInfo> origins_info;
620 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
621 EXPECT_EQ(size_t(1), origins_info.size());
622 EXPECT_EQ(kOrigin2, origins_info[0].GetOrigin());
623 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin1, kDB1));
624 EXPECT_TRUE(
625 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2)));
626 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin1, kDB3));
627
628 // The origin directory should be gone as well.
629 EXPECT_FALSE(file_util::PathExists(origin1_db_dir));
630 }
631
632 static void DatabaseTrackerClearSessionOnlyDatabasesOnExit() { 531 static void DatabaseTrackerClearSessionOnlyDatabasesOnExit() {
633 int64 database_size = 0; 532 int64 database_size = 0;
634 const string16 kOrigin1 = 533 const string16 kOrigin1 =
635 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url)); 534 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
636 const string16 kOrigin2 = 535 const string16 kOrigin2 =
637 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url)); 536 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
638 const string16 kDB1 = ASCIIToUTF16("db1"); 537 const string16 kDB1 = ASCIIToUTF16("db1");
639 const string16 kDB2 = ASCIIToUTF16("db2"); 538 const string16 kDB2 = ASCIIToUTF16("db2");
640 const string16 kDescription = ASCIIToUTF16("database_description"); 539 const string16 kDescription = ASCIIToUTF16("database_description");
641 540
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 EXPECT_TRUE( 598 EXPECT_TRUE(
700 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); 599 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
701 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2)); 600 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2));
702 601
703 // The origin directory of kOrigin1 remains, but the origin directory of 602 // The origin directory of kOrigin1 remains, but the origin directory of
704 // kOrigin2 is deleted. 603 // kOrigin2 is deleted.
705 EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); 604 EXPECT_TRUE(file_util::PathExists(origin1_db_dir));
706 EXPECT_FALSE(file_util::PathExists(origin2_db_dir)); 605 EXPECT_FALSE(file_util::PathExists(origin2_db_dir));
707 } 606 }
708 607
709 static void DatabaseTrackerSaveSessionState() { 608 static void DatabaseTrackerSetForceKeepSessionState() {
710 int64 database_size = 0; 609 int64 database_size = 0;
711 const string16 kOrigin1 = 610 const string16 kOrigin1 =
712 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url)); 611 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
713 const string16 kOrigin2 = 612 const string16 kOrigin2 =
714 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url)); 613 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
715 const string16 kDB1 = ASCIIToUTF16("db1"); 614 const string16 kDB1 = ASCIIToUTF16("db1");
716 const string16 kDB2 = ASCIIToUTF16("db2"); 615 const string16 kDB2 = ASCIIToUTF16("db2");
717 const string16 kDescription = ASCIIToUTF16("database_description"); 616 const string16 kDescription = ASCIIToUTF16("database_description");
718 617
719 // Initialize the tracker database. 618 // Initialize the tracker database.
720 ScopedTempDir temp_dir; 619 ScopedTempDir temp_dir;
721 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 620 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
722 FilePath origin1_db_dir; 621 FilePath origin1_db_dir;
723 FilePath origin2_db_dir; 622 FilePath origin2_db_dir;
724 { 623 {
725 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 624 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
726 new quota::MockSpecialStoragePolicy; 625 new quota::MockSpecialStoragePolicy;
727 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); 626 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
728 scoped_refptr<DatabaseTracker> tracker( 627 scoped_refptr<DatabaseTracker> tracker(
729 new DatabaseTracker( 628 new DatabaseTracker(
730 temp_dir.path(), false, special_storage_policy, NULL, 629 temp_dir.path(), false, special_storage_policy, NULL,
731 base::MessageLoopProxy::current())); 630 base::MessageLoopProxy::current()));
732 tracker->SetClearLocalStateOnExit(true); 631 tracker->SetForceKeepSessionState();
733 tracker->SaveSessionState();
734 632
735 // Open two new databases. 633 // Open two new databases.
736 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 634 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
737 &database_size); 635 &database_size);
738 EXPECT_EQ(0, database_size); 636 EXPECT_EQ(0, database_size);
739 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 637 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
740 &database_size); 638 &database_size);
741 EXPECT_EQ(0, database_size); 639 EXPECT_EQ(0, database_size);
742 640
743 // Write some data to each file. 641 // Write some data to each file.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 816
919 TEST(DatabaseTrackerTest, DatabaseTrackerIncognitoMode) { 817 TEST(DatabaseTrackerTest, DatabaseTrackerIncognitoMode) {
920 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(true); 818 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(true);
921 } 819 }
922 820
923 TEST(DatabaseTrackerTest, DatabaseTrackerQuotaIntegration) { 821 TEST(DatabaseTrackerTest, DatabaseTrackerQuotaIntegration) {
924 // There is no difference in behavior between incognito and not. 822 // There is no difference in behavior between incognito and not.
925 DatabaseTracker_TestHelper_Test::DatabaseTrackerQuotaIntegration(); 823 DatabaseTracker_TestHelper_Test::DatabaseTrackerQuotaIntegration();
926 } 824 }
927 825
928 TEST(DatabaseTrackerTest, DatabaseTrackerClearLocalStateOnExit) {
929 // Only works for regular mode.
930 DatabaseTracker_TestHelper_Test::DatabaseTrackerClearLocalStateOnExit();
931 }
932
933 TEST(DatabaseTrackerTest, DatabaseTrackerClearSessionOnlyDatabasesOnExit) { 826 TEST(DatabaseTrackerTest, DatabaseTrackerClearSessionOnlyDatabasesOnExit) {
934 // Only works for regular mode. 827 // Only works for regular mode.
935 DatabaseTracker_TestHelper_Test:: 828 DatabaseTracker_TestHelper_Test::
936 DatabaseTrackerClearSessionOnlyDatabasesOnExit(); 829 DatabaseTrackerClearSessionOnlyDatabasesOnExit();
937 } 830 }
938 831
939 TEST(DatabaseTrackerTest, DatabaseTrackerSaveSessionState) { 832 TEST(DatabaseTrackerTest, DatabaseTrackerSetForceKeepSessionState) {
940 // Only works for regular mode. 833 // Only works for regular mode.
941 DatabaseTracker_TestHelper_Test::DatabaseTrackerSaveSessionState(); 834 DatabaseTracker_TestHelper_Test::DatabaseTrackerSetForceKeepSessionState();
942 } 835 }
943 836
944 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 837 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
945 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 838 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
946 } 839 }
947 840
948 TEST(DatabaseTrackerTest, HandleSqliteError) { 841 TEST(DatabaseTrackerTest, HandleSqliteError) {
949 DatabaseTracker_TestHelper_Test::HandleSqliteError(); 842 DatabaseTracker_TestHelper_Test::HandleSqliteError();
950 } 843 }
951 844
952 } // namespace webkit_database 845 } // namespace webkit_database
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698