OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/indexed_db/indexed_db_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "content/browser/indexed_db/indexed_db.h" | 18 #include "content/browser/indexed_db/indexed_db.h" |
18 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 19 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
19 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 20 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
20 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 21 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
21 #include "content/browser/indexed_db/indexed_db_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_connection.h" |
22 #include "content/browser/indexed_db/indexed_db_cursor.h" | 23 #include "content/browser/indexed_db/indexed_db_cursor.h" |
23 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 24 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 ASSERT_TRUE(s.ok()); | 232 ASSERT_TRUE(s.ok()); |
232 | 233 |
233 request_ = new MockIndexedDBCallbacks(); | 234 request_ = new MockIndexedDBCallbacks(); |
234 callbacks_ = new MockIndexedDBDatabaseCallbacks(); | 235 callbacks_ = new MockIndexedDBDatabaseCallbacks(); |
235 const int64_t transaction_id = 1; | 236 const int64_t transaction_id = 1; |
236 db_->OpenConnection(IndexedDBPendingConnection( | 237 db_->OpenConnection(IndexedDBPendingConnection( |
237 request_, callbacks_, kFakeChildProcessId, transaction_id, | 238 request_, callbacks_, kFakeChildProcessId, transaction_id, |
238 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 239 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
239 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); | 240 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); |
240 | 241 |
| 242 connection_ = base::WrapUnique(new IndexedDBConnection(db_, callbacks_)); |
241 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( | 243 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( |
242 transaction_id, callbacks_, std::set<int64_t>() /*scope*/, | 244 transaction_id, connection_->GetWeakPtr(), |
243 blink::WebIDBTransactionModeVersionChange, db_.get(), | 245 std::set<int64_t>() /*scope*/, |
| 246 blink::WebIDBTransactionModeVersionChange, |
244 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); | 247 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); |
245 db_->TransactionCreated(transaction_.get()); | 248 db_->TransactionCreated(transaction_.get()); |
246 | 249 |
247 // Add a dummy task which takes the place of the VersionChangeOperation | 250 // Add a dummy task which takes the place of the VersionChangeOperation |
248 // which kicks off the upgrade. This ensures that the transaction has | 251 // which kicks off the upgrade. This ensures that the transaction has |
249 // processed at least one task before the CreateObjectStore call. | 252 // processed at least one task before the CreateObjectStore call. |
250 transaction_->ScheduleTask(base::Bind(&DummyOperation)); | 253 transaction_->ScheduleTask(base::Bind(&DummyOperation)); |
251 } | 254 } |
252 | 255 |
253 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } | 256 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } |
254 | 257 |
255 protected: | 258 protected: |
256 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 259 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
257 scoped_refptr<IndexedDBDatabase> db_; | 260 scoped_refptr<IndexedDBDatabase> db_; |
258 scoped_refptr<MockIndexedDBCallbacks> request_; | 261 scoped_refptr<MockIndexedDBCallbacks> request_; |
259 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; | 262 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; |
260 scoped_refptr<IndexedDBTransaction> transaction_; | 263 scoped_refptr<IndexedDBTransaction> transaction_; |
| 264 std::unique_ptr<IndexedDBConnection> connection_; |
261 | 265 |
262 leveldb::Status commit_success_; | 266 leveldb::Status commit_success_; |
263 | 267 |
264 private: | 268 private: |
265 base::MessageLoop message_loop_; | 269 base::MessageLoop message_loop_; |
266 scoped_refptr<MockIndexedDBFactory> factory_; | 270 scoped_refptr<MockIndexedDBFactory> factory_; |
267 | 271 |
268 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); | 272 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); |
269 }; | 273 }; |
270 | 274 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 393 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
390 | 394 |
391 // This will execute the Put then Delete. | 395 // This will execute the Put then Delete. |
392 RunPostedTasks(); | 396 RunPostedTasks(); |
393 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 397 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
394 | 398 |
395 transaction_->Commit(); // Cleans up the object hierarchy. | 399 transaction_->Commit(); // Cleans up the object hierarchy. |
396 } | 400 } |
397 | 401 |
398 } // namespace content | 402 } // namespace content |
OLD | NEW |