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

Unified Diff: content/browser/in_process_webkit/indexed_db_unittest.cc

Issue 10695158: IndexedDB: Close open databases when user requests browsing data deletion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove const from iterator (not sure how this slipped through) Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/in_process_webkit/indexed_db_unittest.cc
diff --git a/content/browser/in_process_webkit/indexed_db_unittest.cc b/content/browser/in_process_webkit/indexed_db_unittest.cc
index 23a469442d9a4179aaa7dc2d25f1323eed01e11f..05d74c54f7ea06e33fe8f5bfee8efc82e71b5f68 100644
--- a/content/browser/in_process_webkit/indexed_db_unittest.cc
+++ b/content/browser/in_process_webkit/indexed_db_unittest.cc
@@ -9,8 +9,10 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
#include "webkit/database/database_util.h"
#include "webkit/quota/mock_special_storage_policy.h"
+#include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
using content::BrowserContext;
@@ -126,3 +128,71 @@ TEST_F(IndexedDBTest, SetForceKeepSessionState) {
EXPECT_TRUE(file_util::DirectoryExists(normal_path));
EXPECT_TRUE(file_util::DirectoryExists(session_only_path));
}
+
+class MockWebIDBDatabase : public WebKit::WebIDBDatabase
+{
+ public:
+ MockWebIDBDatabase(bool expect_force_close)
+ : expect_force_close_(expect_force_close),
+ force_close_called_(false) {}
+
+ ~MockWebIDBDatabase()
+ {
+ EXPECT_TRUE(force_close_called_ == expect_force_close_);
+ }
+
+ virtual void forceClose()
+ {
+ ASSERT_TRUE(expect_force_close_);
+ force_close_called_ = true;
+ }
+
+ private:
+ bool expect_force_close_;
+ bool force_close_called_;
+};
+
+
+TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ FilePath test_path;
+
+ // Create the scope which will ensure we run the destructor of the webkit
+ // context.
+ {
+ content::TestBrowserContext browser_context;
+
+ const GURL kTestOrigin("http://test/");
+
+ IndexedDBContextImpl* idb_context =
+ static_cast<IndexedDBContextImpl*>(
+ BrowserContext::GetIndexedDBContext(&browser_context));
+
+ idb_context->quota_manager_proxy_ = NULL;
+ idb_context->set_data_path_for_testing(temp_dir.path());
+
+ test_path = idb_context->GetFilePathForTesting(
+ DatabaseUtil::GetOriginIdentifier(kTestOrigin));
+ ASSERT_TRUE(file_util::CreateDirectory(test_path));
+
+ const bool kExpectForceClose = true;
+
+ MockWebIDBDatabase connection1(kExpectForceClose);
+ idb_context->ConnectionOpened(kTestOrigin, &connection1);
+
+ MockWebIDBDatabase connection2(!kExpectForceClose);
+ idb_context->ConnectionOpened(kTestOrigin, &connection2);
+ idb_context->ConnectionClosed(kTestOrigin, &connection2);
+
+ idb_context->DeleteForOrigin(kTestOrigin);
+
+ message_loop_.RunAllPending();
+ }
+
+ // Make sure we wait until the destructor has run.
+ message_loop_.RunAllPending();
+
+ EXPECT_FALSE(file_util::DirectoryExists(test_path));
+}
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_dispatcher_host.cc ('k') | content/common/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698