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

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

Issue 8820009: Appcache, local storage, indexed db, databases: skip exit-time deletion when restarting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 9 years 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
« no previous file with comments | « webkit/database/database_tracker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 EXPECT_TRUE( 680 EXPECT_TRUE(
681 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); 681 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
682 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2)); 682 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2));
683 683
684 // The origin directory of kOrigin1 remains, but the origin directory of 684 // The origin directory of kOrigin1 remains, but the origin directory of
685 // kOrigin2 is deleted. 685 // kOrigin2 is deleted.
686 EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); 686 EXPECT_TRUE(file_util::PathExists(origin1_db_dir));
687 EXPECT_FALSE(file_util::PathExists(origin2_db_dir)); 687 EXPECT_FALSE(file_util::PathExists(origin2_db_dir));
688 } 688 }
689 689
690 static void DatabaseTrackerSaveSessionState() {
691 int64 database_size = 0;
692 const string16 kOrigin1 =
693 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
694 const string16 kOrigin2 =
695 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
696 const string16 kDB1 = ASCIIToUTF16("db1");
697 const string16 kDB2 = ASCIIToUTF16("db2");
698 const string16 kDescription = ASCIIToUTF16("database_description");
699
700 // Initialize the tracker database.
701 ScopedTempDir temp_dir;
702 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
703 FilePath origin1_db_dir;
704 FilePath origin2_db_dir;
705 {
706 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
707 new quota::MockSpecialStoragePolicy;
708 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
709 scoped_refptr<DatabaseTracker> tracker(
710 new DatabaseTracker(
711 temp_dir.path(), false, true /*clear_local_state_on_exit*/,
712 special_storage_policy, NULL,
713 base::MessageLoopProxy::current()));
714 tracker->SaveSessionState();
715
716 // Open two new databases.
717 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
718 &database_size);
719 EXPECT_EQ(0, database_size);
720 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
721 &database_size);
722 EXPECT_EQ(0, database_size);
723
724 // Write some data to each file.
725 FilePath db_file;
726 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
727 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
728 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
729
730 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
731 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
732 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
733
734 // Store the origin database directories as long as they still exist.
735 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName();
736 origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName();
737
738 tracker->DatabaseModified(kOrigin1, kDB1);
739 tracker->DatabaseModified(kOrigin2, kDB2);
740
741 // Close all databases.
742 tracker->DatabaseClosed(kOrigin1, kDB1);
743 tracker->DatabaseClosed(kOrigin2, kDB2);
744
745 tracker->Shutdown();
746 }
747
748 // At this point, the database tracker should be gone. Create a new one.
749 scoped_refptr<DatabaseTracker> tracker(
750 new DatabaseTracker(temp_dir.path(), false, false,
751 NULL, NULL, NULL));
752
753 // Get all data for all origins.
754 std::vector<OriginInfo> origins_info;
755 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
756 // No origins were deleted.
757 EXPECT_EQ(size_t(2), origins_info.size());
758 EXPECT_TRUE(
759 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
760 EXPECT_TRUE(
761 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2)));
762
763 EXPECT_TRUE(file_util::PathExists(origin1_db_dir));
764 EXPECT_TRUE(file_util::PathExists(origin2_db_dir));
765 }
766
690 static void EmptyDatabaseNameIsValid() { 767 static void EmptyDatabaseNameIsValid() {
691 const GURL kOrigin(kOrigin1Url); 768 const GURL kOrigin(kOrigin1Url);
692 const string16 kOriginId = DatabaseUtil::GetOriginIdentifier(kOrigin); 769 const string16 kOriginId = DatabaseUtil::GetOriginIdentifier(kOrigin);
693 const string16 kEmptyName; 770 const string16 kEmptyName;
694 const string16 kDescription(ASCIIToUTF16("description")); 771 const string16 kDescription(ASCIIToUTF16("description"));
695 const string16 kChangedDescription(ASCIIToUTF16("changed_description")); 772 const string16 kChangedDescription(ASCIIToUTF16("changed_description"));
696 773
697 // Initialize a tracker database, no need to put it on disk. 774 // Initialize a tracker database, no need to put it on disk.
698 const bool kUseInMemoryTrackerDatabase = true; 775 const bool kUseInMemoryTrackerDatabase = true;
699 ScopedTempDir temp_dir; 776 ScopedTempDir temp_dir;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 // Only works for regular mode. 836 // Only works for regular mode.
760 DatabaseTracker_TestHelper_Test::DatabaseTrackerClearLocalStateOnExit(); 837 DatabaseTracker_TestHelper_Test::DatabaseTrackerClearLocalStateOnExit();
761 } 838 }
762 839
763 TEST(DatabaseTrackerTest, DatabaseTrackerClearSessionOnlyDatabasesOnExit) { 840 TEST(DatabaseTrackerTest, DatabaseTrackerClearSessionOnlyDatabasesOnExit) {
764 // Only works for regular mode. 841 // Only works for regular mode.
765 DatabaseTracker_TestHelper_Test:: 842 DatabaseTracker_TestHelper_Test::
766 DatabaseTrackerClearSessionOnlyDatabasesOnExit(); 843 DatabaseTrackerClearSessionOnlyDatabasesOnExit();
767 } 844 }
768 845
846 TEST(DatabaseTrackerTest, DatabaseTrackerSaveSessionState) {
847 // Only works for regular mode.
848 DatabaseTracker_TestHelper_Test::DatabaseTrackerSaveSessionState();
849 }
850
769 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 851 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
770 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 852 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
771 } 853 }
772 854
773 } // namespace webkit_database 855 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698