| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | |
| 10 | 9 |
| 11 #include "base/bind.h" | 10 #include "base/bind.h" |
| 12 #include "base/location.h" | 11 #include "base/location.h" |
| 13 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/offline_pages/background/offliner.h" | 14 #include "components/offline_pages/background/offliner.h" |
| 16 #include "components/offline_pages/background/offliner_factory.h" | 15 #include "components/offline_pages/background/offliner_factory.h" |
| 17 #include "components/offline_pages/background/offliner_policy.h" | 16 #include "components/offline_pages/background/offliner_policy.h" |
| 18 #include "components/offline_pages/background/request_queue.h" | 17 #include "components/offline_pages/background/request_queue.h" |
| 19 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 18 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 49 private: | 48 private: |
| 50 bool schedule_called_; | 49 bool schedule_called_; |
| 51 bool unschedule_called_; | 50 bool unschedule_called_; |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 class OfflinerStub : public Offliner { | 53 class OfflinerStub : public Offliner { |
| 55 bool LoadAndSave(const SavePageRequest& request, | 54 bool LoadAndSave(const SavePageRequest& request, |
| 56 const CompletionCallback& callback) override { | 55 const CompletionCallback& callback) override { |
| 57 // Post the callback on the run loop. | 56 // Post the callback on the run loop. |
| 58 base::ThreadTaskRunnerHandle::Get()->PostTask( | 57 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, | 58 FROM_HERE, base::Bind(callback, request, Offliner::SAVED)); |
| 60 base::Bind(callback, request, Offliner::RequestStatus::SAVED)); | |
| 61 return true; | 59 return true; |
| 62 } | 60 } |
| 63 | 61 |
| 64 // Clears the currently processing request, if any. | 62 // Clears the currently processing request, if any. |
| 65 void Cancel() override {} | 63 void Cancel() override {} |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 class OfflinerFactoryStub : public OfflinerFactory { | 66 class OfflinerFactoryStub : public OfflinerFactory { |
| 69 public: | 67 public: |
| 70 Offliner* GetOffliner(const OfflinerPolicy* policy) override { | 68 Offliner* GetOffliner(const OfflinerPolicy* policy) override { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 EXPECT_EQ(1UL, last_requests().size()); | 165 EXPECT_EQ(1UL, last_requests().size()); |
| 168 EXPECT_EQ(kUrl, last_requests()[0].url()); | 166 EXPECT_EQ(kUrl, last_requests()[0].url()); |
| 169 EXPECT_EQ(kClientId, last_requests()[0].client_id()); | 167 EXPECT_EQ(kClientId, last_requests()[0].client_id()); |
| 170 | 168 |
| 171 // Expect that the scheduler got notified. | 169 // Expect that the scheduler got notified. |
| 172 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( | 170 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( |
| 173 coordinator()->GetSchedulerForTesting()); | 171 coordinator()->GetSchedulerForTesting()); |
| 174 EXPECT_TRUE(scheduler_stub->schedule_called()); | 172 EXPECT_TRUE(scheduler_stub->schedule_called()); |
| 175 | 173 |
| 176 // Check that the offliner callback got a response. | 174 // Check that the offliner callback got a response. |
| 177 EXPECT_EQ(Offliner::RequestStatus::SAVED, | 175 EXPECT_EQ(Offliner::SAVED, coordinator()->last_offlining_status()); |
| 178 coordinator()->last_offlining_status()); | |
| 179 | 176 |
| 180 // TODO(petewil): Expect that the scheduler got notified. | 177 // TODO(petewil): Expect that the scheduler got notified. |
| 181 } | 178 } |
| 182 | 179 |
| 183 } // namespace offline_pages | 180 } // namespace offline_pages |
| OLD | NEW |