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

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

Issue 93873017: IndexedDBFactory now ForceCloses databases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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/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 7c8f249f2cfe4ec9e2e0045258d560052e37a807..a255dfc1181adcb89cc3414a5330f0798aabbd04 100644
--- a/content/browser/indexed_db/indexed_db_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_unittest.cc
@@ -116,73 +116,70 @@ 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_);
- }
-
- virtual void ForceClose() OVERRIDE {
- ASSERT_TRUE(expect_force_close_);
- force_close_called_ = true;
+ ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context,
+ const GURL& origin_url)
jsbell 2013/12/19 22:35:34 Nit: indentation
+ : 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 bool IsConnected() OVERRIDE {
- return !force_close_called_;
- }
+ IndexedDBConnection* connection() { return connection_; }
+ 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());
- base::FilePath test_path;
+ scoped_refptr<MockIndexedDBDatabaseCallbacks> open_db_callbacks(
+ new MockIndexedDBDatabaseCallbacks());
+ scoped_refptr<MockIndexedDBDatabaseCallbacks> closed_db_callbacks(
+ new MockIndexedDBDatabaseCallbacks());
// Create the scope which will ensure we run the destructor of the context.
{
TestBrowserContext browser_context;
- const GURL kTestOrigin("http://test/");
-
scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
temp_dir.path(), special_storage_policy_, NULL, task_runner_);
- test_path = idb_context->GetFilePathForTesting(
+ const GURL kTestOrigin("http://test/");
+
+ scoped_refptr<ForceCloseDBCallbacks> open_callbacks =
+ new ForceCloseDBCallbacks(idb_context, kTestOrigin);
+
+ scoped_refptr<ForceCloseDBCallbacks> closed_callbacks =
+ new ForceCloseDBCallbacks(idb_context, kTestOrigin);
+
+ IndexedDBFactory* factory = idb_context->GetIDBFactory();
+
+ base::FilePath test_path = idb_context->GetFilePathForTesting(
webkit_database::GetIdentifierFromOrigin(kTestOrigin));
ASSERT_TRUE(base::CreateDirectory(test_path));
- const bool kExpectForceClose = true;
-
- MockConnection connection1(kExpectForceClose);
- idb_context->TaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&IndexedDBContextImpl::ConnectionOpened,
- idb_context,
- kTestOrigin,
- &connection1));
+ factory->Open(ASCIIToUTF16("opendb"), 0, 0, open_callbacks,
+ open_db_callbacks, kTestOrigin, test_path);
+ factory->Open(ASCIIToUTF16("closeddb"), 0, 0, closed_callbacks,
+ closed_db_callbacks, kTestOrigin, test_path);
- 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));
+ closed_callbacks->connection()->Close();
idb_context->TaskRunner()->PostTask(
FROM_HERE,
@@ -195,7 +192,8 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
// Make sure we wait until the destructor has run.
message_loop_.RunUntilIdle();
- EXPECT_FALSE(base::DirectoryExists(test_path));
+ EXPECT_TRUE(open_db_callbacks->forced_close_called());
+ EXPECT_FALSE(closed_db_callbacks->forced_close_called());
}
TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) {

Powered by Google App Engine
This is Rietveld 408576698