Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2071403003: Revises RequestCoordinator to not try to schedule another request when previous one fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_EQ(1UL, last_requests().size()); 190 EXPECT_EQ(1UL, last_requests().size());
191 EXPECT_EQ(kUrl, last_requests()[0].url()); 191 EXPECT_EQ(kUrl, last_requests()[0].url());
192 EXPECT_EQ(kClientId, last_requests()[0].client_id()); 192 EXPECT_EQ(kClientId, last_requests()[0].client_id());
193 193
194 // Expect that the scheduler got notified. 194 // Expect that the scheduler got notified.
195 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( 195 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
196 coordinator()->scheduler()); 196 coordinator()->scheduler());
197 EXPECT_TRUE(scheduler_stub->schedule_called()); 197 EXPECT_TRUE(scheduler_stub->schedule_called());
198 } 198 }
199 199
200 TEST_F(RequestCoordinatorTest, OfflinerDone) { 200 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
201 // Add a request to the queue, wait for callbacks to finish. 201 // Add a request to the queue, wait for callbacks to finish.
202 offline_pages::SavePageRequest request( 202 offline_pages::SavePageRequest request(
203 kRequestId, kUrl, kClientId, base::Time::Now()); 203 kRequestId, kUrl, kClientId, base::Time::Now());
204 coordinator()->queue()->AddRequest( 204 coordinator()->queue()->AddRequest(
205 request, 205 request,
206 base::Bind(&RequestCoordinatorTest::AddRequestDone, 206 base::Bind(&RequestCoordinatorTest::AddRequestDone,
207 base::Unretained(this))); 207 base::Unretained(this)));
208 PumpLoop(); 208 PumpLoop();
209 209
210 // We need to give a callback to the request. 210 // We need to give a callback to the request.
(...skipping 13 matching lines...) Expand all
224 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 224 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
225 base::Unretained(this))); 225 base::Unretained(this)));
226 PumpLoop(); 226 PumpLoop();
227 227
228 // We should not find any requests in the queue anymore. 228 // We should not find any requests in the queue anymore.
229 // RequestPicker should *not* have tried to start an additional job, 229 // RequestPicker should *not* have tried to start an additional job,
230 // because the request queue is empty now. 230 // because the request queue is empty now.
231 EXPECT_EQ(0UL, last_requests().size()); 231 EXPECT_EQ(0UL, last_requests().size());
232 } 232 }
233 233
234 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
235 // Add a request to the queue, wait for callbacks to finish.
236 offline_pages::SavePageRequest request(
237 kRequestId, kUrl, kClientId, base::Time::Now());
238 coordinator()->queue()->AddRequest(
239 request,
240 base::Bind(&RequestCoordinatorTest::AddRequestDone,
241 base::Unretained(this)));
242 PumpLoop();
243
244 // We need to give a callback to the request.
245 base::Callback<void(bool)> callback =
246 base::Bind(
247 &RequestCoordinatorTest::EmptyCallbackFunction,
248 base::Unretained(this));
249 coordinator()->SetProcessingCallbackForTest(callback);
250
251 // Call the OfflinerDoneCallback to simulate the request failed, wait
252 // for callbacks.
253 SendOfflinerDoneCallback(request, Offliner::RequestStatus::FAILED);
254 PumpLoop();
255
256 // Verify the request is not removed from the queue, and wait for callbacks.
257 coordinator()->queue()->GetRequests(
258 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
259 base::Unretained(this)));
260 PumpLoop();
261
262 // Still one request in the queue.
263 EXPECT_EQ(1UL, last_requests().size());
264 // TODO(dougarnett): Verify retry count gets incremented.
265 }
266
234 } // namespace offline_pages 267 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698