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

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: updated unittests 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 request_ = new MockIndexedDBCallbacks(); 362 request_ = new MockIndexedDBCallbacks();
363 callbacks_ = new MockIndexedDBDatabaseCallbacks(); 363 callbacks_ = new MockIndexedDBDatabaseCallbacks();
364 const int64_t transaction_id = 1; 364 const int64_t transaction_id = 1;
365 std::unique_ptr<IndexedDBPendingConnection> connection( 365 std::unique_ptr<IndexedDBPendingConnection> connection(
366 base::MakeUnique<IndexedDBPendingConnection>( 366 base::MakeUnique<IndexedDBPendingConnection>(
367 request_, callbacks_, kFakeChildProcessId, transaction_id, 367 request_, callbacks_, kFakeChildProcessId, transaction_id,
368 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 368 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
369 db_->OpenConnection(std::move(connection)); 369 db_->OpenConnection(std::move(connection));
370 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); 370 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version);
371 371
372 connection_ = base::MakeUnique<IndexedDBConnection>(db_, callbacks_); 372 connection_ = base::MakeUnique<IndexedDBConnection>(kFakeChildProcessId,
cmumford 2016/11/04 23:33:12 If you switch to base::ProcessId can you also use
dmurph 2016/11/07 20:05:23 Can't due to population stack (it's given as int).
373 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( 373 db_, callbacks_);
374 transaction_id, connection_->GetWeakPtr(), 374 transaction_ = connection_->CreateTransaction(
375 std::set<int64_t>() /*scope*/, 375 transaction_id, std::set<int64_t>() /*scope*/,
376 blink::WebIDBTransactionModeVersionChange, 376 blink::WebIDBTransactionModeVersionChange,
377 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); 377 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_));
378 db_->TransactionCreated(transaction_.get()); 378 db_->TransactionCreated(transaction_);
379 379
380 // Add a dummy task which takes the place of the VersionChangeOperation 380 // Add a dummy task which takes the place of the VersionChangeOperation
381 // which kicks off the upgrade. This ensures that the transaction has 381 // which kicks off the upgrade. This ensures that the transaction has
382 // processed at least one task before the CreateObjectStore call. 382 // processed at least one task before the CreateObjectStore call.
383 transaction_->ScheduleTask(base::Bind(&DummyOperation)); 383 transaction_->ScheduleTask(base::Bind(&DummyOperation));
384 } 384 }
385 385
386 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } 386 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); }
387 387
388 protected: 388 protected:
389 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; 389 scoped_refptr<IndexedDBFakeBackingStore> backing_store_;
390 scoped_refptr<IndexedDBDatabase> db_; 390 scoped_refptr<IndexedDBDatabase> db_;
391 scoped_refptr<MockIndexedDBCallbacks> request_; 391 scoped_refptr<MockIndexedDBCallbacks> request_;
392 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; 392 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_;
393 scoped_refptr<IndexedDBTransaction> transaction_; 393 IndexedDBTransaction* transaction_;
394 std::unique_ptr<IndexedDBConnection> connection_; 394 std::unique_ptr<IndexedDBConnection> connection_;
395 395
396 leveldb::Status commit_success_; 396 leveldb::Status commit_success_;
397 397
398 private: 398 private:
399 scoped_refptr<MockIndexedDBFactory> factory_; 399 scoped_refptr<MockIndexedDBFactory> factory_;
400 content::TestBrowserThreadBundle thread_bundle_; 400 content::TestBrowserThreadBundle thread_bundle_;
401 401
402 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); 402 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest);
403 }; 403 };
404 404
405 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { 405 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) {
406 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 406 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
407 const int64_t store_id = 1001; 407 const int64_t store_id = 1001;
408 db_->CreateObjectStore(transaction_->id(), 408 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
409 store_id, 409 IndexedDBKeyPath(), false /*auto_increment*/);
410 ASCIIToUTF16("store"),
411 IndexedDBKeyPath(),
412 false /*auto_increment*/);
413 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 410 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
414 RunPostedTasks(); 411 RunPostedTasks();
415 transaction_->Commit(); 412 transaction_->Commit();
416 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 413 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
417 } 414 }
418 415
419 TEST_F(IndexedDBDatabaseOperationTest, CreateIndex) { 416 TEST_F(IndexedDBDatabaseOperationTest, CreateIndex) {
420 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 417 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
421 const int64_t store_id = 1001; 418 const int64_t store_id = 1001;
422 db_->CreateObjectStore(transaction_->id(), 419 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
423 store_id, 420 IndexedDBKeyPath(), false /*auto_increment*/);
424 ASCIIToUTF16("store"),
425 IndexedDBKeyPath(),
426 false /*auto_increment*/);
427 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 421 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
428 const int64_t index_id = 2002; 422 const int64_t index_id = 2002;
429 db_->CreateIndex(transaction_->id(), 423 db_->CreateIndex(transaction_, store_id, index_id, ASCIIToUTF16("index"),
430 store_id, 424 IndexedDBKeyPath(), false /*unique*/, false /*multi_entry*/);
431 index_id,
432 ASCIIToUTF16("index"),
433 IndexedDBKeyPath(),
434 false /*unique*/,
435 false /*multi_entry*/);
436 EXPECT_EQ( 425 EXPECT_EQ(
437 1ULL, 426 1ULL,
438 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 427 db_->metadata().object_stores.find(store_id)->second.indexes.size());
439 RunPostedTasks(); 428 RunPostedTasks();
440 transaction_->Commit(); 429 transaction_->Commit();
441 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 430 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
442 EXPECT_EQ( 431 EXPECT_EQ(
443 1ULL, 432 1ULL,
444 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 433 db_->metadata().object_stores.find(store_id)->second.indexes.size());
445 } 434 }
446 435
447 class IndexedDBDatabaseOperationAbortTest 436 class IndexedDBDatabaseOperationAbortTest
448 : public IndexedDBDatabaseOperationTest { 437 : public IndexedDBDatabaseOperationTest {
449 public: 438 public:
450 IndexedDBDatabaseOperationAbortTest() { 439 IndexedDBDatabaseOperationAbortTest() {
451 commit_success_ = leveldb::Status::NotFound("Bummer."); 440 commit_success_ = leveldb::Status::NotFound("Bummer.");
452 } 441 }
453 442
454 private: 443 private:
455 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationAbortTest); 444 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationAbortTest);
456 }; 445 };
457 446
458 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) { 447 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) {
459 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 448 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
460 const int64_t store_id = 1001; 449 const int64_t store_id = 1001;
461 db_->CreateObjectStore(transaction_->id(), 450 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
462 store_id, 451 IndexedDBKeyPath(), false /*auto_increment*/);
463 ASCIIToUTF16("store"),
464 IndexedDBKeyPath(),
465 false /*auto_increment*/);
466 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 452 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
467 RunPostedTasks(); 453 RunPostedTasks();
468 transaction_->Commit(); 454 transaction_->Commit();
469 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 455 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
470 } 456 }
471 457
472 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateIndex) { 458 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateIndex) {
473 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 459 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
474 const int64_t store_id = 1001; 460 const int64_t store_id = 1001;
475 db_->CreateObjectStore(transaction_->id(), 461 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
476 store_id, 462 IndexedDBKeyPath(), false /*auto_increment*/);
477 ASCIIToUTF16("store"),
478 IndexedDBKeyPath(),
479 false /*auto_increment*/);
480 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 463 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
481 const int64_t index_id = 2002; 464 const int64_t index_id = 2002;
482 db_->CreateIndex(transaction_->id(), 465 db_->CreateIndex(transaction_, store_id, index_id, ASCIIToUTF16("index"),
483 store_id, 466 IndexedDBKeyPath(), false /*unique*/, false /*multi_entry*/);
484 index_id,
485 ASCIIToUTF16("index"),
486 IndexedDBKeyPath(),
487 false /*unique*/,
488 false /*multi_entry*/);
489 EXPECT_EQ( 467 EXPECT_EQ(
490 1ULL, 468 1ULL,
491 db_->metadata().object_stores.find(store_id)->second.indexes.size()); 469 db_->metadata().object_stores.find(store_id)->second.indexes.size());
492 RunPostedTasks(); 470 RunPostedTasks();
493 transaction_->Commit(); 471 transaction_->Commit();
494 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 472 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
495 } 473 }
496 474
497 TEST_F(IndexedDBDatabaseOperationTest, CreatePutDelete) { 475 TEST_F(IndexedDBDatabaseOperationTest, CreatePutDelete) {
498 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 476 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
499 const int64_t store_id = 1001; 477 const int64_t store_id = 1001;
500 478
501 // Creation is synchronous. 479 // Creation is synchronous.
502 db_->CreateObjectStore(transaction_->id(), 480 db_->CreateObjectStore(transaction_, store_id, ASCIIToUTF16("store"),
503 store_id, 481 IndexedDBKeyPath(), false /*auto_increment*/);
504 ASCIIToUTF16("store"),
505 IndexedDBKeyPath(),
506 false /*auto_increment*/);
507 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 482 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
508 483
509 484
510 // Put is asynchronous 485 // Put is asynchronous
511 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>()); 486 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>());
512 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; 487 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
513 std::unique_ptr<IndexedDBKey> key(base::MakeUnique<IndexedDBKey>("key")); 488 std::unique_ptr<IndexedDBKey> key(base::MakeUnique<IndexedDBKey>("key"));
514 std::vector<IndexedDBDatabase::IndexKeys> index_keys; 489 std::vector<IndexedDBDatabase::IndexKeys> index_keys;
515 scoped_refptr<MockIndexedDBCallbacks> request( 490 scoped_refptr<MockIndexedDBCallbacks> request(
516 new MockIndexedDBCallbacks(false)); 491 new MockIndexedDBCallbacks(false));
517 db_->Put(transaction_->id(), store_id, &value, &handles, std::move(key), 492 db_->Put(transaction_, store_id, &value, &handles, std::move(key),
518 blink::WebIDBPutModeAddOnly, request, index_keys); 493 blink::WebIDBPutModeAddOnly, request, index_keys);
519 494
520 // Deletion is asynchronous. 495 // Deletion is asynchronous.
521 db_->DeleteObjectStore(transaction_->id(), 496 db_->DeleteObjectStore(transaction_, store_id);
522 store_id);
523 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 497 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
524 498
525 // This will execute the Put then Delete. 499 // This will execute the Put then Delete.
526 RunPostedTasks(); 500 RunPostedTasks();
527 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 501 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
528 502
529 transaction_->Commit(); // Cleans up the object hierarchy. 503 transaction_->Commit(); // Cleans up the object hierarchy.
530 } 504 }
531 505
532 } // namespace content 506 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698