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

Side by Side Diff: content/browser/indexed_db/indexed_db_database_unittest.cc

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: comments & rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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
(...skipping 21 matching lines...) Expand all
32 32
33 using base::ASCIIToUTF16; 33 using base::ASCIIToUTF16;
34 34
35 namespace { 35 namespace {
36 const int kFakeChildProcessId = 0; 36 const int kFakeChildProcessId = 0;
37 } 37 }
38 38
39 namespace content { 39 namespace content {
40 40
41 class IndexedDBDatabaseTest : public ::testing::Test { 41 class IndexedDBDatabaseTest : public ::testing::Test {
42 protected:
43 url::Origin fake_connection_origin_;
44
42 private: 45 private:
43 TestBrowserThreadBundle thread_bundle_; 46 TestBrowserThreadBundle thread_bundle_;
44 }; 47 };
45 48
46 TEST_F(IndexedDBDatabaseTest, BackingStoreRetention) { 49 TEST_F(IndexedDBDatabaseTest, BackingStoreRetention) {
47 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 50 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
48 new IndexedDBFakeBackingStore(); 51 new IndexedDBFakeBackingStore();
49 EXPECT_TRUE(backing_store->HasOneRef()); 52 EXPECT_TRUE(backing_store->HasOneRef());
50 53
51 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 54 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
(...skipping 25 matching lines...) Expand all
77 &s); 80 &s);
78 ASSERT_TRUE(s.ok()); 81 ASSERT_TRUE(s.ok());
79 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 82 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
80 83
81 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 84 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
82 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 85 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
83 new MockIndexedDBDatabaseCallbacks()); 86 new MockIndexedDBDatabaseCallbacks());
84 const int64_t transaction_id1 = 1; 87 const int64_t transaction_id1 = 1;
85 std::unique_ptr<IndexedDBPendingConnection> connection1( 88 std::unique_ptr<IndexedDBPendingConnection> connection1(
86 base::MakeUnique<IndexedDBPendingConnection>( 89 base::MakeUnique<IndexedDBPendingConnection>(
87 request1, callbacks1, kFakeChildProcessId, transaction_id1, 90 request1, callbacks1, kFakeChildProcessId, fake_connection_origin_,
88 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 91 transaction_id1, IndexedDBDatabaseMetadata::DEFAULT_VERSION));
89 db->OpenConnection(std::move(connection1)); 92 db->OpenConnection(std::move(connection1));
90 93
91 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 94 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0
92 95
93 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks()); 96 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks());
94 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2( 97 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2(
95 new MockIndexedDBDatabaseCallbacks()); 98 new MockIndexedDBDatabaseCallbacks());
96 const int64_t transaction_id2 = 2; 99 const int64_t transaction_id2 = 2;
97 std::unique_ptr<IndexedDBPendingConnection> connection2( 100 std::unique_ptr<IndexedDBPendingConnection> connection2(
98 base::MakeUnique<IndexedDBPendingConnection>( 101 base::MakeUnique<IndexedDBPendingConnection>(
99 request2, callbacks2, kFakeChildProcessId, transaction_id2, 102 request2, callbacks2, kFakeChildProcessId, fake_connection_origin_,
100 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 103 transaction_id2, IndexedDBDatabaseMetadata::DEFAULT_VERSION));
101 db->OpenConnection(std::move(connection2)); 104 db->OpenConnection(std::move(connection2));
102 105
103 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 106 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
104 107
105 request1->connection()->ForceClose(); 108 request1->connection()->ForceClose();
106 EXPECT_FALSE(request1->connection()->IsConnected()); 109 EXPECT_FALSE(request1->connection()->IsConnected());
107 110
108 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 111 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
109 112
110 request2->connection()->ForceClose(); 113 request2->connection()->ForceClose();
(...skipping 20 matching lines...) Expand all
131 &s); 134 &s);
132 ASSERT_TRUE(s.ok()); 135 ASSERT_TRUE(s.ok());
133 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 136 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
134 137
135 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( 138 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks(
136 new MockIndexedDBDatabaseCallbacks()); 139 new MockIndexedDBDatabaseCallbacks());
137 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); 140 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks());
138 const int64_t upgrade_transaction_id = 3; 141 const int64_t upgrade_transaction_id = 3;
139 std::unique_ptr<IndexedDBPendingConnection> connection( 142 std::unique_ptr<IndexedDBPendingConnection> connection(
140 base::MakeUnique<IndexedDBPendingConnection>( 143 base::MakeUnique<IndexedDBPendingConnection>(
141 request, callbacks, kFakeChildProcessId, upgrade_transaction_id, 144 request, callbacks, kFakeChildProcessId, fake_connection_origin_,
142 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 145 upgrade_transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION));
143 database->OpenConnection(std::move(connection)); 146 database->OpenConnection(std::move(connection));
144 EXPECT_EQ(database.get(), request->connection()->database()); 147 EXPECT_EQ(database.get(), request->connection()->database());
145 148
146 const int64_t transaction_id = 123; 149 const int64_t transaction_id = 123;
147 const std::vector<int64_t> scope; 150 const std::vector<int64_t> scope;
148 database->CreateTransaction(transaction_id, 151 database->CreateTransaction(transaction_id,
149 request->connection(), 152 request->connection(),
150 scope, 153 scope,
151 blink::WebIDBTransactionModeReadOnly); 154 blink::WebIDBTransactionModeReadOnly);
152 155
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 &s); 201 &s);
199 ASSERT_TRUE(s.ok()); 202 ASSERT_TRUE(s.ok());
200 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 203 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
201 204
202 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 205 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
203 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 206 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
204 new MockIndexedDBDatabaseCallbacks()); 207 new MockIndexedDBDatabaseCallbacks());
205 const int64_t transaction_id1 = 1; 208 const int64_t transaction_id1 = 1;
206 std::unique_ptr<IndexedDBPendingConnection> connection( 209 std::unique_ptr<IndexedDBPendingConnection> connection(
207 base::MakeUnique<IndexedDBPendingConnection>( 210 base::MakeUnique<IndexedDBPendingConnection>(
208 request1, callbacks1, kFakeChildProcessId, transaction_id1, 211 request1, callbacks1, kFakeChildProcessId, fake_connection_origin_,
209 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 212 transaction_id1, IndexedDBDatabaseMetadata::DEFAULT_VERSION));
210 db->OpenConnection(std::move(connection)); 213 db->OpenConnection(std::move(connection));
211 214
212 EXPECT_EQ(db->ConnectionCount(), 1UL); 215 EXPECT_EQ(db->ConnectionCount(), 1UL);
213 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); 216 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
214 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 217 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
215 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 218 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
216 219
217 scoped_refptr<MockCallbacks> request2(new MockCallbacks()); 220 scoped_refptr<MockCallbacks> request2(new MockCallbacks());
218 db->DeleteDatabase(request2); 221 db->DeleteDatabase(request2);
219 EXPECT_EQ(db->ConnectionCount(), 1UL); 222 EXPECT_EQ(db->ConnectionCount(), 1UL);
(...skipping 29 matching lines...) Expand all
249 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( 252 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create(
250 ASCIIToUTF16("db"), backing_store.get(), factory.get(), 253 ASCIIToUTF16("db"), backing_store.get(), factory.get(),
251 IndexedDBDatabase::Identifier(), &s); 254 IndexedDBDatabase::Identifier(), &s);
252 255
253 // Make a connection request. This will be processed immediately. 256 // Make a connection request. This will be processed immediately.
254 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 257 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
255 { 258 {
256 std::unique_ptr<IndexedDBPendingConnection> connection( 259 std::unique_ptr<IndexedDBPendingConnection> connection(
257 base::MakeUnique<IndexedDBPendingConnection>( 260 base::MakeUnique<IndexedDBPendingConnection>(
258 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()), 261 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
259 kFakeChildProcessId, transaction_id1, 262 kFakeChildProcessId, fake_connection_origin_, transaction_id1,
260 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 263 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
261 db->OpenConnection(std::move(connection)); 264 db->OpenConnection(std::move(connection));
262 } 265 }
263 266
264 EXPECT_EQ(db->ConnectionCount(), 1UL); 267 EXPECT_EQ(db->ConnectionCount(), 1UL);
265 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); 268 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
266 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 269 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
267 270
268 // Make a delete request. This will be blocked by the open. 271 // Make a delete request. This will be blocked by the open.
269 scoped_refptr<MockCallbacks> request2(new MockCallbacks()); 272 scoped_refptr<MockCallbacks> request2(new MockCallbacks());
(...skipping 15 matching lines...) Expand all
285 EXPECT_EQ(db->ConnectionCount(), 1UL); 288 EXPECT_EQ(db->ConnectionCount(), 1UL);
286 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); 289 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
287 EXPECT_EQ(db->PendingOpenDeleteCount(), 1UL); 290 EXPECT_EQ(db->PendingOpenDeleteCount(), 1UL);
288 291
289 // Make another connection request. This will also be waiting in the queue. 292 // Make another connection request. This will also be waiting in the queue.
290 scoped_refptr<MockCallbacks> request4(new MockCallbacks()); 293 scoped_refptr<MockCallbacks> request4(new MockCallbacks());
291 { 294 {
292 std::unique_ptr<IndexedDBPendingConnection> connection( 295 std::unique_ptr<IndexedDBPendingConnection> connection(
293 base::MakeUnique<IndexedDBPendingConnection>( 296 base::MakeUnique<IndexedDBPendingConnection>(
294 request4, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()), 297 request4, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
295 kFakeChildProcessId, transaction_id1, 298 kFakeChildProcessId, fake_connection_origin_, transaction_id1,
296 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 299 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
297 db->OpenConnection(std::move(connection)); 300 db->OpenConnection(std::move(connection));
298 } 301 }
299 302
300 EXPECT_EQ(db->ConnectionCount(), 1UL); 303 EXPECT_EQ(db->ConnectionCount(), 1UL);
301 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); 304 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
302 EXPECT_EQ(db->PendingOpenDeleteCount(), 2UL); 305 EXPECT_EQ(db->PendingOpenDeleteCount(), 2UL);
303 306
304 // Finally yet another delete request, also waiting in the queue. 307 // Finally yet another delete request, also waiting in the queue.
305 scoped_refptr<MockCallbacks> request5(new MockCallbacks()); 308 scoped_refptr<MockCallbacks> request5(new MockCallbacks());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 factory_.get(), 360 factory_.get(),
358 IndexedDBDatabase::Identifier(), 361 IndexedDBDatabase::Identifier(),
359 &s); 362 &s);
360 ASSERT_TRUE(s.ok()); 363 ASSERT_TRUE(s.ok());
361 364
362 request_ = new MockIndexedDBCallbacks(); 365 request_ = new MockIndexedDBCallbacks();
363 callbacks_ = new MockIndexedDBDatabaseCallbacks(); 366 callbacks_ = new MockIndexedDBDatabaseCallbacks();
364 const int64_t transaction_id = 1; 367 const int64_t transaction_id = 1;
365 std::unique_ptr<IndexedDBPendingConnection> connection( 368 std::unique_ptr<IndexedDBPendingConnection> connection(
366 base::MakeUnique<IndexedDBPendingConnection>( 369 base::MakeUnique<IndexedDBPendingConnection>(
367 request_, callbacks_, kFakeChildProcessId, transaction_id, 370 request_, callbacks_, kFakeChildProcessId, fake_connection_origin_,
368 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 371 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION));
369 db_->OpenConnection(std::move(connection)); 372 db_->OpenConnection(std::move(connection));
370 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); 373 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version);
371 374
372 connection_ = base::MakeUnique<IndexedDBConnection>(db_, callbacks_); 375 connection_ = base::MakeUnique<IndexedDBConnection>(
373 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( 376 kFakeChildProcessId, fake_connection_origin_, db_, callbacks_);
374 transaction_id, connection_->GetWeakPtr(), 377 transaction_ = connection_->CreateTransaction(
375 std::set<int64_t>() /*scope*/, 378 transaction_id, std::set<int64_t>() /*scope*/,
376 blink::WebIDBTransactionModeVersionChange, 379 blink::WebIDBTransactionModeVersionChange,
377 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); 380 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_));
378 db_->TransactionCreated(transaction_.get()); 381 db_->TransactionCreated(transaction_);
379 382
380 // Add a dummy task which takes the place of the VersionChangeOperation 383 // Add a dummy task which takes the place of the VersionChangeOperation
381 // which kicks off the upgrade. This ensures that the transaction has 384 // which kicks off the upgrade. This ensures that the transaction has
382 // processed at least one task before the CreateObjectStore call. 385 // processed at least one task before the CreateObjectStore call.
383 transaction_->ScheduleTask(base::Bind(&DummyOperation)); 386 transaction_->ScheduleTask(base::Bind(&DummyOperation));
384 } 387 }
385 388
386 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } 389 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); }
387 390
388 protected: 391 protected:
389 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; 392 scoped_refptr<IndexedDBFakeBackingStore> backing_store_;
390 scoped_refptr<IndexedDBDatabase> db_; 393 scoped_refptr<IndexedDBDatabase> db_;
391 scoped_refptr<MockIndexedDBCallbacks> request_; 394 scoped_refptr<MockIndexedDBCallbacks> request_;
392 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; 395 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_;
393 scoped_refptr<IndexedDBTransaction> transaction_; 396 IndexedDBTransaction* transaction_;
394 std::unique_ptr<IndexedDBConnection> connection_; 397 std::unique_ptr<IndexedDBConnection> connection_;
398 url::Origin fake_connection_origin_;
395 399
396 leveldb::Status commit_success_; 400 leveldb::Status commit_success_;
397 401
398 private: 402 private:
399 scoped_refptr<MockIndexedDBFactory> factory_; 403 scoped_refptr<MockIndexedDBFactory> factory_;
400 content::TestBrowserThreadBundle thread_bundle_; 404 content::TestBrowserThreadBundle thread_bundle_;
401 405
402 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); 406 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest);
403 }; 407 };
404 408
405 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { 409 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) {
406 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 410 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
407 const int64_t store_id = 1001; 411 const int64_t store_id = 1001;
408 db_->CreateObjectStore(transaction_->id(), 412 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
409 store_id, 413 IndexedDBKeyPath(), false /*auto_increment*/);
410 ASCIIToUTF16("store"),
411 IndexedDBKeyPath(),
412 false /*auto_increment*/);
413 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 414 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
414 RunPostedTasks(); 415 RunPostedTasks();
415 transaction_->Commit(); 416 transaction_->Commit();
416 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 417 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
417 } 418 }
418 419
419 TEST_F(IndexedDBDatabaseOperationTest, CreateIndex) { 420 TEST_F(IndexedDBDatabaseOperationTest, CreateIndex) {
420 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 421 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
421 const int64_t store_id = 1001; 422 const int64_t store_id = 1001;
422 db_->CreateObjectStore(transaction_->id(), 423 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
423 store_id, 424 IndexedDBKeyPath(), false /*auto_increment*/);
424 ASCIIToUTF16("store"),
425 IndexedDBKeyPath(),
426 false /*auto_increment*/);
427 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 425 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
428 const int64_t index_id = 2002; 426 const int64_t index_id = 2002;
429 db_->CreateIndex(transaction_->id(), 427 db_->CreateIndex(transaction_, store_id, index_id, ASCIIToUTF16("index"),
430 store_id, 428 IndexedDBKeyPath(), false /*unique*/, false /*multi_entry*/);
431 index_id,
432 ASCIIToUTF16("index"),
433 IndexedDBKeyPath(),
434 false /*unique*/,
435 false /*multi_entry*/);
436 EXPECT_EQ( 429 EXPECT_EQ(
437 1ULL, 430 1ULL,
438 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 431 db_->metadata().object_stores.find(store_id)->second.indexes.size());
439 RunPostedTasks(); 432 RunPostedTasks();
440 transaction_->Commit(); 433 transaction_->Commit();
441 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 434 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
442 EXPECT_EQ( 435 EXPECT_EQ(
443 1ULL, 436 1ULL,
444 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 437 db_->metadata().object_stores.find(store_id)->second.indexes.size());
445 } 438 }
446 439
447 class IndexedDBDatabaseOperationAbortTest 440 class IndexedDBDatabaseOperationAbortTest
448 : public IndexedDBDatabaseOperationTest { 441 : public IndexedDBDatabaseOperationTest {
449 public: 442 public:
450 IndexedDBDatabaseOperationAbortTest() { 443 IndexedDBDatabaseOperationAbortTest() {
451 commit_success_ = leveldb::Status::NotFound("Bummer."); 444 commit_success_ = leveldb::Status::NotFound("Bummer.");
452 } 445 }
453 446
447 protected:
448 url::Origin fake_connection_origin_;
449
454 private: 450 private:
455 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationAbortTest); 451 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationAbortTest);
456 }; 452 };
457 453
458 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) { 454 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) {
459 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 455 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
460 const int64_t store_id = 1001; 456 const int64_t store_id = 1001;
461 db_->CreateObjectStore(transaction_->id(), 457 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
462 store_id, 458 IndexedDBKeyPath(), false /*auto_increment*/);
463 ASCIIToUTF16("store"),
464 IndexedDBKeyPath(),
465 false /*auto_increment*/);
466 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 459 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
467 RunPostedTasks(); 460 RunPostedTasks();
468 transaction_->Commit(); 461 transaction_->Commit();
469 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 462 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
470 } 463 }
471 464
472 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateIndex) { 465 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateIndex) {
473 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 466 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
474 const int64_t store_id = 1001; 467 const int64_t store_id = 1001;
475 db_->CreateObjectStore(transaction_->id(), 468 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
476 store_id, 469 IndexedDBKeyPath(), false /*auto_increment*/);
477 ASCIIToUTF16("store"),
478 IndexedDBKeyPath(),
479 false /*auto_increment*/);
480 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 470 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
481 const int64_t index_id = 2002; 471 const int64_t index_id = 2002;
482 db_->CreateIndex(transaction_->id(), 472 db_->CreateIndex(transaction_, store_id, index_id, ASCIIToUTF16("index"),
483 store_id, 473 IndexedDBKeyPath(), false /*unique*/, false /*multi_entry*/);
484 index_id,
485 ASCIIToUTF16("index"),
486 IndexedDBKeyPath(),
487 false /*unique*/,
488 false /*multi_entry*/);
489 EXPECT_EQ( 474 EXPECT_EQ(
490 1ULL, 475 1ULL,
491 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 476 db_->metadata().object_stores.find(store_id)->second.indexes.size());
492 RunPostedTasks(); 477 RunPostedTasks();
493 transaction_->Commit(); 478 transaction_->Commit();
494 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 479 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
495 } 480 }
496 481
497 TEST_F(IndexedDBDatabaseOperationTest, CreatePutDelete) { 482 TEST_F(IndexedDBDatabaseOperationTest, CreatePutDelete) {
498 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 483 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
499 const int64_t store_id = 1001; 484 const int64_t store_id = 1001;
500 485
501 // Creation is synchronous. 486 // Creation is synchronous.
502 db_->CreateObjectStore(transaction_->id(), 487 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
503 store_id, 488 IndexedDBKeyPath(), false /*auto_increment*/);
504 ASCIIToUTF16("store"),
505 IndexedDBKeyPath(),
506 false /*auto_increment*/);
507 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 489 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
508 490
509 491
510 // Put is asynchronous 492 // Put is asynchronous
511 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>()); 493 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>());
512 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; 494 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
513 std::unique_ptr<IndexedDBKey> key(base::MakeUnique<IndexedDBKey>("key")); 495 std::unique_ptr<IndexedDBKey> key(base::MakeUnique<IndexedDBKey>("key"));
514 std::vector<IndexedDBDatabase::IndexKeys> index_keys; 496 std::vector<IndexedDBDatabase::IndexKeys> index_keys;
515 scoped_refptr<MockIndexedDBCallbacks> request( 497 scoped_refptr<MockIndexedDBCallbacks> request(
516 new MockIndexedDBCallbacks(false)); 498 new MockIndexedDBCallbacks(false));
517 db_->Put(transaction_->id(), store_id, &value, &handles, std::move(key), 499 db_->Put(transaction_, store_id, &value, &handles, std::move(key),
518 blink::WebIDBPutModeAddOnly, request, index_keys); 500 blink::WebIDBPutModeAddOnly, request, index_keys);
519 501
520 // Deletion is asynchronous. 502 // Deletion is asynchronous.
521 db_->DeleteObjectStore(transaction_->id(), 503 db_->DeleteObjectStore(transaction_, store_id);
522 store_id);
523 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 504 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
524 505
525 // This will execute the Put then Delete. 506 // This will execute the Put then Delete.
526 RunPostedTasks(); 507 RunPostedTasks();
527 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 508 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
528 509
529 transaction_->Commit(); // Cleans up the object hierarchy. 510 transaction_->Commit(); // Cleans up the object hierarchy.
530 } 511 }
531 512
532 } // namespace content 513 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698