diff options
author | cmumford@chromium.org <cmumford@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 21:11:10 +0000 |
---|---|---|
committer | cmumford@chromium.org <cmumford@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 21:11:10 +0000 |
commit | 791c1228d13ebccee5d79aa5d4e96779ab1f0e91 (patch) | |
tree | 8012985818a878b8f5d4850ce12a769f13efd5d3 /content/browser/indexed_db/indexed_db_unittest.cc | |
parent | b2732a066c9ca0b106db440b3fd267befee2ea58 (diff) | |
download | chromium_src-791c1228d13ebccee5d79aa5d4e96779ab1f0e91.zip chromium_src-791c1228d13ebccee5d79aa5d4e96779ab1f0e91.tar.gz chromium_src-791c1228d13ebccee5d79aa5d4e96779ab1f0e91.tar.bz2 |
IndexedDBFactory now ForceCloses databases.
Also, IndexedDBContextImpl used to maintain a map of open
connections. This change also deletes this map, and instead
relies on one which already exists in IndexedDBFactory.
BUG=259564
Review URL: https://codereview.chromium.org/93873017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/indexed_db/indexed_db_unittest.cc')
-rw-r--r-- | content/browser/indexed_db/indexed_db_unittest.cc | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/content/browser/indexed_db/indexed_db_unittest.cc b/content/browser/indexed_db/indexed_db_unittest.cc index d0fe981..006436b 100644 --- a/content/browser/indexed_db/indexed_db_unittest.cc +++ b/content/browser/indexed_db/indexed_db_unittest.cc @@ -116,35 +116,44 @@ 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), + connection_(NULL) {} + + 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.release(); + idb_context_->ConnectionOpened(origin_url_, connection_); } - virtual void ForceClose() OVERRIDE { - ASSERT_TRUE(expect_force_close_); - force_close_called_ = true; - } + IndexedDBConnection* connection() { return connection_; } - 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_; + 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 +165,33 @@ 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)); + + factory->Open(base::ASCIIToUTF16("opendb"), + 0, + 0, + open_callbacks, + open_db_callbacks, + kTestOrigin, + idb_context->data_path()); + factory->Open(base::ASCIIToUTF16("closeddb"), + 0, + 0, + closed_callbacks, + closed_db_callbacks, + kTestOrigin, + idb_context->data_path()); + + closed_callbacks->connection()->Close(); idb_context->TaskRunner()->PostTask( FROM_HERE, @@ -195,6 +204,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)); } |