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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 DISALLOW_COPY_AND_ASSIGN(TestCallback); | 365 DISALLOW_COPY_AND_ASSIGN(TestCallback); |
366 }; | 366 }; |
367 | 367 |
368 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 368 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
369 { | 369 { |
370 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 370 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
371 transaction1.Begin(); | 371 transaction1.Begin(); |
372 ScopedVector<webkit_blob::BlobDataHandle> handles; | 372 ScopedVector<webkit_blob::BlobDataHandle> handles; |
373 IndexedDBBackingStore::RecordIdentifier record; | 373 IndexedDBBackingStore::RecordIdentifier record; |
374 leveldb::Status s = backing_store_->PutRecord( | 374 leveldb::Status s = backing_store_->PutRecord( |
375 &transaction1, 1, 1, m_key1, m_value1, &handles, &record); | 375 &transaction1, 1, 1, m_key1, &m_value1, &handles, &record); |
376 EXPECT_TRUE(s.ok()); | 376 EXPECT_TRUE(s.ok()); |
377 scoped_refptr<TestCallback> callback(new TestCallback()); | 377 scoped_refptr<TestCallback> callback(new TestCallback()); |
378 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 378 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
379 EXPECT_TRUE(callback->called); | 379 EXPECT_TRUE(callback->called); |
380 EXPECT_TRUE(callback->succeeded); | 380 EXPECT_TRUE(callback->succeeded); |
381 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 381 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
382 } | 382 } |
383 | 383 |
384 { | 384 { |
385 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 385 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
(...skipping 14 matching lines...) Expand all Loading... |
400 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | 400 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { |
401 { | 401 { |
402 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 402 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
403 transaction1.Begin(); | 403 transaction1.Begin(); |
404 ScopedVector<webkit_blob::BlobDataHandle> handles; | 404 ScopedVector<webkit_blob::BlobDataHandle> handles; |
405 IndexedDBBackingStore::RecordIdentifier record; | 405 IndexedDBBackingStore::RecordIdentifier record; |
406 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 406 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
407 1, | 407 1, |
408 1, | 408 1, |
409 m_key3, | 409 m_key3, |
410 m_value3, | 410 &m_value3, |
411 &handles, | 411 &handles, |
412 &record).ok()); | 412 &record).ok()); |
413 scoped_refptr<TestCallback> callback(new TestCallback()); | 413 scoped_refptr<TestCallback> callback(new TestCallback()); |
414 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 414 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
415 task_runner_->RunUntilIdle(); | 415 task_runner_->RunUntilIdle(); |
416 EXPECT_TRUE(CheckBlobWrites()); | 416 EXPECT_TRUE(CheckBlobWrites()); |
417 EXPECT_TRUE(callback->called); | 417 EXPECT_TRUE(callback->called); |
418 EXPECT_TRUE(callback->succeeded); | 418 EXPECT_TRUE(callback->succeeded); |
419 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 419 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
420 } | 420 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 485 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
486 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 486 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
487 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 487 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
488 transaction1.Begin(); | 488 transaction1.Begin(); |
489 ScopedVector<webkit_blob::BlobDataHandle> handles; | 489 ScopedVector<webkit_blob::BlobDataHandle> handles; |
490 IndexedDBBackingStore::RecordIdentifier record; | 490 IndexedDBBackingStore::RecordIdentifier record; |
491 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 491 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
492 1, | 492 1, |
493 i + 1, | 493 i + 1, |
494 key0, | 494 key0, |
495 value0, | 495 &value0, |
496 &handles, | 496 &handles, |
497 &record).ok()); | 497 &record).ok()); |
498 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 498 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
499 1, | 499 1, |
500 i + 1, | 500 i + 1, |
501 key1, | 501 key1, |
502 value1, | 502 &value1, |
503 &handles, | 503 &handles, |
504 &record).ok()); | 504 &record).ok()); |
505 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 505 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
506 1, | 506 1, |
507 i + 1, | 507 i + 1, |
508 key2, | 508 key2, |
509 value2, | 509 &value2, |
510 &handles, | 510 &handles, |
511 &record).ok()); | 511 &record).ok()); |
512 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 512 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
513 1, | 513 1, |
514 i + 1, | 514 i + 1, |
515 key3, | 515 key3, |
516 value3, | 516 &value3, |
517 &handles, | 517 &handles, |
518 &record).ok()); | 518 &record).ok()); |
519 scoped_refptr<TestCallback> callback(new TestCallback()); | 519 scoped_refptr<TestCallback> callback(new TestCallback()); |
520 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 520 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
521 task_runner_->RunUntilIdle(); | 521 task_runner_->RunUntilIdle(); |
522 EXPECT_TRUE(callback->called); | 522 EXPECT_TRUE(callback->called); |
523 EXPECT_TRUE(callback->succeeded); | 523 EXPECT_TRUE(callback->succeeded); |
524 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 524 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
525 } | 525 } |
526 | 526 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); | 575 IndexedDBValue value2 = IndexedDBValue("value2", blob_info2); |
576 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); | 576 IndexedDBValue value3 = IndexedDBValue("value3", blob_info3); |
577 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 577 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
578 transaction1.Begin(); | 578 transaction1.Begin(); |
579 ScopedVector<webkit_blob::BlobDataHandle> handles; | 579 ScopedVector<webkit_blob::BlobDataHandle> handles; |
580 IndexedDBBackingStore::RecordIdentifier record; | 580 IndexedDBBackingStore::RecordIdentifier record; |
581 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 581 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
582 1, | 582 1, |
583 i + 1, | 583 i + 1, |
584 key0, | 584 key0, |
585 value0, | 585 &value0, |
586 &handles, | 586 &handles, |
587 &record).ok()); | 587 &record).ok()); |
588 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 588 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
589 1, | 589 1, |
590 i + 1, | 590 i + 1, |
591 key1, | 591 key1, |
592 value1, | 592 &value1, |
593 &handles, | 593 &handles, |
594 &record).ok()); | 594 &record).ok()); |
595 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 595 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
596 1, | 596 1, |
597 i + 1, | 597 i + 1, |
598 key2, | 598 key2, |
599 value2, | 599 &value2, |
600 &handles, | 600 &handles, |
601 &record).ok()); | 601 &record).ok()); |
602 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 602 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
603 1, | 603 1, |
604 i + 1, | 604 i + 1, |
605 key3, | 605 key3, |
606 value3, | 606 &value3, |
607 &handles, | 607 &handles, |
608 &record).ok()); | 608 &record).ok()); |
609 scoped_refptr<TestCallback> callback(new TestCallback()); | 609 scoped_refptr<TestCallback> callback(new TestCallback()); |
610 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 610 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
611 task_runner_->RunUntilIdle(); | 611 task_runner_->RunUntilIdle(); |
612 EXPECT_TRUE(callback->called); | 612 EXPECT_TRUE(callback->called); |
613 EXPECT_TRUE(callback->succeeded); | 613 EXPECT_TRUE(callback->succeeded); |
614 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 614 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
615 } | 615 } |
616 | 616 |
(...skipping 17 matching lines...) Expand all Loading... |
634 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 634 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
635 { | 635 { |
636 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 636 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
637 transaction1.Begin(); | 637 transaction1.Begin(); |
638 ScopedVector<webkit_blob::BlobDataHandle> handles; | 638 ScopedVector<webkit_blob::BlobDataHandle> handles; |
639 IndexedDBBackingStore::RecordIdentifier record; | 639 IndexedDBBackingStore::RecordIdentifier record; |
640 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 640 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
641 1, | 641 1, |
642 1, | 642 1, |
643 m_key3, | 643 m_key3, |
644 m_value3, | 644 &m_value3, |
645 &handles, | 645 &handles, |
646 &record).ok()); | 646 &record).ok()); |
647 scoped_refptr<TestCallback> callback(new TestCallback()); | 647 scoped_refptr<TestCallback> callback(new TestCallback()); |
648 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 648 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
649 task_runner_->RunUntilIdle(); | 649 task_runner_->RunUntilIdle(); |
650 EXPECT_TRUE(CheckBlobWrites()); | 650 EXPECT_TRUE(CheckBlobWrites()); |
651 EXPECT_TRUE(callback->called); | 651 EXPECT_TRUE(callback->called); |
652 EXPECT_TRUE(callback->succeeded); | 652 EXPECT_TRUE(callback->succeeded); |
653 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 653 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
654 } | 654 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 EncodeIDBKey(index_key, &index_key_raw); | 713 EncodeIDBKey(index_key, &index_key_raw); |
714 { | 714 { |
715 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 715 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
716 transaction1.Begin(); | 716 transaction1.Begin(); |
717 ScopedVector<webkit_blob::BlobDataHandle> handles; | 717 ScopedVector<webkit_blob::BlobDataHandle> handles; |
718 IndexedDBBackingStore::RecordIdentifier record; | 718 IndexedDBBackingStore::RecordIdentifier record; |
719 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 719 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
720 high_database_id, | 720 high_database_id, |
721 high_object_store_id, | 721 high_object_store_id, |
722 m_key1, | 722 m_key1, |
723 m_value1, | 723 &m_value1, |
724 &handles, | 724 &handles, |
725 &record); | 725 &record); |
726 EXPECT_TRUE(s.ok()); | 726 EXPECT_TRUE(s.ok()); |
727 | 727 |
728 s = backing_store_->PutIndexDataForRecord(&transaction1, | 728 s = backing_store_->PutIndexDataForRecord(&transaction1, |
729 high_database_id, | 729 high_database_id, |
730 high_object_store_id, | 730 high_object_store_id, |
731 invalid_high_index_id, | 731 invalid_high_index_id, |
732 index_key, | 732 index_key, |
733 record); | 733 record); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 802 |
803 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 803 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
804 transaction1.Begin(); | 804 transaction1.Begin(); |
805 | 805 |
806 ScopedVector<webkit_blob::BlobDataHandle> handles; | 806 ScopedVector<webkit_blob::BlobDataHandle> handles; |
807 IndexedDBBackingStore::RecordIdentifier record; | 807 IndexedDBBackingStore::RecordIdentifier record; |
808 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 808 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
809 database_id, | 809 database_id, |
810 KeyPrefix::kInvalidId, | 810 KeyPrefix::kInvalidId, |
811 m_key1, | 811 m_key1, |
812 m_value1, | 812 &m_value1, |
813 &handles, | 813 &handles, |
814 &record); | 814 &record); |
815 EXPECT_FALSE(s.ok()); | 815 EXPECT_FALSE(s.ok()); |
816 s = backing_store_->PutRecord( | 816 s = backing_store_->PutRecord( |
817 &transaction1, database_id, 0, m_key1, m_value1, &handles, &record); | 817 &transaction1, database_id, 0, m_key1, &m_value1, &handles, &record); |
818 EXPECT_FALSE(s.ok()); | 818 EXPECT_FALSE(s.ok()); |
819 s = backing_store_->PutRecord(&transaction1, | 819 s = backing_store_->PutRecord(&transaction1, |
820 KeyPrefix::kInvalidId, | 820 KeyPrefix::kInvalidId, |
821 object_store_id, | 821 object_store_id, |
822 m_key1, | 822 m_key1, |
823 m_value1, | 823 &m_value1, |
824 &handles, | 824 &handles, |
825 &record); | 825 &record); |
826 EXPECT_FALSE(s.ok()); | 826 EXPECT_FALSE(s.ok()); |
827 s = backing_store_->PutRecord( | 827 s = backing_store_->PutRecord( |
828 &transaction1, 0, object_store_id, m_key1, m_value1, &handles, &record); | 828 &transaction1, 0, object_store_id, m_key1, &m_value1, &handles, &record); |
829 EXPECT_FALSE(s.ok()); | 829 EXPECT_FALSE(s.ok()); |
830 | 830 |
831 s = backing_store_->GetRecord( | 831 s = backing_store_->GetRecord( |
832 &transaction1, database_id, KeyPrefix::kInvalidId, m_key1, &result_value); | 832 &transaction1, database_id, KeyPrefix::kInvalidId, m_key1, &result_value); |
833 EXPECT_FALSE(s.ok()); | 833 EXPECT_FALSE(s.ok()); |
834 s = backing_store_->GetRecord( | 834 s = backing_store_->GetRecord( |
835 &transaction1, database_id, 0, m_key1, &result_value); | 835 &transaction1, database_id, 0, m_key1, &result_value); |
836 EXPECT_FALSE(s.ok()); | 836 EXPECT_FALSE(s.ok()); |
837 s = backing_store_->GetRecord(&transaction1, | 837 s = backing_store_->GetRecord(&transaction1, |
838 KeyPrefix::kInvalidId, | 838 KeyPrefix::kInvalidId, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 EXPECT_EQ(index_name, index.name); | 961 EXPECT_EQ(index_name, index.name); |
962 EXPECT_EQ(index_key_path, index.key_path); | 962 EXPECT_EQ(index_key_path, index.key_path); |
963 EXPECT_EQ(unique, index.unique); | 963 EXPECT_EQ(unique, index.unique); |
964 EXPECT_EQ(multi_entry, index.multi_entry); | 964 EXPECT_EQ(multi_entry, index.multi_entry); |
965 } | 965 } |
966 } | 966 } |
967 | 967 |
968 } // namespace | 968 } // namespace |
969 | 969 |
970 } // namespace content | 970 } // namespace content |
OLD | NEW |