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

Unified Diff: content/browser/in_process_webkit/dom_storage_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 side-by-side diff with in-line comments
Download patch
Index: content/browser/in_process_webkit/dom_storage_unittest.cc
diff --git a/content/browser/in_process_webkit/dom_storage_unittest.cc b/content/browser/in_process_webkit/dom_storage_unittest.cc
index 593c3b3519f25ef977a588e7a723a978ef72191b..6684995fc2f76abd294991872f997127174f549f 100644
--- a/content/browser/in_process_webkit/dom_storage_unittest.cc
+++ b/content/browser/in_process_webkit/dom_storage_unittest.cc
@@ -33,44 +33,88 @@ TEST_F(DOMStorageTest, SessionOnly) {
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddSessionOnly(session_only_origin);
- // A scope for deleting TestBrowserContext early enough.
- {
- TestBrowserContext browser_context;
-
- // Create databases for permanent and session-only origins.
- FilePath domstorage_dir = browser_context.GetPath().Append(
- DOMStorageContext::kLocalStorageDirectory);
- FilePath::StringType session_only_database(
- FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
- FilePath::StringType permanent_database(
- FILE_PATH_LITERAL("http_www.permanent.com_0"));
- session_only_database.append(DOMStorageContext::kLocalStorageExtension);
- permanent_database.append(DOMStorageContext::kLocalStorageExtension);
- FilePath session_only_database_path =
- domstorage_dir.Append(session_only_database);
- FilePath permanent_database_path =
- domstorage_dir.Append(permanent_database);
-
- ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
-
- ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
- ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
-
- // Inject MockSpecialStoragePolicy into DOMStorageContext.
- browser_context.GetWebKitContext()->dom_storage_context()->
- special_storage_policy_ = special_storage_policy;
-
- // Tell the WebKitContext explicitly do clean up the session-only
- // data. TestBrowserContext doesn't do it automatically
- // when destructed. The deletion is done immediately since we're on the
- // WEBKIT thread (created by the test).
- browser_context.GetWebKitContext()->DeleteSessionOnlyData();
-
- // Expected result: the database file for the permanent storage remains but
- // the database for the session only storage was deleted.
- EXPECT_FALSE(file_util::PathExists(session_only_database_path));
- EXPECT_TRUE(file_util::PathExists(permanent_database_path));
- }
+ TestBrowserContext browser_context;
+
+ // Create databases for permanent and session-only origins.
+ FilePath domstorage_dir = browser_context.GetPath().Append(
+ DOMStorageContext::kLocalStorageDirectory);
+ FilePath::StringType session_only_database(
+ FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
+ FilePath::StringType permanent_database(
+ FILE_PATH_LITERAL("http_www.permanent.com_0"));
+ session_only_database.append(DOMStorageContext::kLocalStorageExtension);
+ permanent_database.append(DOMStorageContext::kLocalStorageExtension);
+ FilePath session_only_database_path =
+ domstorage_dir.Append(session_only_database);
+ FilePath permanent_database_path =
+ domstorage_dir.Append(permanent_database);
+
+ ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
+
+ ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
+ ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
+
+ // Inject MockSpecialStoragePolicy into DOMStorageContext.
+ browser_context.GetWebKitContext()->dom_storage_context()->
+ special_storage_policy_ = special_storage_policy;
+
+ // Delete the WebKitContext before destroying TestBrowserContext. This way the
+ // temporary data directory stays alive long enough to conduct the test.
+ browser_context.webkit_context_ = NULL;
+ // Run the message loop to ensure that DOMStorageContext gets destroyed.
+ message_loop_.RunAllPending();
+
+ // Expected result: the database file for the permanent storage remains but
+ // the database for the session only storage was deleted.
+ EXPECT_FALSE(file_util::PathExists(session_only_database_path));
+ EXPECT_TRUE(file_util::PathExists(permanent_database_path));
+}
+
+TEST_F(DOMStorageTest, SaveSessionState) {
+ GURL session_only_origin("http://www.sessiononly.com");
+ scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
+ new quota::MockSpecialStoragePolicy;
+ special_storage_policy->AddSessionOnly(session_only_origin);
+
+ TestBrowserContext browser_context;
+
+ // Create databases for permanent and session-only origins.
+ FilePath domstorage_dir = browser_context.GetPath().Append(
+ DOMStorageContext::kLocalStorageDirectory);
+ FilePath::StringType session_only_database(
+ FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
+ FilePath::StringType permanent_database(
+ FILE_PATH_LITERAL("http_www.permanent.com_0"));
+ session_only_database.append(DOMStorageContext::kLocalStorageExtension);
+ permanent_database.append(DOMStorageContext::kLocalStorageExtension);
+ FilePath session_only_database_path =
+ domstorage_dir.Append(session_only_database);
+ FilePath permanent_database_path =
+ domstorage_dir.Append(permanent_database);
+
+ ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
+
+ ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
+ ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
+
+ // Inject MockSpecialStoragePolicy into DOMStorageContext.
+ DOMStorageContext* dom_storage_context =
+ browser_context.GetWebKitContext()->dom_storage_context();
+ dom_storage_context->special_storage_policy_ = special_storage_policy;
+
+ dom_storage_context->set_clear_local_state_on_exit_(true);
+
+ // Save session state. This should bypass the destruction-time deletion.
+ dom_storage_context->SaveSessionState();
+
+ // Delete the WebKitContext before destroying TestBrowserContext. This way the
+ // temporary data directory stays alive long enough to conduct the test.
+ browser_context.webkit_context_ = NULL;
// Run the message loop to ensure that DOMStorageContext gets destroyed.
message_loop_.RunAllPending();
+
+ // Expected result: no database files were deleted because of
+ // SaveSessionState.
+ EXPECT_TRUE(file_util::PathExists(session_only_database_path));
+ EXPECT_TRUE(file_util::PathExists(permanent_database_path));
}
« no previous file with comments | « content/browser/in_process_webkit/dom_storage_context.cc ('k') | content/browser/in_process_webkit/indexed_db_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698