Chromium Code Reviews| Index: components/offline_pages/background/request_coordinator_unittest.cc |
| diff --git a/components/offline_pages/background/request_coordinator_unittest.cc b/components/offline_pages/background/request_coordinator_unittest.cc |
| index 7cacdf3d65acd259a11b99bb914b68c0b5ed6385..68dc5797314299a53e9c25a3660d23c86fa04f06 100644 |
| --- a/components/offline_pages/background/request_coordinator_unittest.cc |
| +++ b/components/offline_pages/background/request_coordinator_unittest.cc |
| @@ -8,8 +8,10 @@ |
| #include <utility> |
| #include "base/bind.h" |
| +#include "base/location.h" |
| #include "base/test/test_simple_task_runner.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| +#include "components/offline_pages/background/offliner.h" |
| #include "components/offline_pages/background/offliner_factory.h" |
| #include "components/offline_pages/background/offliner_policy.h" |
| #include "components/offline_pages/background/request_queue.h" |
| @@ -48,6 +50,30 @@ class SchedulerStub : public Scheduler { |
| bool unschedule_called_; |
| }; |
| +class OfflinerStub : public Offliner { |
| + bool LoadAndSave(const SavePageRequest& request, |
| + const CompletionCallback& callback) override { |
| + // Call the callback, on another thread. |
|
dougarnett
2016/05/13 19:33:00
another thread? I don't think we want that and I d
Pete Williamson
2016/05/13 22:28:24
Done.
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(callback, request, Offliner::SAVED)); |
| + return true; |
| + } |
| + |
| + // Clears the currently processing request, if any. |
| + void Cancel() override {} |
| +}; |
| + |
| +class OfflinerFactoryStub : public OfflinerFactory { |
| + public: |
| + Offliner* GetOffliner(const OfflinerPolicy* policy) override { |
| + offliner_.reset(new OfflinerStub()); |
| + return offliner_.get(); |
| + } |
| + |
| + private: |
| + std::unique_ptr<Offliner> offliner_; |
| +}; |
| + |
| class RequestCoordinatorTest |
| : public testing::Test { |
| public: |
| @@ -95,7 +121,7 @@ RequestCoordinatorTest::~RequestCoordinatorTest() {} |
| void RequestCoordinatorTest::SetUp() { |
| std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy()); |
| - std::unique_ptr<OfflinerFactory> factory; |
| + std::unique_ptr<OfflinerFactory> factory(new OfflinerFactoryStub()); |
| std::unique_ptr<RequestQueueInMemoryStore> |
| store(new RequestQueueInMemoryStore()); |
| std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); |
| @@ -132,10 +158,10 @@ TEST_F(RequestCoordinatorTest, SavePageLater) { |
| base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| base::Unretained(this))); |
| - // Wait for callback to finish. |
| + // Wait for callbacks to finish, both request queue and offliner. |
| PumpLoop(); |
| - // Check the results are as expected. |
| + // Check the request queue is as expected. |
| EXPECT_EQ(1UL, last_requests().size()); |
| EXPECT_EQ(kUrl, last_requests()[0].url()); |
| EXPECT_EQ(kClientId, last_requests()[0].client_id()); |
| @@ -144,6 +170,11 @@ TEST_F(RequestCoordinatorTest, SavePageLater) { |
| SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( |
| coordinator()->GetSchedulerForTesting()); |
| EXPECT_TRUE(scheduler_stub->schedule_called()); |
| + |
| + // Check that the offliner callback got a response. |
| + EXPECT_EQ(Offliner::SAVED, coordinator()->last_offlining_status()); |
| + |
| + // TODO(petewil): Expect that the scheduler got notified. |
| } |
| } // namespace offline_pages |