diff options
Diffstat (limited to 'chromium/content/browser/indexed_db/indexed_db_unittest.cc')
-rw-r--r-- | chromium/content/browser/indexed_db/indexed_db_unittest.cc | 121 |
1 files changed, 70 insertions, 51 deletions
diff --git a/chromium/content/browser/indexed_db/indexed_db_unittest.cc b/chromium/content/browser/indexed_db/indexed_db_unittest.cc index 7c8f249f2cf..6fa627b1632 100644 --- a/chromium/content/browser/indexed_db/indexed_db_unittest.cc +++ b/chromium/content/browser/indexed_db/indexed_db_unittest.cc @@ -13,9 +13,9 @@ #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" #include "content/public/browser/storage_partition.h" #include "content/public/common/url_constants.h" +#include "content/public/test/mock_special_storage_policy.h" #include "content/public/test/test_browser_context.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/browser/quota/mock_special_storage_policy.h" #include "webkit/browser/quota/quota_manager.h" #include "webkit/browser/quota/special_storage_policy.h" #include "webkit/common/database/database_identifier.h" @@ -30,9 +30,8 @@ class IndexedDBTest : public testing::Test { IndexedDBTest() : kNormalOrigin("http://normal/"), kSessionOnlyOrigin("http://session-only/"), - message_loop_(base::MessageLoop::TYPE_IO), task_runner_(new base::TestSimpleTaskRunner), - special_storage_policy_(new quota::MockSpecialStoragePolicy), + special_storage_policy_(new MockSpecialStoragePolicy), file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) { special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin); @@ -41,9 +40,9 @@ class IndexedDBTest : public testing::Test { protected: void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } - base::MessageLoop message_loop_; + base::MessageLoopForIO message_loop_; scoped_refptr<base::TestSimpleTaskRunner> task_runner_; - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; + scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; private: BrowserThreadImpl file_thread_; @@ -116,35 +115,43 @@ TEST_F(IndexedDBTest, SetForceKeepSessionState) { EXPECT_TRUE(base::DirectoryExists(session_only_path)); } -class MockConnection : public IndexedDBConnection { +class ForceCloseDBCallbacks : public IndexedDBCallbacks { public: - explicit MockConnection(bool expect_force_close) - : IndexedDBConnection(NULL, NULL), - expect_force_close_(expect_force_close), - force_close_called_(false) {} - - virtual ~MockConnection() { - EXPECT_TRUE(force_close_called_ == expect_force_close_); + ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context, + const GURL& origin_url) + : IndexedDBCallbacks(NULL, 0, 0), + idb_context_(idb_context), + origin_url_(origin_url) {} + + virtual void OnSuccess() OVERRIDE {} + virtual void OnSuccess(const std::vector<base::string16>&) OVERRIDE {} + virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection, + const IndexedDBDatabaseMetadata& metadata) OVERRIDE { + connection_ = connection.Pass(); + idb_context_->ConnectionOpened(origin_url_, connection_.get()); } - virtual void ForceClose() OVERRIDE { - ASSERT_TRUE(expect_force_close_); - force_close_called_ = true; - } + IndexedDBConnection* connection() { return connection_.get(); } - virtual bool IsConnected() OVERRIDE { - return !force_close_called_; - } + protected: + virtual ~ForceCloseDBCallbacks() {} private: - bool expect_force_close_; - bool force_close_called_; + scoped_refptr<IndexedDBContextImpl> idb_context_; + GURL origin_url_; + scoped_ptr<IndexedDBConnection> connection_; + DISALLOW_COPY_AND_ASSIGN(ForceCloseDBCallbacks); }; TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { base::ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + scoped_refptr<MockIndexedDBDatabaseCallbacks> open_db_callbacks( + new MockIndexedDBDatabaseCallbacks()); + scoped_refptr<MockIndexedDBDatabaseCallbacks> closed_db_callbacks( + new MockIndexedDBDatabaseCallbacks()); + base::FilePath test_path; // Create the scope which will ensure we run the destructor of the context. @@ -156,33 +163,39 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( temp_dir.path(), special_storage_policy_, NULL, task_runner_); - test_path = idb_context->GetFilePathForTesting( - webkit_database::GetIdentifierFromOrigin(kTestOrigin)); - ASSERT_TRUE(base::CreateDirectory(test_path)); + scoped_refptr<ForceCloseDBCallbacks> open_callbacks = + new ForceCloseDBCallbacks(idb_context, kTestOrigin); - const bool kExpectForceClose = true; + scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = + new ForceCloseDBCallbacks(idb_context, kTestOrigin); - MockConnection connection1(kExpectForceClose); - idb_context->TaskRunner()->PostTask( - FROM_HERE, - base::Bind(&IndexedDBContextImpl::ConnectionOpened, - idb_context, - kTestOrigin, - &connection1)); + IndexedDBFactory* factory = idb_context->GetIDBFactory(); - MockConnection connection2(!kExpectForceClose); - 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)); + test_path = idb_context->GetFilePathForTesting( + webkit_database::GetIdentifierFromOrigin(kTestOrigin)); + + IndexedDBPendingConnection open_connection(open_callbacks, + open_db_callbacks, + 0 /* child_process_id */, + 0 /* host_transaction_id */, + 0 /* version */); + factory->Open(base::ASCIIToUTF16("opendb"), + open_connection, + NULL /* request_context */, + kTestOrigin, + idb_context->data_path()); + IndexedDBPendingConnection closed_connection(closed_callbacks, + closed_db_callbacks, + 0 /* child_process_id */, + 0 /* host_transaction_id */, + 0 /* version */); + factory->Open(base::ASCIIToUTF16("closeddb"), + closed_connection, + NULL /* request_context */, + kTestOrigin, + idb_context->data_path()); + + closed_callbacks->connection()->Close(); idb_context->TaskRunner()->PostTask( FROM_HERE, @@ -195,6 +208,8 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { // Make sure we wait until the destructor has run. message_loop_.RunUntilIdle(); + EXPECT_TRUE(open_db_callbacks->forced_close_called()); + EXPECT_FALSE(closed_db_callbacks->forced_close_called()); EXPECT_FALSE(base::DirectoryExists(test_path)); } @@ -238,11 +253,15 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnCommitFailure) { scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( new MockIndexedDBDatabaseCallbacks()); const int64 transaction_id = 1; - factory->Open(ASCIIToUTF16("db"), - IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, - transaction_id, - callbacks, - db_callbacks, + IndexedDBPendingConnection connection( + callbacks, + db_callbacks, + 0 /* child_process_id */, + transaction_id, + IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); + factory->Open(base::ASCIIToUTF16("db"), + connection, + NULL /* request_context */, kTestOrigin, temp_dir.path()); |