diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 10:44:03 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 10:44:03 +0000 |
commit | e9005779e42a908cb54400018b94a2f158116321 (patch) | |
tree | 4217188a1f8dea29170b89c87bcc8661a6003dc6 /webkit/database/database_tracker_unittest.cc | |
parent | b5621306f7ff98d66d5a25920a8749f5034b6c7c (diff) | |
download | chromium_src-e9005779e42a908cb54400018b94a2f158116321.zip chromium_src-e9005779e42a908cb54400018b94a2f158116321.tar.gz chromium_src-e9005779e42a908cb54400018b94a2f158116321.tar.bz2 |
Appcache, local storage, indexed db, databases: skip exit-time deletion when restarting.
BUG=104291
TEST={ChromeAppCacheServiceTest, DOMStorageTest, IndexedDBBrowserTest, DatabaseTrackerTest}.SaveSessionState
Review URL: http://codereview.chromium.org/8820009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_tracker_unittest.cc')
-rw-r--r-- | webkit/database/database_tracker_unittest.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc index e46e16b..4d4923d 100644 --- a/webkit/database/database_tracker_unittest.cc +++ b/webkit/database/database_tracker_unittest.cc @@ -687,6 +687,83 @@ class DatabaseTracker_TestHelper_Test { EXPECT_FALSE(file_util::PathExists(origin2_db_dir)); } + static void DatabaseTrackerSaveSessionState() { + int64 database_size = 0; + const string16 kOrigin1 = + DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url)); + const string16 kOrigin2 = + DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url)); + const string16 kDB1 = ASCIIToUTF16("db1"); + const string16 kDB2 = ASCIIToUTF16("db2"); + const string16 kDescription = ASCIIToUTF16("database_description"); + + // Initialize the tracker database. + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + FilePath origin1_db_dir; + FilePath origin2_db_dir; + { + scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = + new quota::MockSpecialStoragePolicy; + special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); + scoped_refptr<DatabaseTracker> tracker( + new DatabaseTracker( + temp_dir.path(), false, true /*clear_local_state_on_exit*/, + special_storage_policy, NULL, + base::MessageLoopProxy::current())); + tracker->SaveSessionState(); + + // Open two new databases. + tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, + &database_size); + EXPECT_EQ(0, database_size); + tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, + &database_size); + EXPECT_EQ(0, database_size); + + // Write some data to each file. + FilePath db_file; + db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1); + EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); + EXPECT_TRUE(EnsureFileOfSize(db_file, 1)); + + db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2); + EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); + EXPECT_TRUE(EnsureFileOfSize(db_file, 2)); + + // Store the origin database directories as long as they still exist. + origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName(); + origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName(); + + tracker->DatabaseModified(kOrigin1, kDB1); + tracker->DatabaseModified(kOrigin2, kDB2); + + // Close all databases. + tracker->DatabaseClosed(kOrigin1, kDB1); + tracker->DatabaseClosed(kOrigin2, kDB2); + + tracker->Shutdown(); + } + + // At this point, the database tracker should be gone. Create a new one. + scoped_refptr<DatabaseTracker> tracker( + new DatabaseTracker(temp_dir.path(), false, false, + NULL, NULL, NULL)); + + // Get all data for all origins. + std::vector<OriginInfo> origins_info; + EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info)); + // No origins were deleted. + EXPECT_EQ(size_t(2), origins_info.size()); + EXPECT_TRUE( + file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); + EXPECT_TRUE( + file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2))); + + EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); + EXPECT_TRUE(file_util::PathExists(origin2_db_dir)); + } + static void EmptyDatabaseNameIsValid() { const GURL kOrigin(kOrigin1Url); const string16 kOriginId = DatabaseUtil::GetOriginIdentifier(kOrigin); @@ -766,6 +843,11 @@ TEST(DatabaseTrackerTest, DatabaseTrackerClearSessionOnlyDatabasesOnExit) { DatabaseTrackerClearSessionOnlyDatabasesOnExit(); } +TEST(DatabaseTrackerTest, DatabaseTrackerSaveSessionState) { + // Only works for regular mode. + DatabaseTracker_TestHelper_Test::DatabaseTrackerSaveSessionState(); +} + TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); } |