| Index: content/browser/indexed_db/indexed_db_backing_store_unittest.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_backing_store_unittest.cc b/content/browser/indexed_db/indexed_db_backing_store_unittest.cc
|
| index f6126705cc1c4272420f9f008e1d46514e082843..7fae530705e91a74c7193520f434bcd8df53d427 100644
|
| --- a/content/browser/indexed_db/indexed_db_backing_store_unittest.cc
|
| +++ b/content/browser/indexed_db/indexed_db_backing_store_unittest.cc
|
| @@ -17,7 +17,9 @@
|
| #include "base/sequenced_task_runner.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "base/test/test_simple_task_runner.h"
|
| +#include "base/test/scoped_task_environment.h"
|
| +#include "base/threading/sequenced_task_runner_handle.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "content/browser/indexed_db/indexed_db_context_impl.h"
|
| #include "content/browser/indexed_db/indexed_db_factory_impl.h"
|
| #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
|
| @@ -234,19 +236,25 @@ class TestIDBFactory : public IndexedDBFactoryImpl {
|
|
|
| class IndexedDBBackingStoreTest : public testing::Test {
|
| public:
|
| - IndexedDBBackingStoreTest() {}
|
| + IndexedDBBackingStoreTest()
|
| + : scoped_task_environment_(
|
| + base::test::ScopedTaskEnvironment::MainThreadType::UI),
|
| + url_request_context_getter_(new net::TestURLRequestContextGetter(
|
| + base::ThreadTaskRunnerHandle::Get())),
|
| + special_storage_policy_(new MockSpecialStoragePolicy()),
|
| + quota_manager_proxy_(new MockQuotaManagerProxy(nullptr, nullptr)) {}
|
| +
|
| void SetUp() override {
|
| const Origin origin(GURL("http://localhost:81"));
|
| - task_runner_ = new base::TestSimpleTaskRunner();
|
| - url_request_context_getter_ =
|
| - new net::TestURLRequestContextGetter(task_runner_);
|
| - special_storage_policy_ = new MockSpecialStoragePolicy();
|
| - quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr);
|
| special_storage_policy_->SetAllUnlimited(true);
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| - idb_context_ = new IndexedDBContextImpl(
|
| - temp_dir_.GetPath(), special_storage_policy_.get(),
|
| - quota_manager_proxy_.get(), task_runner_.get());
|
| + idb_context_ = new IndexedDBContextImpl(temp_dir_.GetPath(),
|
| + special_storage_policy_.get(),
|
| + quota_manager_proxy_.get());
|
| + // Assign current task runner so that methods on backing store can be
|
| + // invoked directly from test bodies.
|
| + idb_context_->SetTaskRunnerForTesting(
|
| + base::SequencedTaskRunnerHandle::Get());
|
| idb_factory_ = new TestIDBFactory(idb_context_.get());
|
| backing_store_ = idb_factory_->OpenBackingStoreForTest(
|
| origin, url_request_context_getter_);
|
| @@ -349,16 +357,17 @@ class IndexedDBBackingStoreTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| + base::test::ScopedTaskEnvironment scoped_task_environment_;
|
| +
|
| // Must be initialized before url_request_context_getter_
|
| TestBrowserThreadBundle thread_bundle_;
|
|
|
| base::ScopedTempDir temp_dir_;
|
| - scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
|
| + scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
|
| scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_;
|
| scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
|
| scoped_refptr<IndexedDBContextImpl> idb_context_;
|
| scoped_refptr<TestIDBFactory> idb_factory_;
|
| - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
|
|
|
| scoped_refptr<TestableIndexedDBBackingStore> backing_store_;
|
|
|
| @@ -448,7 +457,7 @@ TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) {
|
| &record).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(CheckBlobWrites());
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| @@ -482,7 +491,7 @@ TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) {
|
| .ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction3.CommitPhaseTwo().ok());
|
| @@ -554,7 +563,7 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRange) {
|
| &record).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction1.CommitPhaseTwo().ok());
|
| @@ -568,7 +577,7 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRange) {
|
| backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction2.CommitPhaseTwo().ok());
|
| @@ -644,7 +653,7 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRangeEmptyRange) {
|
| &record).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction1.CommitPhaseTwo().ok());
|
| @@ -658,7 +667,7 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRangeEmptyRange) {
|
| backing_store_->DeleteRange(&transaction2, 1, i + 1, ranges[i]).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction2.CommitPhaseTwo().ok());
|
| @@ -676,7 +685,7 @@ TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) {
|
| &handles1, &record1).ok());
|
| scoped_refptr<TestCallback> callback1(new TestCallback());
|
| EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(CheckBlobWrites());
|
| EXPECT_TRUE(callback1->called);
|
| EXPECT_TRUE(callback1->succeeded);
|
| @@ -690,7 +699,7 @@ TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) {
|
| &handles2, &record2).ok());
|
| scoped_refptr<TestCallback> callback2(new TestCallback());
|
| EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(CheckBlobWrites());
|
| EXPECT_TRUE(callback2->called);
|
| EXPECT_TRUE(callback2->succeeded);
|
| @@ -718,7 +727,7 @@ TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) {
|
| &record).ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(CheckBlobWrites());
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| @@ -755,7 +764,7 @@ TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) {
|
| .ok());
|
| scoped_refptr<TestCallback> callback(new TestCallback());
|
| EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok());
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_TRUE(callback->called);
|
| EXPECT_TRUE(callback->succeeded);
|
| EXPECT_TRUE(transaction3.CommitPhaseTwo().ok());
|
| @@ -764,7 +773,7 @@ TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) {
|
| read_result_value.blob_info[i].release_callback().Run(
|
| read_result_value.blob_info[i].file_path());
|
| }
|
| - task_runner_->RunUntilIdle();
|
| + scoped_task_environment_.RunUntilIdle();
|
| EXPECT_NE(0U, backing_store_->removals().size());
|
| EXPECT_TRUE(CheckBlobRemovals());
|
| }
|
|
|