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

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

Issue 134693005: Revert of IndexedDBFactory now ForceCloses databases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 006436ba00263c4e93fccdd7ddd33a48c09a8527..d0fe9816ec9b075deafecd5c2d2ddce49102fdf9 100644
--- a/content/browser/indexed_db/indexed_db_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_unittest.cc
@@ -116,43 +116,34 @@
EXPECT_TRUE(base::DirectoryExists(session_only_path));
}
-class ForceCloseDBCallbacks : public IndexedDBCallbacks {
+class MockConnection : public IndexedDBConnection {
public:
- 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_);
- }
-
- IndexedDBConnection* connection() { return connection_; }
-
- protected:
- virtual ~ForceCloseDBCallbacks() {}
+ 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;
+ }
+
+ virtual bool IsConnected() OVERRIDE {
+ return !force_close_called_;
+ }
private:
- scoped_refptr<IndexedDBContextImpl> idb_context_;
- GURL origin_url_;
- IndexedDBConnection* connection_;
- DISALLOW_COPY_AND_ASSIGN(ForceCloseDBCallbacks);
+ bool expect_force_close_;
+ bool force_close_called_;
};
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;
@@ -165,33 +156,33 @@
scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
temp_dir.path(), special_storage_policy_, NULL, task_runner_);
- 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();
-
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();
+ 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));
+
+ 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));
idb_context->TaskRunner()->PostTask(
FROM_HERE,
@@ -204,8 +195,6 @@
// 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));
}
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698