| OLD | NEW |
| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 ~TestCallback() override {} | 379 ~TestCallback() override {} |
| 380 | 380 |
| 381 private: | 381 private: |
| 382 DISALLOW_COPY_AND_ASSIGN(TestCallback); | 382 DISALLOW_COPY_AND_ASSIGN(TestCallback); |
| 383 }; | 383 }; |
| 384 | 384 |
| 385 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 385 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
| 386 { | 386 { |
| 387 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 387 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 388 transaction1.Begin(); | 388 transaction1.Begin(); |
| 389 ScopedVector<storage::BlobDataHandle> handles; | 389 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 390 IndexedDBBackingStore::RecordIdentifier record; | 390 IndexedDBBackingStore::RecordIdentifier record; |
| 391 leveldb::Status s = backing_store_->PutRecord( | 391 leveldb::Status s = backing_store_->PutRecord( |
| 392 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); | 392 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); |
| 393 EXPECT_TRUE(s.ok()); | 393 EXPECT_TRUE(s.ok()); |
| 394 scoped_refptr<TestCallback> callback(new TestCallback()); | 394 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 395 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 395 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| 396 EXPECT_TRUE(callback->called); | 396 EXPECT_TRUE(callback->called); |
| 397 EXPECT_TRUE(callback->succeeded); | 397 EXPECT_TRUE(callback->succeeded); |
| 398 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 398 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 399 } | 399 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 411 EXPECT_TRUE(callback->succeeded); | 411 EXPECT_TRUE(callback->succeeded); |
| 412 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 412 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 413 EXPECT_EQ(m_value1.bits, result_value.bits); | 413 EXPECT_EQ(m_value1.bits, result_value.bits); |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | 417 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { |
| 418 { | 418 { |
| 419 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 419 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 420 transaction1.Begin(); | 420 transaction1.Begin(); |
| 421 ScopedVector<storage::BlobDataHandle> handles; | 421 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 422 IndexedDBBackingStore::RecordIdentifier record; | 422 IndexedDBBackingStore::RecordIdentifier record; |
| 423 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 423 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 424 1, | 424 1, |
| 425 1, | 425 1, |
| 426 m_key3, | 426 m_key3, |
| 427 &m_value3, | 427 &m_value3, |
| 428 &handles, | 428 &handles, |
| 429 &record).ok()); | 429 &record).ok()); |
| 430 scoped_refptr<TestCallback> callback(new TestCallback()); | 430 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 431 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 431 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 blob_info0.push_back(blob0); | 498 blob_info0.push_back(blob0); |
| 499 blob_info1.push_back(blob1); | 499 blob_info1.push_back(blob1); |
| 500 blob_info2.push_back(blob2); | 500 blob_info2.push_back(blob2); |
| 501 blob_info3.push_back(blob3); | 501 blob_info3.push_back(blob3); |
| 502 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 502 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
| 503 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 503 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
| 504 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 504 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
| 505 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 505 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
| 506 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 506 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 507 transaction1.Begin(); | 507 transaction1.Begin(); |
| 508 ScopedVector<storage::BlobDataHandle> handles; | 508 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 509 IndexedDBBackingStore::RecordIdentifier record; | 509 IndexedDBBackingStore::RecordIdentifier record; |
| 510 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 510 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 511 1, | 511 1, |
| 512 i + 1, | 512 i + 1, |
| 513 key0, | 513 key0, |
| 514 &value0, | 514 &value0, |
| 515 &handles, | 515 &handles, |
| 516 &record).ok()); | 516 &record).ok()); |
| 517 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 517 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 518 1, | 518 1, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 blob_info0.push_back(blob0); | 592 blob_info0.push_back(blob0); |
| 593 blob_info1.push_back(blob1); | 593 blob_info1.push_back(blob1); |
| 594 blob_info2.push_back(blob2); | 594 blob_info2.push_back(blob2); |
| 595 blob_info3.push_back(blob3); | 595 blob_info3.push_back(blob3); |
| 596 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 596 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
| 597 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 597 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
| 598 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 598 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
| 599 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 599 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
| 600 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 600 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 601 transaction1.Begin(); | 601 transaction1.Begin(); |
| 602 ScopedVector<storage::BlobDataHandle> handles; | 602 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 603 IndexedDBBackingStore::RecordIdentifier record; | 603 IndexedDBBackingStore::RecordIdentifier record; |
| 604 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 604 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 605 1, | 605 1, |
| 606 i + 1, | 606 i + 1, |
| 607 key0, | 607 key0, |
| 608 &value0, | 608 &value0, |
| 609 &handles, | 609 &handles, |
| 610 &record).ok()); | 610 &record).ok()); |
| 611 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 611 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 612 1, | 612 1, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 EXPECT_TRUE(callback->succeeded); | 654 EXPECT_TRUE(callback->succeeded); |
| 655 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 655 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 656 EXPECT_EQ(0UL, backing_store_->removals().size()); | 656 EXPECT_EQ(0UL, backing_store_->removals().size()); |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 | 660 |
| 661 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { | 661 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { |
| 662 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 662 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 663 transaction1.Begin(); | 663 transaction1.Begin(); |
| 664 ScopedVector<storage::BlobDataHandle> handles1; | 664 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles1; |
| 665 IndexedDBBackingStore::RecordIdentifier record1; | 665 IndexedDBBackingStore::RecordIdentifier record1; |
| 666 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, | 666 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, |
| 667 &handles1, &record1).ok()); | 667 &handles1, &record1).ok()); |
| 668 scoped_refptr<TestCallback> callback1(new TestCallback()); | 668 scoped_refptr<TestCallback> callback1(new TestCallback()); |
| 669 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); | 669 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); |
| 670 task_runner_->RunUntilIdle(); | 670 task_runner_->RunUntilIdle(); |
| 671 EXPECT_TRUE(CheckBlobWrites()); | 671 EXPECT_TRUE(CheckBlobWrites()); |
| 672 EXPECT_TRUE(callback1->called); | 672 EXPECT_TRUE(callback1->called); |
| 673 EXPECT_TRUE(callback1->succeeded); | 673 EXPECT_TRUE(callback1->succeeded); |
| 674 EXPECT_EQ(0U, backing_store_->removals().size()); | 674 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 675 | 675 |
| 676 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 676 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 677 transaction2.Begin(); | 677 transaction2.Begin(); |
| 678 ScopedVector<storage::BlobDataHandle> handles2; | 678 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles2; |
| 679 IndexedDBBackingStore::RecordIdentifier record2; | 679 IndexedDBBackingStore::RecordIdentifier record2; |
| 680 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, | 680 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, |
| 681 &handles2, &record2).ok()); | 681 &handles2, &record2).ok()); |
| 682 scoped_refptr<TestCallback> callback2(new TestCallback()); | 682 scoped_refptr<TestCallback> callback2(new TestCallback()); |
| 683 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); | 683 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); |
| 684 task_runner_->RunUntilIdle(); | 684 task_runner_->RunUntilIdle(); |
| 685 EXPECT_TRUE(CheckBlobWrites()); | 685 EXPECT_TRUE(CheckBlobWrites()); |
| 686 EXPECT_TRUE(callback2->called); | 686 EXPECT_TRUE(callback2->called); |
| 687 EXPECT_TRUE(callback2->succeeded); | 687 EXPECT_TRUE(callback2->succeeded); |
| 688 EXPECT_EQ(0U, backing_store_->removals().size()); | 688 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 689 | 689 |
| 690 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 690 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 691 EXPECT_EQ(0U, backing_store_->removals().size()); | 691 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 692 | 692 |
| 693 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 693 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 694 EXPECT_EQ(0U, backing_store_->removals().size()); | 694 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 695 } | 695 } |
| 696 | 696 |
| 697 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 697 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
| 698 { | 698 { |
| 699 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 699 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 700 transaction1.Begin(); | 700 transaction1.Begin(); |
| 701 ScopedVector<storage::BlobDataHandle> handles; | 701 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 702 IndexedDBBackingStore::RecordIdentifier record; | 702 IndexedDBBackingStore::RecordIdentifier record; |
| 703 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 703 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 704 1, | 704 1, |
| 705 1, | 705 1, |
| 706 m_key3, | 706 m_key3, |
| 707 &m_value3, | 707 &m_value3, |
| 708 &handles, | 708 &handles, |
| 709 &record).ok()); | 709 &record).ok()); |
| 710 scoped_refptr<TestCallback> callback(new TestCallback()); | 710 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 711 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 711 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 const int64_t high_index_id = 1ULL << 29; | 772 const int64_t high_index_id = 1ULL << 29; |
| 773 | 773 |
| 774 const int64_t invalid_high_index_id = 1ULL << 37; | 774 const int64_t invalid_high_index_id = 1ULL << 37; |
| 775 | 775 |
| 776 const IndexedDBKey& index_key = m_key2; | 776 const IndexedDBKey& index_key = m_key2; |
| 777 std::string index_key_raw; | 777 std::string index_key_raw; |
| 778 EncodeIDBKey(index_key, &index_key_raw); | 778 EncodeIDBKey(index_key, &index_key_raw); |
| 779 { | 779 { |
| 780 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 780 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 781 transaction1.Begin(); | 781 transaction1.Begin(); |
| 782 ScopedVector<storage::BlobDataHandle> handles; | 782 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 783 IndexedDBBackingStore::RecordIdentifier record; | 783 IndexedDBBackingStore::RecordIdentifier record; |
| 784 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 784 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
| 785 high_database_id, | 785 high_database_id, |
| 786 high_object_store_id, | 786 high_object_store_id, |
| 787 m_key1, | 787 m_key1, |
| 788 &m_value1, | 788 &m_value1, |
| 789 &handles, | 789 &handles, |
| 790 &record); | 790 &record); |
| 791 EXPECT_TRUE(s.ok()); | 791 EXPECT_TRUE(s.ok()); |
| 792 | 792 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 const int64_t object_store_id = 1; | 862 const int64_t object_store_id = 1; |
| 863 const int64_t index_id = kMinimumIndexId; | 863 const int64_t index_id = kMinimumIndexId; |
| 864 const int64_t invalid_low_index_id = | 864 const int64_t invalid_low_index_id = |
| 865 19; // index_ids must be > kMinimumIndexId | 865 19; // index_ids must be > kMinimumIndexId |
| 866 | 866 |
| 867 IndexedDBValue result_value; | 867 IndexedDBValue result_value; |
| 868 | 868 |
| 869 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 869 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 870 transaction1.Begin(); | 870 transaction1.Begin(); |
| 871 | 871 |
| 872 ScopedVector<storage::BlobDataHandle> handles; | 872 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 873 IndexedDBBackingStore::RecordIdentifier record; | 873 IndexedDBBackingStore::RecordIdentifier record; |
| 874 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 874 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
| 875 database_id, | 875 database_id, |
| 876 KeyPrefix::kInvalidId, | 876 KeyPrefix::kInvalidId, |
| 877 m_key1, | 877 m_key1, |
| 878 &m_value1, | 878 &m_value1, |
| 879 &handles, | 879 &handles, |
| 880 &record); | 880 &record); |
| 881 EXPECT_FALSE(s.ok()); | 881 EXPECT_FALSE(s.ok()); |
| 882 s = backing_store_->PutRecord( | 882 s = backing_store_->PutRecord( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 | 1051 |
| 1052 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 1052 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
| 1053 EXPECT_TRUE(s.ok()); | 1053 EXPECT_TRUE(s.ok()); |
| 1054 EXPECT_EQ(names.size(), 1ULL); | 1054 EXPECT_EQ(names.size(), 1ULL); |
| 1055 EXPECT_EQ(names[0], db1_name); | 1055 EXPECT_EQ(names[0], db1_name); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 } // namespace | 1058 } // namespace |
| 1059 | 1059 |
| 1060 } // namespace content | 1060 } // namespace content |
| OLD | NEW |