| Index: content/browser/indexed_db/indexed_db_unittest.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_unittest.cc b/content/browser/indexed_db/indexed_db_unittest.cc
|
| index e5a8b35215308ca4ff4487a85f17ca232f0a08b0..9dc6c046c5a6ba3d6f31cf57fd223178b0bc2ec6 100644
|
| --- a/content/browser/indexed_db/indexed_db_unittest.cc
|
| +++ b/content/browser/indexed_db/indexed_db_unittest.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "base/file_util.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| +#include "base/test/thread_test_helper.h"
|
| +#include "base/threading/thread.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| #include "content/browser/indexed_db/indexed_db_context_impl.h"
|
| #include "content/browser/indexed_db/webidbdatabase_impl.h"
|
| @@ -20,17 +22,33 @@ namespace content {
|
|
|
| class IndexedDBTest : public testing::Test {
|
| public:
|
| + const GURL kNormalOrigin;
|
| + const GURL kSessionOnlyOrigin;
|
| +
|
| IndexedDBTest()
|
| - : message_loop_(base::MessageLoop::TYPE_IO),
|
| - webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
|
| + : kNormalOrigin("http://normal/"),
|
| + kSessionOnlyOrigin("http://session-only/"),
|
| + message_loop_(base::MessageLoop::TYPE_IO),
|
| + idb_thread_(new base::Thread("IndexedDBTest")),
|
| + special_storage_policy_(new quota::MockSpecialStoragePolicy),
|
| file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
|
| - io_thread_(BrowserThread::IO, &message_loop_) {}
|
| + io_thread_(BrowserThread::IO, &message_loop_) {
|
| + special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin);
|
| + idb_thread_->Start();
|
| + }
|
| +
|
| + void FlushIndexedDBTaskRunner() {
|
| + scoped_refptr<base::ThreadTestHelper> helper(
|
| + new base::ThreadTestHelper(idb_thread_->message_loop_proxy()));
|
| + ASSERT_TRUE(helper->Run());
|
| + }
|
|
|
| protected:
|
| base::MessageLoop message_loop_;
|
| + scoped_ptr<base::Thread> idb_thread_;
|
| + scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
|
|
|
| private:
|
| - BrowserThreadImpl webkit_thread_;
|
| BrowserThreadImpl file_thread_;
|
| BrowserThreadImpl io_thread_;
|
| };
|
| @@ -42,26 +60,14 @@ TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
|
| base::FilePath normal_path;
|
| base::FilePath session_only_path;
|
|
|
| - // Create the scope which will ensure we run the destructor of the webkit
|
| - // context which should trigger the clean up.
|
| + // Create the scope which will ensure we run the destructor of the context
|
| + // which should trigger the clean up.
|
| {
|
| - TestBrowserContext browser_context;
|
| -
|
| - const GURL kNormalOrigin("http://normal/");
|
| - const GURL kSessionOnlyOrigin("http://session-only/");
|
| - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
|
| - new quota::MockSpecialStoragePolicy;
|
| - special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
|
| -
|
| - // Create some indexedDB paths.
|
| - // With the levelDB backend, these are directories.
|
| - IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>(
|
| - BrowserContext::GetDefaultStoragePartition(&browser_context)
|
| - ->GetIndexedDBContext());
|
| -
|
| - // Override the storage policy with our own.
|
| - idb_context->special_storage_policy_ = special_storage_policy;
|
| - idb_context->set_data_path_for_testing(temp_dir.path());
|
| + scoped_refptr<IndexedDBContextImpl> idb_context =
|
| + new IndexedDBContextImpl(temp_dir.path(),
|
| + special_storage_policy_,
|
| + NULL,
|
| + idb_thread_->message_loop());
|
|
|
| normal_path = idb_context->GetFilePathForTesting(
|
| webkit_database::GetIdentifierFromOrigin(kNormalOrigin));
|
| @@ -69,9 +75,11 @@ TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
|
| webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin));
|
| ASSERT_TRUE(file_util::CreateDirectory(normal_path));
|
| ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
|
| + FlushIndexedDBTaskRunner();
|
| message_loop_.RunUntilIdle();
|
| }
|
|
|
| + FlushIndexedDBTaskRunner();
|
| message_loop_.RunUntilIdle();
|
|
|
| EXPECT_TRUE(file_util::DirectoryExists(normal_path));
|
| @@ -85,26 +93,15 @@ TEST_F(IndexedDBTest, SetForceKeepSessionState) {
|
| base::FilePath normal_path;
|
| base::FilePath session_only_path;
|
|
|
| - // Create the scope which will ensure we run the destructor of the webkit
|
| - // context.
|
| + // Create the scope which will ensure we run the destructor of the context.
|
| {
|
| - TestBrowserContext browser_context;
|
| -
|
| - const GURL kNormalOrigin("http://normal/");
|
| - const GURL kSessionOnlyOrigin("http://session-only/");
|
| - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
|
| - new quota::MockSpecialStoragePolicy;
|
| - special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
|
| -
|
| // Create some indexedDB paths.
|
| // With the levelDB backend, these are directories.
|
| - IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>(
|
| - BrowserContext::GetDefaultStoragePartition(&browser_context)
|
| - ->GetIndexedDBContext());
|
| -
|
| - // Override the storage policy with our own.
|
| - idb_context->special_storage_policy_ = special_storage_policy;
|
| - idb_context->set_data_path_for_testing(temp_dir.path());
|
| + scoped_refptr<IndexedDBContextImpl> idb_context =
|
| + new IndexedDBContextImpl(temp_dir.path(),
|
| + special_storage_policy_,
|
| + NULL,
|
| + idb_thread_->message_loop());
|
|
|
| // Save session state. This should bypass the destruction-time deletion.
|
| idb_context->SetForceKeepSessionState();
|
| @@ -153,19 +150,17 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
|
|
|
| base::FilePath test_path;
|
|
|
| - // Create the scope which will ensure we run the destructor of the webkit
|
| - // context.
|
| + // Create the scope which will ensure we run the destructor of the context.
|
| {
|
| TestBrowserContext browser_context;
|
|
|
| const GURL kTestOrigin("http://test/");
|
|
|
| - IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>(
|
| - BrowserContext::GetDefaultStoragePartition(&browser_context)
|
| - ->GetIndexedDBContext());
|
| -
|
| - idb_context->quota_manager_proxy_ = NULL;
|
| - idb_context->set_data_path_for_testing(temp_dir.path());
|
| + scoped_refptr<IndexedDBContextImpl> idb_context =
|
| + new IndexedDBContextImpl(temp_dir.path(),
|
| + special_storage_policy_,
|
| + NULL,
|
| + idb_thread_->message_loop());
|
|
|
| test_path = idb_context->GetFilePathForTesting(
|
| webkit_database::GetIdentifierFromOrigin(kTestOrigin));
|
| @@ -174,14 +169,35 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
|
| const bool kExpectForceClose = true;
|
|
|
| MockWebIDBDatabase connection1(kExpectForceClose);
|
| - idb_context->ConnectionOpened(kTestOrigin, &connection1);
|
| + idb_context->TaskRunner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&IndexedDBContextImpl::ConnectionOpened,
|
| + idb_context,
|
| + kTestOrigin,
|
| + &connection1));
|
|
|
| MockWebIDBDatabase connection2(!kExpectForceClose);
|
| - idb_context->ConnectionOpened(kTestOrigin, &connection2);
|
| - idb_context->ConnectionClosed(kTestOrigin, &connection2);
|
| -
|
| - idb_context->DeleteForOrigin(kTestOrigin);
|
| -
|
| + idb_context->TaskRunner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&IndexedDBContextImpl::ConnectionOpened,
|
| + idb_context,
|
| + kTestOrigin,
|
| + &connection2));
|
| + idb_context->TaskRunner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&IndexedDBContextImpl::ConnectionClosed,
|
| + idb_context,
|
| + kTestOrigin,
|
| + &connection2));
|
| +
|
| + idb_context->TaskRunner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&IndexedDBContextImpl::DeleteForOrigin,
|
| + idb_context,
|
| + kTestOrigin));
|
| + scoped_refptr<base::ThreadTestHelper> helper(
|
| + new base::ThreadTestHelper(idb_context->MessageLoopProxy()));
|
| + EXPECT_TRUE(helper->Run());
|
| message_loop_.RunUntilIdle();
|
| }
|
|
|
|
|