| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/test_simple_task_runner.h" | 20 #include "base/test/scoped_task_environment.h" |
| 21 #include "base/threading/sequenced_task_runner_handle.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 23 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 22 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 24 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 23 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 25 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 24 #include "content/browser/indexed_db/indexed_db_value.h" | 26 #include "content/browser/indexed_db/indexed_db_value.h" |
| 25 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" | 27 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 28 #include "storage/browser/blob/blob_data_handle.h" | 30 #include "storage/browser/blob/blob_data_handle.h" |
| 29 #include "storage/browser/quota/special_storage_policy.h" | 31 #include "storage/browser/quota/special_storage_policy.h" |
| 30 #include "storage/browser/test/mock_quota_manager_proxy.h" | 32 #include "storage/browser/test/mock_quota_manager_proxy.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 this, origin, data_directory, request_context_getter, &leveldb_factory, | 229 this, origin, data_directory, request_context_getter, &leveldb_factory, |
| 228 context()->TaskRunner(), status); | 230 context()->TaskRunner(), status); |
| 229 } | 231 } |
| 230 | 232 |
| 231 private: | 233 private: |
| 232 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory); | 234 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory); |
| 233 }; | 235 }; |
| 234 | 236 |
| 235 class IndexedDBBackingStoreTest : public testing::Test { | 237 class IndexedDBBackingStoreTest : public testing::Test { |
| 236 public: | 238 public: |
| 237 IndexedDBBackingStoreTest() {} | 239 IndexedDBBackingStoreTest() |
| 240 : scoped_task_environment_( |
| 241 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 242 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 243 base::ThreadTaskRunnerHandle::Get())), |
| 244 special_storage_policy_(new MockSpecialStoragePolicy()), |
| 245 quota_manager_proxy_(new MockQuotaManagerProxy(nullptr, nullptr)) {} |
| 246 |
| 238 void SetUp() override { | 247 void SetUp() override { |
| 239 const Origin origin(GURL("http://localhost:81")); | 248 const Origin origin(GURL("http://localhost:81")); |
| 240 task_runner_ = new base::TestSimpleTaskRunner(); | |
| 241 url_request_context_getter_ = | |
| 242 new net::TestURLRequestContextGetter(task_runner_); | |
| 243 special_storage_policy_ = new MockSpecialStoragePolicy(); | |
| 244 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr); | |
| 245 special_storage_policy_->SetAllUnlimited(true); | 249 special_storage_policy_->SetAllUnlimited(true); |
| 246 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 250 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 247 idb_context_ = new IndexedDBContextImpl( | 251 idb_context_ = new IndexedDBContextImpl(temp_dir_.GetPath(), |
| 248 temp_dir_.GetPath(), special_storage_policy_.get(), | 252 special_storage_policy_.get(), |
| 249 quota_manager_proxy_.get(), task_runner_.get()); | 253 quota_manager_proxy_.get()); |
| 254 // Assign current task runner so that methods on backing store can be |
| 255 // invoked directly from test bodies. |
| 256 idb_context_->SetTaskRunnerForTesting( |
| 257 base::SequencedTaskRunnerHandle::Get()); |
| 250 idb_factory_ = new TestIDBFactory(idb_context_.get()); | 258 idb_factory_ = new TestIDBFactory(idb_context_.get()); |
| 251 backing_store_ = idb_factory_->OpenBackingStoreForTest( | 259 backing_store_ = idb_factory_->OpenBackingStoreForTest( |
| 252 origin, url_request_context_getter_); | 260 origin, url_request_context_getter_); |
| 253 | 261 |
| 254 // useful keys and values during tests | 262 // useful keys and values during tests |
| 255 m_value1 = IndexedDBValue("value1", std::vector<IndexedDBBlobInfo>()); | 263 m_value1 = IndexedDBValue("value1", std::vector<IndexedDBBlobInfo>()); |
| 256 m_value2 = IndexedDBValue("value2", std::vector<IndexedDBBlobInfo>()); | 264 m_value2 = IndexedDBValue("value2", std::vector<IndexedDBBlobInfo>()); |
| 257 | 265 |
| 258 m_blob_info.push_back( | 266 m_blob_info.push_back( |
| 259 IndexedDBBlobInfo("uuid 3", base::UTF8ToUTF16("blob type"), 1)); | 267 IndexedDBBlobInfo("uuid 3", base::UTF8ToUTF16("blob type"), 1)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if (backing_store_->removals().size() != backing_store_->writes().size()) | 350 if (backing_store_->removals().size() != backing_store_->writes().size()) |
| 343 return false; | 351 return false; |
| 344 for (size_t i = 0; i < backing_store_->writes().size(); ++i) { | 352 for (size_t i = 0; i < backing_store_->writes().size(); ++i) { |
| 345 if (backing_store_->writes()[i].key() != backing_store_->removals()[i]) | 353 if (backing_store_->writes()[i].key() != backing_store_->removals()[i]) |
| 346 return false; | 354 return false; |
| 347 } | 355 } |
| 348 return true; | 356 return true; |
| 349 } | 357 } |
| 350 | 358 |
| 351 protected: | 359 protected: |
| 360 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 361 |
| 352 // Must be initialized before url_request_context_getter_ | 362 // Must be initialized before url_request_context_getter_ |
| 353 TestBrowserThreadBundle thread_bundle_; | 363 TestBrowserThreadBundle thread_bundle_; |
| 354 | 364 |
| 355 base::ScopedTempDir temp_dir_; | 365 base::ScopedTempDir temp_dir_; |
| 356 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 366 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 357 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; | 367 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; |
| 358 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 368 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
| 359 scoped_refptr<IndexedDBContextImpl> idb_context_; | 369 scoped_refptr<IndexedDBContextImpl> idb_context_; |
| 360 scoped_refptr<TestIDBFactory> idb_factory_; | 370 scoped_refptr<TestIDBFactory> idb_factory_; |
| 361 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
| 362 | 371 |
| 363 scoped_refptr<TestableIndexedDBBackingStore> backing_store_; | 372 scoped_refptr<TestableIndexedDBBackingStore> backing_store_; |
| 364 | 373 |
| 365 // Sample keys and values that are consistent. | 374 // Sample keys and values that are consistent. |
| 366 IndexedDBKey m_key1; | 375 IndexedDBKey m_key1; |
| 367 IndexedDBKey m_key2; | 376 IndexedDBKey m_key2; |
| 368 IndexedDBKey m_key3; | 377 IndexedDBKey m_key3; |
| 369 IndexedDBValue m_value1; | 378 IndexedDBValue m_value1; |
| 370 IndexedDBValue m_value2; | 379 IndexedDBValue m_value2; |
| 371 IndexedDBValue m_value3; | 380 IndexedDBValue m_value3; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 IndexedDBBackingStore::RecordIdentifier record; | 450 IndexedDBBackingStore::RecordIdentifier record; |
| 442 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 451 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 443 1, | 452 1, |
| 444 1, | 453 1, |
| 445 m_key3, | 454 m_key3, |
| 446 &m_value3, | 455 &m_value3, |
| 447 &handles, | 456 &handles, |
| 448 &record).ok()); | 457 &record).ok()); |
| 449 scoped_refptr<TestCallback> callback(new TestCallback()); | 458 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 450 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 459 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| 451 task_runner_->RunUntilIdle(); | 460 scoped_task_environment_.RunUntilIdle(); |
| 452 EXPECT_TRUE(CheckBlobWrites()); | 461 EXPECT_TRUE(CheckBlobWrites()); |
| 453 EXPECT_TRUE(callback->called); | 462 EXPECT_TRUE(callback->called); |
| 454 EXPECT_TRUE(callback->succeeded); | 463 EXPECT_TRUE(callback->succeeded); |
| 455 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 464 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 456 } | 465 } |
| 457 | 466 |
| 458 { | 467 { |
| 459 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 468 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 460 transaction2.Begin(); | 469 transaction2.Begin(); |
| 461 IndexedDBValue result_value; | 470 IndexedDBValue result_value; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 475 { | 484 { |
| 476 IndexedDBBackingStore::Transaction transaction3(backing_store_.get()); | 485 IndexedDBBackingStore::Transaction transaction3(backing_store_.get()); |
| 477 transaction3.Begin(); | 486 transaction3.Begin(); |
| 478 IndexedDBValue result_value; | 487 IndexedDBValue result_value; |
| 479 EXPECT_TRUE( | 488 EXPECT_TRUE( |
| 480 backing_store_ | 489 backing_store_ |
| 481 ->DeleteRange(&transaction3, 1, 1, IndexedDBKeyRange(m_key3)) | 490 ->DeleteRange(&transaction3, 1, 1, IndexedDBKeyRange(m_key3)) |
| 482 .ok()); | 491 .ok()); |
| 483 scoped_refptr<TestCallback> callback(new TestCallback()); | 492 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 484 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); | 493 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); |
| 485 task_runner_->RunUntilIdle(); | 494 scoped_task_environment_.RunUntilIdle(); |
| 486 EXPECT_TRUE(callback->called); | 495 EXPECT_TRUE(callback->called); |
| 487 EXPECT_TRUE(callback->succeeded); | 496 EXPECT_TRUE(callback->succeeded); |
| 488 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); | 497 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); |
| 489 EXPECT_TRUE(CheckBlobRemovals()); | 498 EXPECT_TRUE(CheckBlobRemovals()); |
| 490 } | 499 } |
| 491 } | 500 } |
| 492 | 501 |
| 493 TEST_F(IndexedDBBackingStoreTest, DeleteRange) { | 502 TEST_F(IndexedDBBackingStoreTest, DeleteRange) { |
| 494 IndexedDBKey key0 = IndexedDBKey(ASCIIToUTF16("key0")); | 503 IndexedDBKey key0 = IndexedDBKey(ASCIIToUTF16("key0")); |
| 495 IndexedDBKey key1 = IndexedDBKey(ASCIIToUTF16("key1")); | 504 IndexedDBKey key1 = IndexedDBKey(ASCIIToUTF16("key1")); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 &record).ok()); | 556 &record).ok()); |
| 548 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 557 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 549 1, | 558 1, |
| 550 i + 1, | 559 i + 1, |
| 551 key3, | 560 key3, |
| 552 &value3, | 561 &value3, |
| 553 &handles, | 562 &handles, |
| 554 &record).ok()); | 563 &record).ok()); |
| 555 scoped_refptr<TestCallback> callback(new TestCallback()); | 564 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 556 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 565 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| 557 task_runner_->RunUntilIdle(); | 566 scoped_task_environment_.RunUntilIdle(); |
| 558 EXPECT_TRUE(callback->called); | 567 EXPECT_TRUE(callback->called); |
| 559 EXPECT_TRUE(callback->succeeded); | 568 EXPECT_TRUE(callback->succeeded); |
| 560 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 569 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 561 } | 570 } |
| 562 | 571 |
| 563 { | 572 { |
| 564 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 573 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 565 transaction2.Begin(); | 574 transaction2.Begin(); |
| 566 IndexedDBValue result_value; | 575 IndexedDBValue result_value; |
| 567 EXPECT_TRUE( | 576 EXPECT_TRUE( |
| 568 backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok()); | 577 backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok()); |
| 569 scoped_refptr<TestCallback> callback(new TestCallback()); | 578 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 570 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | 579 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); |
| 571 task_runner_->RunUntilIdle(); | 580 scoped_task_environment_.RunUntilIdle(); |
| 572 EXPECT_TRUE(callback->called); | 581 EXPECT_TRUE(callback->called); |
| 573 EXPECT_TRUE(callback->succeeded); | 582 EXPECT_TRUE(callback->succeeded); |
| 574 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 583 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 575 ASSERT_EQ(2UL, backing_store_->removals().size()); | 584 ASSERT_EQ(2UL, backing_store_->removals().size()); |
| 576 EXPECT_EQ(backing_store_->writes()[1].key(), | 585 EXPECT_EQ(backing_store_->writes()[1].key(), |
| 577 backing_store_->removals()[0]); | 586 backing_store_->removals()[0]); |
| 578 EXPECT_EQ(backing_store_->writes()[2].key(), | 587 EXPECT_EQ(backing_store_->writes()[2].key(), |
| 579 backing_store_->removals()[1]); | 588 backing_store_->removals()[1]); |
| 580 } | 589 } |
| 581 } | 590 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 &record).ok()); | 646 &record).ok()); |
| 638 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 647 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 639 1, | 648 1, |
| 640 i + 1, | 649 i + 1, |
| 641 key3, | 650 key3, |
| 642 &value3, | 651 &value3, |
| 643 &handles, | 652 &handles, |
| 644 &record).ok()); | 653 &record).ok()); |
| 645 scoped_refptr<TestCallback> callback(new TestCallback()); | 654 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 646 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 655 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| 647 task_runner_->RunUntilIdle(); | 656 scoped_task_environment_.RunUntilIdle(); |
| 648 EXPECT_TRUE(callback->called); | 657 EXPECT_TRUE(callback->called); |
| 649 EXPECT_TRUE(callback->succeeded); | 658 EXPECT_TRUE(callback->succeeded); |
| 650 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 659 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 651 } | 660 } |
| 652 | 661 |
| 653 { | 662 { |
| 654 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 663 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 655 transaction2.Begin(); | 664 transaction2.Begin(); |
| 656 IndexedDBValue result_value; | 665 IndexedDBValue result_value; |
| 657 EXPECT_TRUE( | 666 EXPECT_TRUE( |
| 658 backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok()); | 667 backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok()); |
| 659 scoped_refptr<TestCallback> callback(new TestCallback()); | 668 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 660 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | 669 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); |
| 661 task_runner_->RunUntilIdle(); | 670 scoped_task_environment_.RunUntilIdle(); |
| 662 EXPECT_TRUE(callback->called); | 671 EXPECT_TRUE(callback->called); |
| 663 EXPECT_TRUE(callback->succeeded); | 672 EXPECT_TRUE(callback->succeeded); |
| 664 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 673 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 665 EXPECT_EQ(0UL, backing_store_->removals().size()); | 674 EXPECT_EQ(0UL, backing_store_->removals().size()); |
| 666 } | 675 } |
| 667 } | 676 } |
| 668 } | 677 } |
| 669 | 678 |
| 670 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { | 679 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { |
| 671 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 680 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 672 transaction1.Begin(); | 681 transaction1.Begin(); |
| 673 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles1; | 682 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles1; |
| 674 IndexedDBBackingStore::RecordIdentifier record1; | 683 IndexedDBBackingStore::RecordIdentifier record1; |
| 675 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, | 684 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, |
| 676 &handles1, &record1).ok()); | 685 &handles1, &record1).ok()); |
| 677 scoped_refptr<TestCallback> callback1(new TestCallback()); | 686 scoped_refptr<TestCallback> callback1(new TestCallback()); |
| 678 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); | 687 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); |
| 679 task_runner_->RunUntilIdle(); | 688 scoped_task_environment_.RunUntilIdle(); |
| 680 EXPECT_TRUE(CheckBlobWrites()); | 689 EXPECT_TRUE(CheckBlobWrites()); |
| 681 EXPECT_TRUE(callback1->called); | 690 EXPECT_TRUE(callback1->called); |
| 682 EXPECT_TRUE(callback1->succeeded); | 691 EXPECT_TRUE(callback1->succeeded); |
| 683 EXPECT_EQ(0U, backing_store_->removals().size()); | 692 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 684 | 693 |
| 685 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 694 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 686 transaction2.Begin(); | 695 transaction2.Begin(); |
| 687 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles2; | 696 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles2; |
| 688 IndexedDBBackingStore::RecordIdentifier record2; | 697 IndexedDBBackingStore::RecordIdentifier record2; |
| 689 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, | 698 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, |
| 690 &handles2, &record2).ok()); | 699 &handles2, &record2).ok()); |
| 691 scoped_refptr<TestCallback> callback2(new TestCallback()); | 700 scoped_refptr<TestCallback> callback2(new TestCallback()); |
| 692 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); | 701 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); |
| 693 task_runner_->RunUntilIdle(); | 702 scoped_task_environment_.RunUntilIdle(); |
| 694 EXPECT_TRUE(CheckBlobWrites()); | 703 EXPECT_TRUE(CheckBlobWrites()); |
| 695 EXPECT_TRUE(callback2->called); | 704 EXPECT_TRUE(callback2->called); |
| 696 EXPECT_TRUE(callback2->succeeded); | 705 EXPECT_TRUE(callback2->succeeded); |
| 697 EXPECT_EQ(0U, backing_store_->removals().size()); | 706 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 698 | 707 |
| 699 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 708 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 700 EXPECT_EQ(0U, backing_store_->removals().size()); | 709 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 701 | 710 |
| 702 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 711 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
| 703 EXPECT_EQ(0U, backing_store_->removals().size()); | 712 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 704 } | 713 } |
| 705 | 714 |
| 706 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 715 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
| 707 { | 716 { |
| 708 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 717 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
| 709 transaction1.Begin(); | 718 transaction1.Begin(); |
| 710 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | 719 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 711 IndexedDBBackingStore::RecordIdentifier record; | 720 IndexedDBBackingStore::RecordIdentifier record; |
| 712 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 721 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
| 713 1, | 722 1, |
| 714 1, | 723 1, |
| 715 m_key3, | 724 m_key3, |
| 716 &m_value3, | 725 &m_value3, |
| 717 &handles, | 726 &handles, |
| 718 &record).ok()); | 727 &record).ok()); |
| 719 scoped_refptr<TestCallback> callback(new TestCallback()); | 728 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 720 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | 729 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); |
| 721 task_runner_->RunUntilIdle(); | 730 scoped_task_environment_.RunUntilIdle(); |
| 722 EXPECT_TRUE(CheckBlobWrites()); | 731 EXPECT_TRUE(CheckBlobWrites()); |
| 723 EXPECT_TRUE(callback->called); | 732 EXPECT_TRUE(callback->called); |
| 724 EXPECT_TRUE(callback->succeeded); | 733 EXPECT_TRUE(callback->succeeded); |
| 725 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | 734 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); |
| 726 } | 735 } |
| 727 | 736 |
| 728 IndexedDBValue read_result_value; | 737 IndexedDBValue read_result_value; |
| 729 { | 738 { |
| 730 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | 739 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); |
| 731 transaction2.Begin(); | 740 transaction2.Begin(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 748 | 757 |
| 749 { | 758 { |
| 750 IndexedDBBackingStore::Transaction transaction3(backing_store_.get()); | 759 IndexedDBBackingStore::Transaction transaction3(backing_store_.get()); |
| 751 transaction3.Begin(); | 760 transaction3.Begin(); |
| 752 EXPECT_TRUE( | 761 EXPECT_TRUE( |
| 753 backing_store_ | 762 backing_store_ |
| 754 ->DeleteRange(&transaction3, 1, 1, IndexedDBKeyRange(m_key3)) | 763 ->DeleteRange(&transaction3, 1, 1, IndexedDBKeyRange(m_key3)) |
| 755 .ok()); | 764 .ok()); |
| 756 scoped_refptr<TestCallback> callback(new TestCallback()); | 765 scoped_refptr<TestCallback> callback(new TestCallback()); |
| 757 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); | 766 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); |
| 758 task_runner_->RunUntilIdle(); | 767 scoped_task_environment_.RunUntilIdle(); |
| 759 EXPECT_TRUE(callback->called); | 768 EXPECT_TRUE(callback->called); |
| 760 EXPECT_TRUE(callback->succeeded); | 769 EXPECT_TRUE(callback->succeeded); |
| 761 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); | 770 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); |
| 762 EXPECT_EQ(0U, backing_store_->removals().size()); | 771 EXPECT_EQ(0U, backing_store_->removals().size()); |
| 763 for (size_t i = 0; i < read_result_value.blob_info.size(); ++i) { | 772 for (size_t i = 0; i < read_result_value.blob_info.size(); ++i) { |
| 764 read_result_value.blob_info[i].release_callback().Run( | 773 read_result_value.blob_info[i].release_callback().Run( |
| 765 read_result_value.blob_info[i].file_path()); | 774 read_result_value.blob_info[i].file_path()); |
| 766 } | 775 } |
| 767 task_runner_->RunUntilIdle(); | 776 scoped_task_environment_.RunUntilIdle(); |
| 768 EXPECT_NE(0U, backing_store_->removals().size()); | 777 EXPECT_NE(0U, backing_store_->removals().size()); |
| 769 EXPECT_TRUE(CheckBlobRemovals()); | 778 EXPECT_TRUE(CheckBlobRemovals()); |
| 770 } | 779 } |
| 771 } | 780 } |
| 772 | 781 |
| 773 // Make sure that using very high ( more than 32 bit ) values for database_id | 782 // Make sure that using very high ( more than 32 bit ) values for database_id |
| 774 // and object_store_id still work. | 783 // and object_store_id still work. |
| 775 TEST_F(IndexedDBBackingStoreTest, HighIds) { | 784 TEST_F(IndexedDBBackingStoreTest, HighIds) { |
| 776 const int64_t high_database_id = 1ULL << 35; | 785 const int64_t high_database_id = 1ULL << 35; |
| 777 const int64_t high_object_store_id = 1ULL << 39; | 786 const int64_t high_object_store_id = 1ULL << 39; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 | 1158 |
| 1150 // Dictionary, message key and more. | 1159 // Dictionary, message key and more. |
| 1151 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}")); | 1160 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}")); |
| 1152 EXPECT_TRUE( | 1161 EXPECT_TRUE( |
| 1153 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message)); | 1162 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message)); |
| 1154 EXPECT_FALSE(PathExists(info_path)); | 1163 EXPECT_FALSE(PathExists(info_path)); |
| 1155 EXPECT_EQ("foo", message); | 1164 EXPECT_EQ("foo", message); |
| 1156 } | 1165 } |
| 1157 | 1166 |
| 1158 } // namespace content | 1167 } // namespace content |
| OLD | NEW |