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

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

Issue 2255853003: IndexedDB: ScopedVector<T> -> vector<unique_ptr<T>> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 ~TestCallback() override {} 376 ~TestCallback() override {}
377 377
378 private: 378 private:
379 DISALLOW_COPY_AND_ASSIGN(TestCallback); 379 DISALLOW_COPY_AND_ASSIGN(TestCallback);
380 }; 380 };
381 381
382 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { 382 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) {
383 { 383 {
384 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 384 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
385 transaction1.Begin(); 385 transaction1.Begin();
386 ScopedVector<storage::BlobDataHandle> handles; 386 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
387 IndexedDBBackingStore::RecordIdentifier record; 387 IndexedDBBackingStore::RecordIdentifier record;
388 leveldb::Status s = backing_store_->PutRecord( 388 leveldb::Status s = backing_store_->PutRecord(
389 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); 389 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record);
390 EXPECT_TRUE(s.ok()); 390 EXPECT_TRUE(s.ok());
391 scoped_refptr<TestCallback> callback(new TestCallback()); 391 scoped_refptr<TestCallback> callback(new TestCallback());
392 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); 392 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
393 EXPECT_TRUE(callback->called); 393 EXPECT_TRUE(callback->called);
394 EXPECT_TRUE(callback->succeeded); 394 EXPECT_TRUE(callback->succeeded);
395 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); 395 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok());
396 } 396 }
(...skipping 11 matching lines...) Expand all
408 EXPECT_TRUE(callback->succeeded); 408 EXPECT_TRUE(callback->succeeded);
409 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); 409 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok());
410 EXPECT_EQ(m_value1.bits, result_value.bits); 410 EXPECT_EQ(m_value1.bits, result_value.bits);
411 } 411 }
412 } 412 }
413 413
414 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { 414 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) {
415 { 415 {
416 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 416 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
417 transaction1.Begin(); 417 transaction1.Begin();
418 ScopedVector<storage::BlobDataHandle> handles; 418 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
419 IndexedDBBackingStore::RecordIdentifier record; 419 IndexedDBBackingStore::RecordIdentifier record;
420 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 420 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
421 1, 421 1,
422 1, 422 1,
423 m_key3, 423 m_key3,
424 &m_value3, 424 &m_value3,
425 &handles, 425 &handles,
426 &record).ok()); 426 &record).ok());
427 scoped_refptr<TestCallback> callback(new TestCallback()); 427 scoped_refptr<TestCallback> callback(new TestCallback());
428 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); 428 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 blob_info0.push_back(blob0); 495 blob_info0.push_back(blob0);
496 blob_info1.push_back(blob1); 496 blob_info1.push_back(blob1);
497 blob_info2.push_back(blob2); 497 blob_info2.push_back(blob2);
498 blob_info3.push_back(blob3); 498 blob_info3.push_back(blob3);
499 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); 499 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0);
500 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); 500 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1);
501 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); 501 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2);
502 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); 502 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3);
503 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 503 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
504 transaction1.Begin(); 504 transaction1.Begin();
505 ScopedVector<storage::BlobDataHandle> handles; 505 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
506 IndexedDBBackingStore::RecordIdentifier record; 506 IndexedDBBackingStore::RecordIdentifier record;
507 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 507 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
508 1, 508 1,
509 i + 1, 509 i + 1,
510 key0, 510 key0,
511 &value0, 511 &value0,
512 &handles, 512 &handles,
513 &record).ok()); 513 &record).ok());
514 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 514 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
515 1, 515 1,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 blob_info0.push_back(blob0); 589 blob_info0.push_back(blob0);
590 blob_info1.push_back(blob1); 590 blob_info1.push_back(blob1);
591 blob_info2.push_back(blob2); 591 blob_info2.push_back(blob2);
592 blob_info3.push_back(blob3); 592 blob_info3.push_back(blob3);
593 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); 593 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0);
594 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); 594 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1);
595 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); 595 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2);
596 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); 596 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3);
597 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 597 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
598 transaction1.Begin(); 598 transaction1.Begin();
599 ScopedVector<storage::BlobDataHandle> handles; 599 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
600 IndexedDBBackingStore::RecordIdentifier record; 600 IndexedDBBackingStore::RecordIdentifier record;
601 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 601 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
602 1, 602 1,
603 i + 1, 603 i + 1,
604 key0, 604 key0,
605 &value0, 605 &value0,
606 &handles, 606 &handles,
607 &record).ok()); 607 &record).ok());
608 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 608 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
609 1, 609 1,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 EXPECT_TRUE(callback->succeeded); 651 EXPECT_TRUE(callback->succeeded);
652 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); 652 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok());
653 EXPECT_EQ(0UL, backing_store_->removals().size()); 653 EXPECT_EQ(0UL, backing_store_->removals().size());
654 } 654 }
655 } 655 }
656 } 656 }
657 657
658 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { 658 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) {
659 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 659 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
660 transaction1.Begin(); 660 transaction1.Begin();
661 ScopedVector<storage::BlobDataHandle> handles1; 661 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles1;
662 IndexedDBBackingStore::RecordIdentifier record1; 662 IndexedDBBackingStore::RecordIdentifier record1;
663 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, 663 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3,
664 &handles1, &record1).ok()); 664 &handles1, &record1).ok());
665 scoped_refptr<TestCallback> callback1(new TestCallback()); 665 scoped_refptr<TestCallback> callback1(new TestCallback());
666 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); 666 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok());
667 task_runner_->RunUntilIdle(); 667 task_runner_->RunUntilIdle();
668 EXPECT_TRUE(CheckBlobWrites()); 668 EXPECT_TRUE(CheckBlobWrites());
669 EXPECT_TRUE(callback1->called); 669 EXPECT_TRUE(callback1->called);
670 EXPECT_TRUE(callback1->succeeded); 670 EXPECT_TRUE(callback1->succeeded);
671 EXPECT_EQ(0U, backing_store_->removals().size()); 671 EXPECT_EQ(0U, backing_store_->removals().size());
672 672
673 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); 673 IndexedDBBackingStore::Transaction transaction2(backing_store_.get());
674 transaction2.Begin(); 674 transaction2.Begin();
675 ScopedVector<storage::BlobDataHandle> handles2; 675 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles2;
676 IndexedDBBackingStore::RecordIdentifier record2; 676 IndexedDBBackingStore::RecordIdentifier record2;
677 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, 677 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1,
678 &handles2, &record2).ok()); 678 &handles2, &record2).ok());
679 scoped_refptr<TestCallback> callback2(new TestCallback()); 679 scoped_refptr<TestCallback> callback2(new TestCallback());
680 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); 680 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok());
681 task_runner_->RunUntilIdle(); 681 task_runner_->RunUntilIdle();
682 EXPECT_TRUE(CheckBlobWrites()); 682 EXPECT_TRUE(CheckBlobWrites());
683 EXPECT_TRUE(callback2->called); 683 EXPECT_TRUE(callback2->called);
684 EXPECT_TRUE(callback2->succeeded); 684 EXPECT_TRUE(callback2->succeeded);
685 EXPECT_EQ(0U, backing_store_->removals().size()); 685 EXPECT_EQ(0U, backing_store_->removals().size());
686 686
687 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); 687 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok());
688 EXPECT_EQ(0U, backing_store_->removals().size()); 688 EXPECT_EQ(0U, backing_store_->removals().size());
689 689
690 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); 690 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok());
691 EXPECT_EQ(0U, backing_store_->removals().size()); 691 EXPECT_EQ(0U, backing_store_->removals().size());
692 } 692 }
693 693
694 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { 694 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) {
695 { 695 {
696 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 696 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
697 transaction1.Begin(); 697 transaction1.Begin();
698 ScopedVector<storage::BlobDataHandle> handles; 698 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
699 IndexedDBBackingStore::RecordIdentifier record; 699 IndexedDBBackingStore::RecordIdentifier record;
700 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 700 EXPECT_TRUE(backing_store_->PutRecord(&transaction1,
701 1, 701 1,
702 1, 702 1,
703 m_key3, 703 m_key3,
704 &m_value3, 704 &m_value3,
705 &handles, 705 &handles,
706 &record).ok()); 706 &record).ok());
707 scoped_refptr<TestCallback> callback(new TestCallback()); 707 scoped_refptr<TestCallback> callback(new TestCallback());
708 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); 708 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 const int64_t high_index_id = 1ULL << 29; 769 const int64_t high_index_id = 1ULL << 29;
770 770
771 const int64_t invalid_high_index_id = 1ULL << 37; 771 const int64_t invalid_high_index_id = 1ULL << 37;
772 772
773 const IndexedDBKey& index_key = m_key2; 773 const IndexedDBKey& index_key = m_key2;
774 std::string index_key_raw; 774 std::string index_key_raw;
775 EncodeIDBKey(index_key, &index_key_raw); 775 EncodeIDBKey(index_key, &index_key_raw);
776 { 776 {
777 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 777 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
778 transaction1.Begin(); 778 transaction1.Begin();
779 ScopedVector<storage::BlobDataHandle> handles; 779 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
780 IndexedDBBackingStore::RecordIdentifier record; 780 IndexedDBBackingStore::RecordIdentifier record;
781 leveldb::Status s = backing_store_->PutRecord(&transaction1, 781 leveldb::Status s = backing_store_->PutRecord(&transaction1,
782 high_database_id, 782 high_database_id,
783 high_object_store_id, 783 high_object_store_id,
784 m_key1, 784 m_key1,
785 &m_value1, 785 &m_value1,
786 &handles, 786 &handles,
787 &record); 787 &record);
788 EXPECT_TRUE(s.ok()); 788 EXPECT_TRUE(s.ok());
789 789
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 const int64_t object_store_id = 1; 859 const int64_t object_store_id = 1;
860 const int64_t index_id = kMinimumIndexId; 860 const int64_t index_id = kMinimumIndexId;
861 const int64_t invalid_low_index_id = 861 const int64_t invalid_low_index_id =
862 19; // index_ids must be > kMinimumIndexId 862 19; // index_ids must be > kMinimumIndexId
863 863
864 IndexedDBValue result_value; 864 IndexedDBValue result_value;
865 865
866 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 866 IndexedDBBackingStore::Transaction transaction1(backing_store_.get());
867 transaction1.Begin(); 867 transaction1.Begin();
868 868
869 ScopedVector<storage::BlobDataHandle> handles; 869 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
870 IndexedDBBackingStore::RecordIdentifier record; 870 IndexedDBBackingStore::RecordIdentifier record;
871 leveldb::Status s = backing_store_->PutRecord(&transaction1, 871 leveldb::Status s = backing_store_->PutRecord(&transaction1,
872 database_id, 872 database_id,
873 KeyPrefix::kInvalidId, 873 KeyPrefix::kInvalidId,
874 m_key1, 874 m_key1,
875 &m_value1, 875 &m_value1,
876 &handles, 876 &handles,
877 &record); 877 &record);
878 EXPECT_FALSE(s.ok()); 878 EXPECT_FALSE(s.ok());
879 s = backing_store_->PutRecord( 879 s = backing_store_->PutRecord(
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 1048
1049 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); 1049 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s);
1050 EXPECT_TRUE(s.ok()); 1050 EXPECT_TRUE(s.ok());
1051 EXPECT_EQ(names.size(), 1ULL); 1051 EXPECT_EQ(names.size(), 1ULL);
1052 EXPECT_EQ(names[0], db1_name); 1052 EXPECT_EQ(names[0], db1_name);
1053 } 1053 }
1054 1054
1055 } // namespace 1055 } // namespace
1056 1056
1057 } // namespace content 1057 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698