Chromium Code Reviews| 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/logging.h" | |
| 13 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/offline_pages/background/device_conditions.h" | 16 #include "components/offline_pages/background/device_conditions.h" |
| 16 #include "components/offline_pages/background/offliner.h" | 17 #include "components/offline_pages/background/offliner.h" |
| 17 #include "components/offline_pages/background/offliner_factory.h" | 18 #include "components/offline_pages/background/offliner_factory.h" |
| 18 #include "components/offline_pages/background/offliner_policy.h" | 19 #include "components/offline_pages/background/offliner_policy.h" |
| 19 #include "components/offline_pages/background/request_queue.h" | 20 #include "components/offline_pages/background/request_queue.h" |
| 20 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 21 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| 21 #include "components/offline_pages/background/save_page_request.h" | 22 #include "components/offline_pages/background/save_page_request.h" |
| 22 #include "components/offline_pages/background/scheduler.h" | 23 #include "components/offline_pages/background/scheduler.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 ~RequestCoordinatorTest() override; | 86 ~RequestCoordinatorTest() override; |
| 86 | 87 |
| 87 void SetUp() override; | 88 void SetUp() override; |
| 88 | 89 |
| 89 void PumpLoop(); | 90 void PumpLoop(); |
| 90 | 91 |
| 91 RequestCoordinator* coordinator() { | 92 RequestCoordinator* coordinator() { |
| 92 return coordinator_.get(); | 93 return coordinator_.get(); |
| 93 } | 94 } |
| 94 | 95 |
| 96 bool request_in_progress() { | |
| 97 return coordinator_->request_in_progress_; | |
|
dougarnett
2016/06/20 18:30:08
Might consider public method on Coordinator instea
Pete Williamson
2016/06/21 17:55:25
New public method is_busy() added. (Following acce
| |
| 98 } | |
| 99 | |
| 100 void SendRequestToOffliner(SavePageRequest& request) { | |
| 101 coordinator_->SendRequestToOffliner(request); | |
| 102 } | |
| 103 | |
| 95 // Empty callback function | 104 // Empty callback function |
| 96 void EmptyCallbackFunction(bool result) { | 105 void EmptyCallbackFunction(bool result) { |
| 97 } | 106 } |
| 98 | 107 |
| 99 // Callback for Add requests | 108 // Callback for Add requests |
| 100 void AddRequestDone(RequestQueue::AddRequestResult result, | 109 void AddRequestDone(RequestQueue::AddRequestResult result, |
| 101 const SavePageRequest& request); | 110 const SavePageRequest& request); |
| 102 | 111 |
| 103 // Callback for getting requests. | 112 // Callback for getting requests. |
| 104 void GetRequestsDone(RequestQueue::GetRequestsResult result, | 113 void GetRequestsDone(RequestQueue::GetRequestsResult result, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { | 177 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { |
| 169 DeviceConditions device_conditions(false, 75, | 178 DeviceConditions device_conditions(false, 75, |
| 170 net::NetworkChangeNotifier::CONNECTION_3G); | 179 net::NetworkChangeNotifier::CONNECTION_3G); |
| 171 base::Callback<void(bool)> callback = | 180 base::Callback<void(bool)> callback = |
| 172 base::Bind( | 181 base::Bind( |
| 173 &RequestCoordinatorTest::EmptyCallbackFunction, | 182 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 174 base::Unretained(this)); | 183 base::Unretained(this)); |
| 175 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 184 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); |
| 176 } | 185 } |
| 177 | 186 |
| 187 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { | |
| 188 // Build a request. | |
| 189 offline_pages::SavePageRequest request( | |
| 190 kRequestId, kUrl, kClientId, base::Time::Now()); | |
| 191 // Sending the request to the offliner should make it busy. | |
| 192 SendRequestToOffliner(request); | |
|
dougarnett
2016/06/20 18:30:08
Why not call StartProcessing (with some PumpLoops
Pete Williamson
2016/06/21 17:55:25
I tried that, but the process goes all the way thr
dougarnett
2016/06/22 17:25:47
Ah, so that is actually a good case that I wasn't
Pete Williamson
2016/06/22 22:32:26
If I understand your suggestion correctly, then be
dougarnett
2016/06/22 23:18:36
I see your point with OfflinerStub now - I missed
| |
| 193 EXPECT_TRUE(request_in_progress()); | |
| 194 // Now trying to start processing on another request should return false. | |
| 195 DeviceConditions device_conditions(false, 75, | |
| 196 net::NetworkChangeNotifier::CONNECTION_3G); | |
| 197 base::Callback<void(bool)> callback = | |
| 198 base::Bind( | |
| 199 &RequestCoordinatorTest::EmptyCallbackFunction, | |
| 200 base::Unretained(this)); | |
| 201 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); | |
| 202 } | |
| 203 | |
| 178 TEST_F(RequestCoordinatorTest, SavePageLater) { | 204 TEST_F(RequestCoordinatorTest, SavePageLater) { |
| 179 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId)); | 205 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId)); |
| 180 | 206 |
| 181 // Expect that a request got placed on the queue. | 207 // Expect that a request got placed on the queue. |
| 182 coordinator()->queue()->GetRequests( | 208 coordinator()->queue()->GetRequests( |
| 183 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 209 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 184 base::Unretained(this))); | 210 base::Unretained(this))); |
| 185 | 211 |
| 186 // Wait for callbacks to finish, both request queue and offliner. | 212 // Wait for callbacks to finish, both request queue and offliner. |
| 187 PumpLoop(); | 213 PumpLoop(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 284 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 259 base::Unretained(this))); | 285 base::Unretained(this))); |
| 260 PumpLoop(); | 286 PumpLoop(); |
| 261 | 287 |
| 262 // Still one request in the queue. | 288 // Still one request in the queue. |
| 263 EXPECT_EQ(1UL, last_requests().size()); | 289 EXPECT_EQ(1UL, last_requests().size()); |
| 264 // TODO(dougarnett): Verify retry count gets incremented. | 290 // TODO(dougarnett): Verify retry count gets incremented. |
| 265 } | 291 } |
| 266 | 292 |
| 267 } // namespace offline_pages | 293 } // namespace offline_pages |
| OLD | NEW |