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/file_util.h" | 8 #include "base/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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 virtual ~TestCallback() {} | 368 virtual ~TestCallback() {} |
369 | 369 |
370 private: | 370 private: |
371 DISALLOW_COPY_AND_ASSIGN(TestCallback); | 371 DISALLOW_COPY_AND_ASSIGN(TestCallback); |
372 }; | 372 }; |
373 | 373 |
374 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 374 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
375 { | 375 { |
376 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 376 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
377 transaction1.Begin(); | 377 transaction1.Begin(); |
378 ScopedVector<webkit_blob::BlobDataHandle> handles; | 378 ScopedVector<storage::BlobDataHandle> handles; |
379 IndexedDBBackingStore::RecordIdentifier record; | 379 IndexedDBBackingStore::RecordIdentifier record; |
380 leveldb::Status s = backing_store_->PutRecord( | 380 leveldb::Status s = backing_store_->PutRecord( |
381 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); | 381 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); |
382 EXPECT_TRUE(s.ok()); | 382 EXPECT_TRUE(s.ok()); |
383 scoped_refptr<TestCallback> callback(new TestCallback()); | 383 scoped_refptr<TestCallback> callback(new TestCallback()); |
384 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 384 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
385 EXPECT_TRUE(callback->called); | 385 EXPECT_TRUE(callback->called); |
386 EXPECT_TRUE(callback->succeeded); | 386 EXPECT_TRUE(callback->succeeded); |
387 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 387 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
388 } | 388 } |
(...skipping 11 matching lines...) Expand all Loading... |
400 EXPECT_TRUE(callback->succeeded); | 400 EXPECT_TRUE(callback->succeeded); |
401 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 401 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
402 EXPECT_EQ(m_value1.bits, result_value.bits); | 402 EXPECT_EQ(m_value1.bits, result_value.bits); |
403 } | 403 } |
404 } | 404 } |
405 | 405 |
406 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | 406 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { |
407 { | 407 { |
408 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 408 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
409 transaction1.Begin(); | 409 transaction1.Begin(); |
410 ScopedVector<webkit_blob::BlobDataHandle> handles; | 410 ScopedVector<storage::BlobDataHandle> handles; |
411 IndexedDBBackingStore::RecordIdentifier record; | 411 IndexedDBBackingStore::RecordIdentifier record; |
412 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 412 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
413 1, | 413 1, |
414 1, | 414 1, |
415 m_key3, | 415 m_key3, |
416 &m_value3, | 416 &m_value3, |
417 &handles, | 417 &handles, |
418 &record).ok()); | 418 &record).ok()); |
419 scoped_refptr<TestCallback> callback(new TestCallback()); | 419 scoped_refptr<TestCallback> callback(new TestCallback()); |
420 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 420 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 blob_info0.push_back(blob0); | 485 blob_info0.push_back(blob0); |
486 blob_info1.push_back(blob1); | 486 blob_info1.push_back(blob1); |
487 blob_info2.push_back(blob2); | 487 blob_info2.push_back(blob2); |
488 blob_info3.push_back(blob3); | 488 blob_info3.push_back(blob3); |
489 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 489 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
490 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 490 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
491 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 491 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
492 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 492 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
493 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 493 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
494 transaction1.Begin(); | 494 transaction1.Begin(); |
495 ScopedVector<webkit_blob::BlobDataHandle> handles; | 495 ScopedVector<storage::BlobDataHandle> handles; |
496 IndexedDBBackingStore::RecordIdentifier record; | 496 IndexedDBBackingStore::RecordIdentifier record; |
497 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 497 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
498 1, | 498 1, |
499 i + 1, | 499 i + 1, |
500 key0, | 500 key0, |
501 &value0, | 501 &value0, |
502 &handles, | 502 &handles, |
503 &record).ok()); | 503 &record).ok()); |
504 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 504 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
505 1, | 505 1, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 blob_info0.push_back(blob0); | 575 blob_info0.push_back(blob0); |
576 blob_info1.push_back(blob1); | 576 blob_info1.push_back(blob1); |
577 blob_info2.push_back(blob2); | 577 blob_info2.push_back(blob2); |
578 blob_info3.push_back(blob3); | 578 blob_info3.push_back(blob3); |
579 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 579 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
580 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 580 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
581 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 581 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
582 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 582 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
583 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 583 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
584 transaction1.Begin(); | 584 transaction1.Begin(); |
585 ScopedVector<webkit_blob::BlobDataHandle> handles; | 585 ScopedVector<storage::BlobDataHandle> handles; |
586 IndexedDBBackingStore::RecordIdentifier record; | 586 IndexedDBBackingStore::RecordIdentifier record; |
587 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 587 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
588 1, | 588 1, |
589 i + 1, | 589 i + 1, |
590 key0, | 590 key0, |
591 &value0, | 591 &value0, |
592 &handles, | 592 &handles, |
593 &record).ok()); | 593 &record).ok()); |
594 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 594 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
595 1, | 595 1, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 634 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
635 EXPECT_EQ(0UL, backing_store_->removals().size()); | 635 EXPECT_EQ(0UL, backing_store_->removals().size()); |
636 } | 636 } |
637 } | 637 } |
638 } | 638 } |
639 | 639 |
640 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 640 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
641 { | 641 { |
642 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 642 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
643 transaction1.Begin(); | 643 transaction1.Begin(); |
644 ScopedVector<webkit_blob::BlobDataHandle> handles; | 644 ScopedVector<storage::BlobDataHandle> handles; |
645 IndexedDBBackingStore::RecordIdentifier record; | 645 IndexedDBBackingStore::RecordIdentifier record; |
646 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 646 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
647 1, | 647 1, |
648 1, | 648 1, |
649 m_key3, | 649 m_key3, |
650 &m_value3, | 650 &m_value3, |
651 &handles, | 651 &handles, |
652 &record).ok()); | 652 &record).ok()); |
653 scoped_refptr<TestCallback> callback(new TestCallback()); | 653 scoped_refptr<TestCallback> callback(new TestCallback()); |
654 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 654 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 const int64 high_index_id = 1ULL << 29; | 713 const int64 high_index_id = 1ULL << 29; |
714 | 714 |
715 const int64 invalid_high_index_id = 1ULL << 37; | 715 const int64 invalid_high_index_id = 1ULL << 37; |
716 | 716 |
717 const IndexedDBKey& index_key = m_key2; | 717 const IndexedDBKey& index_key = m_key2; |
718 std::string index_key_raw; | 718 std::string index_key_raw; |
719 EncodeIDBKey(index_key, &index_key_raw); | 719 EncodeIDBKey(index_key, &index_key_raw); |
720 { | 720 { |
721 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 721 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
722 transaction1.Begin(); | 722 transaction1.Begin(); |
723 ScopedVector<webkit_blob::BlobDataHandle> handles; | 723 ScopedVector<storage::BlobDataHandle> handles; |
724 IndexedDBBackingStore::RecordIdentifier record; | 724 IndexedDBBackingStore::RecordIdentifier record; |
725 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 725 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
726 high_database_id, | 726 high_database_id, |
727 high_object_store_id, | 727 high_object_store_id, |
728 m_key1, | 728 m_key1, |
729 &m_value1, | 729 &m_value1, |
730 &handles, | 730 &handles, |
731 &record); | 731 &record); |
732 EXPECT_TRUE(s.ok()); | 732 EXPECT_TRUE(s.ok()); |
733 | 733 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 const int64 database_id = 1; | 802 const int64 database_id = 1; |
803 const int64 object_store_id = 1; | 803 const int64 object_store_id = 1; |
804 const int64 index_id = kMinimumIndexId; | 804 const int64 index_id = kMinimumIndexId; |
805 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId | 805 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId |
806 | 806 |
807 IndexedDBValue result_value; | 807 IndexedDBValue result_value; |
808 | 808 |
809 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 809 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
810 transaction1.Begin(); | 810 transaction1.Begin(); |
811 | 811 |
812 ScopedVector<webkit_blob::BlobDataHandle> handles; | 812 ScopedVector<storage::BlobDataHandle> handles; |
813 IndexedDBBackingStore::RecordIdentifier record; | 813 IndexedDBBackingStore::RecordIdentifier record; |
814 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 814 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
815 database_id, | 815 database_id, |
816 KeyPrefix::kInvalidId, | 816 KeyPrefix::kInvalidId, |
817 m_key1, | 817 m_key1, |
818 &m_value1, | 818 &m_value1, |
819 &handles, | 819 &handles, |
820 &record); | 820 &record); |
821 EXPECT_FALSE(s.ok()); | 821 EXPECT_FALSE(s.ok()); |
822 s = backing_store_->PutRecord( | 822 s = backing_store_->PutRecord( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 | 996 |
997 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 997 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
998 EXPECT_TRUE(s.ok()); | 998 EXPECT_TRUE(s.ok()); |
999 EXPECT_EQ(names.size(), 1ULL); | 999 EXPECT_EQ(names.size(), 1ULL); |
1000 EXPECT_EQ(names[0], db1_name); | 1000 EXPECT_EQ(names[0], db1_name); |
1001 } | 1001 } |
1002 | 1002 |
1003 } // namespace | 1003 } // namespace |
1004 | 1004 |
1005 } // namespace content | 1005 } // namespace content |
OLD | NEW |