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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 ~TestCallback() override {} | 375 ~TestCallback() override {} |
376 | 376 |
377 private: | 377 private: |
378 DISALLOW_COPY_AND_ASSIGN(TestCallback); | 378 DISALLOW_COPY_AND_ASSIGN(TestCallback); |
379 }; | 379 }; |
380 | 380 |
381 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 381 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
382 { | 382 { |
383 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 383 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
384 transaction1.Begin(); | 384 transaction1.Begin(); |
385 ScopedVector<storage::BlobDataHandle> handles; | 385 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
386 IndexedDBBackingStore::RecordIdentifier record; | 386 IndexedDBBackingStore::RecordIdentifier record; |
387 leveldb::Status s = backing_store_->PutRecord( | 387 leveldb::Status s = backing_store_->PutRecord( |
388 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); | 388 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); |
389 EXPECT_TRUE(s.ok()); | 389 EXPECT_TRUE(s.ok()); |
390 scoped_refptr<TestCallback> callback(new TestCallback()); | 390 scoped_refptr<TestCallback> callback(new TestCallback()); |
391 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 391 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
392 EXPECT_TRUE(callback->called); | 392 EXPECT_TRUE(callback->called); |
393 EXPECT_TRUE(callback->succeeded); | 393 EXPECT_TRUE(callback->succeeded); |
394 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 394 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
395 } | 395 } |
(...skipping 11 matching lines...) Expand all Loading... |
407 EXPECT_TRUE(callback->succeeded); | 407 EXPECT_TRUE(callback->succeeded); |
408 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 408 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
409 EXPECT_EQ(m_value1.bits, result_value.bits); | 409 EXPECT_EQ(m_value1.bits, result_value.bits); |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | 413 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { |
414 { | 414 { |
415 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 415 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
416 transaction1.Begin(); | 416 transaction1.Begin(); |
417 ScopedVector<storage::BlobDataHandle> handles; | 417 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
418 IndexedDBBackingStore::RecordIdentifier record; | 418 IndexedDBBackingStore::RecordIdentifier record; |
419 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 419 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
420 1, | 420 1, |
421 1, | 421 1, |
422 m_key3, | 422 m_key3, |
423 &m_value3, | 423 &m_value3, |
424 &handles, | 424 &handles, |
425 &record).ok()); | 425 &record).ok()); |
426 scoped_refptr<TestCallback> callback(new TestCallback()); | 426 scoped_refptr<TestCallback> callback(new TestCallback()); |
427 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 427 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 blob_info0.push_back(blob0); | 492 blob_info0.push_back(blob0); |
493 blob_info1.push_back(blob1); | 493 blob_info1.push_back(blob1); |
494 blob_info2.push_back(blob2); | 494 blob_info2.push_back(blob2); |
495 blob_info3.push_back(blob3); | 495 blob_info3.push_back(blob3); |
496 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 496 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
497 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 497 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
498 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 498 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
499 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 499 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
500 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 500 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
501 transaction1.Begin(); | 501 transaction1.Begin(); |
502 ScopedVector<storage::BlobDataHandle> handles; | 502 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
503 IndexedDBBackingStore::RecordIdentifier record; | 503 IndexedDBBackingStore::RecordIdentifier record; |
504 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 504 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
505 1, | 505 1, |
506 i + 1, | 506 i + 1, |
507 key0, | 507 key0, |
508 &value0, | 508 &value0, |
509 &handles, | 509 &handles, |
510 &record).ok()); | 510 &record).ok()); |
511 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 511 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
512 1, | 512 1, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 blob_info0.push_back(blob0); | 582 blob_info0.push_back(blob0); |
583 blob_info1.push_back(blob1); | 583 blob_info1.push_back(blob1); |
584 blob_info2.push_back(blob2); | 584 blob_info2.push_back(blob2); |
585 blob_info3.push_back(blob3); | 585 blob_info3.push_back(blob3); |
586 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 586 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
587 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 587 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
588 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 588 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
589 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 589 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
590 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 590 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
591 transaction1.Begin(); | 591 transaction1.Begin(); |
592 ScopedVector<storage::BlobDataHandle> handles; | 592 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
593 IndexedDBBackingStore::RecordIdentifier record; | 593 IndexedDBBackingStore::RecordIdentifier record; |
594 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 594 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
595 1, | 595 1, |
596 i + 1, | 596 i + 1, |
597 key0, | 597 key0, |
598 &value0, | 598 &value0, |
599 &handles, | 599 &handles, |
600 &record).ok()); | 600 &record).ok()); |
601 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 601 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
602 1, | 602 1, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 641 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
642 EXPECT_EQ(0UL, backing_store_->removals().size()); | 642 EXPECT_EQ(0UL, backing_store_->removals().size()); |
643 } | 643 } |
644 } | 644 } |
645 } | 645 } |
646 | 646 |
647 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 647 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
648 { | 648 { |
649 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 649 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
650 transaction1.Begin(); | 650 transaction1.Begin(); |
651 ScopedVector<storage::BlobDataHandle> handles; | 651 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
652 IndexedDBBackingStore::RecordIdentifier record; | 652 IndexedDBBackingStore::RecordIdentifier record; |
653 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 653 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
654 1, | 654 1, |
655 1, | 655 1, |
656 m_key3, | 656 m_key3, |
657 &m_value3, | 657 &m_value3, |
658 &handles, | 658 &handles, |
659 &record).ok()); | 659 &record).ok()); |
660 scoped_refptr<TestCallback> callback(new TestCallback()); | 660 scoped_refptr<TestCallback> callback(new TestCallback()); |
661 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 661 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 const int64 high_index_id = 1ULL << 29; | 720 const int64 high_index_id = 1ULL << 29; |
721 | 721 |
722 const int64 invalid_high_index_id = 1ULL << 37; | 722 const int64 invalid_high_index_id = 1ULL << 37; |
723 | 723 |
724 const IndexedDBKey& index_key = m_key2; | 724 const IndexedDBKey& index_key = m_key2; |
725 std::string index_key_raw; | 725 std::string index_key_raw; |
726 EncodeIDBKey(index_key, &index_key_raw); | 726 EncodeIDBKey(index_key, &index_key_raw); |
727 { | 727 { |
728 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 728 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
729 transaction1.Begin(); | 729 transaction1.Begin(); |
730 ScopedVector<storage::BlobDataHandle> handles; | 730 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
731 IndexedDBBackingStore::RecordIdentifier record; | 731 IndexedDBBackingStore::RecordIdentifier record; |
732 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 732 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
733 high_database_id, | 733 high_database_id, |
734 high_object_store_id, | 734 high_object_store_id, |
735 m_key1, | 735 m_key1, |
736 &m_value1, | 736 &m_value1, |
737 &handles, | 737 &handles, |
738 &record); | 738 &record); |
739 EXPECT_TRUE(s.ok()); | 739 EXPECT_TRUE(s.ok()); |
740 | 740 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 const int64 database_id = 1; | 809 const int64 database_id = 1; |
810 const int64 object_store_id = 1; | 810 const int64 object_store_id = 1; |
811 const int64 index_id = kMinimumIndexId; | 811 const int64 index_id = kMinimumIndexId; |
812 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId | 812 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId |
813 | 813 |
814 IndexedDBValue result_value; | 814 IndexedDBValue result_value; |
815 | 815 |
816 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 816 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
817 transaction1.Begin(); | 817 transaction1.Begin(); |
818 | 818 |
819 ScopedVector<storage::BlobDataHandle> handles; | 819 ScopedVector<storage::BlobDataSnapshotHandle> handles; |
820 IndexedDBBackingStore::RecordIdentifier record; | 820 IndexedDBBackingStore::RecordIdentifier record; |
821 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 821 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
822 database_id, | 822 database_id, |
823 KeyPrefix::kInvalidId, | 823 KeyPrefix::kInvalidId, |
824 m_key1, | 824 m_key1, |
825 &m_value1, | 825 &m_value1, |
826 &handles, | 826 &handles, |
827 &record); | 827 &record); |
828 EXPECT_FALSE(s.ok()); | 828 EXPECT_FALSE(s.ok()); |
829 s = backing_store_->PutRecord( | 829 s = backing_store_->PutRecord( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 | 1003 |
1004 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 1004 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
1005 EXPECT_TRUE(s.ok()); | 1005 EXPECT_TRUE(s.ok()); |
1006 EXPECT_EQ(names.size(), 1ULL); | 1006 EXPECT_EQ(names.size(), 1ULL); |
1007 EXPECT_EQ(names[0], db1_name); | 1007 EXPECT_EQ(names[0], db1_name); |
1008 } | 1008 } |
1009 | 1009 |
1010 } // namespace | 1010 } // namespace |
1011 | 1011 |
1012 } // namespace content | 1012 } // namespace content |
OLD | NEW |