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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
17 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
18 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 18 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
19 #include "content/browser/indexed_db/indexed_db_value.h" | 19 #include "content/browser/indexed_db/indexed_db_value.h" |
20 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" | 20 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" |
21 #include "content/public/test/mock_special_storage_policy.h" | 21 #include "content/public/test/mock_special_storage_policy.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/WebKit/public/platform/WebIDBTypes.h" | 25 #include "third_party/WebKit/public/platform/WebIDBTypes.h" |
26 #include "webkit/browser/blob/blob_data_handle.h" | 26 #include "storage/browser/blob/blob_data_handle.h" |
27 #include "webkit/browser/quota/special_storage_policy.h" | 27 #include "storage/browser/quota/special_storage_policy.h" |
28 | 28 |
29 using base::ASCIIToUTF16; | 29 using base::ASCIIToUTF16; |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 class Comparator : public LevelDBComparator { | 35 class Comparator : public LevelDBComparator { |
36 public: | 36 public: |
37 virtual int Compare(const base::StringPiece& a, | 37 virtual int Compare(const base::StringPiece& a, |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 virtual ~TestCallback() {} | 367 virtual ~TestCallback() {} |
368 | 368 |
369 private: | 369 private: |
370 DISALLOW_COPY_AND_ASSIGN(TestCallback); | 370 DISALLOW_COPY_AND_ASSIGN(TestCallback); |
371 }; | 371 }; |
372 | 372 |
373 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 373 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
374 { | 374 { |
375 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 375 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
376 transaction1.Begin(); | 376 transaction1.Begin(); |
377 ScopedVector<webkit_blob::BlobDataHandle> handles; | 377 ScopedVector<storage::BlobDataHandle> handles; |
378 IndexedDBBackingStore::RecordIdentifier record; | 378 IndexedDBBackingStore::RecordIdentifier record; |
379 leveldb::Status s = backing_store_->PutRecord( | 379 leveldb::Status s = backing_store_->PutRecord( |
380 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); | 380 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); |
381 EXPECT_TRUE(s.ok()); | 381 EXPECT_TRUE(s.ok()); |
382 scoped_refptr<TestCallback> callback(new TestCallback()); | 382 scoped_refptr<TestCallback> callback(new TestCallback()); |
383 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 383 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
384 EXPECT_TRUE(callback->called); | 384 EXPECT_TRUE(callback->called); |
385 EXPECT_TRUE(callback->succeeded); | 385 EXPECT_TRUE(callback->succeeded); |
386 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 386 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
387 } | 387 } |
(...skipping 11 matching lines...) Expand all Loading... |
399 EXPECT_TRUE(callback->succeeded); | 399 EXPECT_TRUE(callback->succeeded); |
400 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 400 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
401 EXPECT_EQ(m_value1.bits, result_value.bits); | 401 EXPECT_EQ(m_value1.bits, result_value.bits); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | 405 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { |
406 { | 406 { |
407 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 407 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
408 transaction1.Begin(); | 408 transaction1.Begin(); |
409 ScopedVector<webkit_blob::BlobDataHandle> handles; | 409 ScopedVector<storage::BlobDataHandle> handles; |
410 IndexedDBBackingStore::RecordIdentifier record; | 410 IndexedDBBackingStore::RecordIdentifier record; |
411 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 411 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
412 1, | 412 1, |
413 1, | 413 1, |
414 m_key3, | 414 m_key3, |
415 &m_value3, | 415 &m_value3, |
416 &handles, | 416 &handles, |
417 &record).ok()); | 417 &record).ok()); |
418 scoped_refptr<TestCallback> callback(new TestCallback()); | 418 scoped_refptr<TestCallback> callback(new TestCallback()); |
419 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 419 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 blob_info0.push_back(blob0); | 484 blob_info0.push_back(blob0); |
485 blob_info1.push_back(blob1); | 485 blob_info1.push_back(blob1); |
486 blob_info2.push_back(blob2); | 486 blob_info2.push_back(blob2); |
487 blob_info3.push_back(blob3); | 487 blob_info3.push_back(blob3); |
488 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 488 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
489 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 489 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
490 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 490 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
491 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 491 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
492 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 492 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
493 transaction1.Begin(); | 493 transaction1.Begin(); |
494 ScopedVector<webkit_blob::BlobDataHandle> handles; | 494 ScopedVector<storage::BlobDataHandle> handles; |
495 IndexedDBBackingStore::RecordIdentifier record; | 495 IndexedDBBackingStore::RecordIdentifier record; |
496 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 496 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
497 1, | 497 1, |
498 i + 1, | 498 i + 1, |
499 key0, | 499 key0, |
500 &value0, | 500 &value0, |
501 &handles, | 501 &handles, |
502 &record).ok()); | 502 &record).ok()); |
503 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 503 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
504 1, | 504 1, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 blob_info0.push_back(blob0); | 574 blob_info0.push_back(blob0); |
575 blob_info1.push_back(blob1); | 575 blob_info1.push_back(blob1); |
576 blob_info2.push_back(blob2); | 576 blob_info2.push_back(blob2); |
577 blob_info3.push_back(blob3); | 577 blob_info3.push_back(blob3); |
578 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); | 578 IndexedDBValue value0 = IndexedDBValue("value0", blob_info0); |
579 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); | 579 IndexedDBValue value1 = IndexedDBValue("value1", blob_info1); |
580 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 580 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
581 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 581 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
582 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 582 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
583 transaction1.Begin(); | 583 transaction1.Begin(); |
584 ScopedVector<webkit_blob::BlobDataHandle> handles; | 584 ScopedVector<storage::BlobDataHandle> handles; |
585 IndexedDBBackingStore::RecordIdentifier record; | 585 IndexedDBBackingStore::RecordIdentifier record; |
586 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 586 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
587 1, | 587 1, |
588 i + 1, | 588 i + 1, |
589 key0, | 589 key0, |
590 &value0, | 590 &value0, |
591 &handles, | 591 &handles, |
592 &record).ok()); | 592 &record).ok()); |
593 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 593 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
594 1, | 594 1, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 633 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
634 EXPECT_EQ(0UL, backing_store_->removals().size()); | 634 EXPECT_EQ(0UL, backing_store_->removals().size()); |
635 } | 635 } |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
639 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 639 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
640 { | 640 { |
641 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 641 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
642 transaction1.Begin(); | 642 transaction1.Begin(); |
643 ScopedVector<webkit_blob::BlobDataHandle> handles; | 643 ScopedVector<storage::BlobDataHandle> handles; |
644 IndexedDBBackingStore::RecordIdentifier record; | 644 IndexedDBBackingStore::RecordIdentifier record; |
645 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 645 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
646 1, | 646 1, |
647 1, | 647 1, |
648 m_key3, | 648 m_key3, |
649 &m_value3, | 649 &m_value3, |
650 &handles, | 650 &handles, |
651 &record).ok()); | 651 &record).ok()); |
652 scoped_refptr<TestCallback> callback(new TestCallback()); | 652 scoped_refptr<TestCallback> callback(new TestCallback()); |
653 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 653 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 const int64 high_index_id = 1ULL << 29; | 712 const int64 high_index_id = 1ULL << 29; |
713 | 713 |
714 const int64 invalid_high_index_id = 1ULL << 37; | 714 const int64 invalid_high_index_id = 1ULL << 37; |
715 | 715 |
716 const IndexedDBKey& index_key = m_key2; | 716 const IndexedDBKey& index_key = m_key2; |
717 std::string index_key_raw; | 717 std::string index_key_raw; |
718 EncodeIDBKey(index_key, &index_key_raw); | 718 EncodeIDBKey(index_key, &index_key_raw); |
719 { | 719 { |
720 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 720 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
721 transaction1.Begin(); | 721 transaction1.Begin(); |
722 ScopedVector<webkit_blob::BlobDataHandle> handles; | 722 ScopedVector<storage::BlobDataHandle> handles; |
723 IndexedDBBackingStore::RecordIdentifier record; | 723 IndexedDBBackingStore::RecordIdentifier record; |
724 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 724 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
725 high_database_id, | 725 high_database_id, |
726 high_object_store_id, | 726 high_object_store_id, |
727 m_key1, | 727 m_key1, |
728 &m_value1, | 728 &m_value1, |
729 &handles, | 729 &handles, |
730 &record); | 730 &record); |
731 EXPECT_TRUE(s.ok()); | 731 EXPECT_TRUE(s.ok()); |
732 | 732 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 const int64 database_id = 1; | 801 const int64 database_id = 1; |
802 const int64 object_store_id = 1; | 802 const int64 object_store_id = 1; |
803 const int64 index_id = kMinimumIndexId; | 803 const int64 index_id = kMinimumIndexId; |
804 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId | 804 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId |
805 | 805 |
806 IndexedDBValue result_value; | 806 IndexedDBValue result_value; |
807 | 807 |
808 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 808 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
809 transaction1.Begin(); | 809 transaction1.Begin(); |
810 | 810 |
811 ScopedVector<webkit_blob::BlobDataHandle> handles; | 811 ScopedVector<storage::BlobDataHandle> handles; |
812 IndexedDBBackingStore::RecordIdentifier record; | 812 IndexedDBBackingStore::RecordIdentifier record; |
813 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 813 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
814 database_id, | 814 database_id, |
815 KeyPrefix::kInvalidId, | 815 KeyPrefix::kInvalidId, |
816 m_key1, | 816 m_key1, |
817 &m_value1, | 817 &m_value1, |
818 &handles, | 818 &handles, |
819 &record); | 819 &record); |
820 EXPECT_FALSE(s.ok()); | 820 EXPECT_FALSE(s.ok()); |
821 s = backing_store_->PutRecord( | 821 s = backing_store_->PutRecord( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 | 995 |
996 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 996 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
997 EXPECT_TRUE(s.ok()); | 997 EXPECT_TRUE(s.ok()); |
998 EXPECT_EQ(names.size(), 1ULL); | 998 EXPECT_EQ(names.size(), 1ULL); |
999 EXPECT_EQ(names[0], db1_name); | 999 EXPECT_EQ(names[0], db1_name); |
1000 } | 1000 } |
1001 | 1001 |
1002 } // namespace | 1002 } // namespace |
1003 | 1003 |
1004 } // namespace content | 1004 } // namespace content |
OLD | NEW |