| 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> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/offline_pages/background/device_conditions.h" |
| 15 #include "components/offline_pages/background/offliner.h" | 16 #include "components/offline_pages/background/offliner.h" |
| 16 #include "components/offline_pages/background/offliner_factory.h" | 17 #include "components/offline_pages/background/offliner_factory.h" |
| 17 #include "components/offline_pages/background/offliner_policy.h" | 18 #include "components/offline_pages/background/offliner_policy.h" |
| 18 #include "components/offline_pages/background/request_queue.h" | 19 #include "components/offline_pages/background/request_queue.h" |
| 19 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 20 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| 20 #include "components/offline_pages/background/save_page_request.h" | 21 #include "components/offline_pages/background/save_page_request.h" |
| 21 #include "components/offline_pages/background/scheduler.h" | 22 #include "components/offline_pages/background/scheduler.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace offline_pages { | 25 namespace offline_pages { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 const SavePageRequest& request) {} | 159 const SavePageRequest& request) {} |
| 159 | 160 |
| 160 void RequestCoordinatorTest::SendOfflinerDoneCallback( | 161 void RequestCoordinatorTest::SendOfflinerDoneCallback( |
| 161 const SavePageRequest& request, Offliner::RequestStatus status) { | 162 const SavePageRequest& request, Offliner::RequestStatus status) { |
| 162 // Using the fact that the test class is a friend, call to the callback | 163 // Using the fact that the test class is a friend, call to the callback |
| 163 coordinator_->OfflinerDoneCallback(request, status); | 164 coordinator_->OfflinerDoneCallback(request, status); |
| 164 } | 165 } |
| 165 | 166 |
| 166 | 167 |
| 167 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { | 168 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { |
| 169 DeviceConditions device_conditions(false, 75, |
| 170 net::NetworkChangeNotifier::CONNECTION_3G); |
| 168 base::Callback<void(bool)> callback = | 171 base::Callback<void(bool)> callback = |
| 169 base::Bind( | 172 base::Bind( |
| 170 &RequestCoordinatorTest::EmptyCallbackFunction, | 173 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 171 base::Unretained(this)); | 174 base::Unretained(this)); |
| 172 EXPECT_TRUE(coordinator()->StartProcessing(callback)); | 175 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); |
| 173 } | 176 } |
| 174 | 177 |
| 175 TEST_F(RequestCoordinatorTest, SavePageLater) { | 178 TEST_F(RequestCoordinatorTest, SavePageLater) { |
| 176 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId)); | 179 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId)); |
| 177 | 180 |
| 178 // Expect that a request got placed on the queue. | 181 // Expect that a request got placed on the queue. |
| 179 coordinator()->queue()->GetRequests( | 182 coordinator()->queue()->GetRequests( |
| 180 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 183 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 181 base::Unretained(this))); | 184 base::Unretained(this))); |
| 182 | 185 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 base::Unretained(this))); | 226 base::Unretained(this))); |
| 224 PumpLoop(); | 227 PumpLoop(); |
| 225 | 228 |
| 226 // We should not find any requests in the queue anymore. | 229 // We should not find any requests in the queue anymore. |
| 227 // RequestPicker should *not* have tried to start an additional job, | 230 // RequestPicker should *not* have tried to start an additional job, |
| 228 // because the request queue is empty now. | 231 // because the request queue is empty now. |
| 229 EXPECT_EQ(0UL, last_requests().size()); | 232 EXPECT_EQ(0UL, last_requests().size()); |
| 230 } | 233 } |
| 231 | 234 |
| 232 } // namespace offline_pages | 235 } // namespace offline_pages |
| OLD | NEW |