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

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

Issue 2196293002: Skips processing more SavePageLater requests in current processing window when one completes unsucc… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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 13 matching lines...) Expand all
24 #include "components/offline_pages/background/save_page_request.h" 24 #include "components/offline_pages/background/save_page_request.h"
25 #include "components/offline_pages/background/scheduler.h" 25 #include "components/offline_pages/background/scheduler.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace offline_pages { 28 namespace offline_pages {
29 29
30 namespace { 30 namespace {
31 // put test constants here 31 // put test constants here
32 const GURL kUrl("http://universe.com/everything"); 32 const GURL kUrl("http://universe.com/everything");
33 const ClientId kClientId("bookmark", "42"); 33 const ClientId kClientId("bookmark", "42");
34 const int kRequestId2(2);
35 const GURL kUrl2("http://universe.com/toinfinityandbeyond");
36 const ClientId kClientId2("bookmark", "43");
34 const int kRequestId(1); 37 const int kRequestId(1);
35 const long kTestTimeoutSeconds = 1; 38 const long kTestTimeoutSeconds = 1;
36 const long kTestTimeBudgetSeconds = 200; 39 const long kTestTimeBudgetSeconds = 200;
37 const int kBatteryPercentageHigh = 75; 40 const int kBatteryPercentageHigh = 75;
38 const bool kPowerRequired = true; 41 const bool kPowerRequired = true;
39 const bool kUserRequested = true; 42 const bool kUserRequested = true;
40 const int kAttemptCount = 1; 43 const int kAttemptCount = 1;
41 } // namespace 44 } // namespace
42 45
43 class SchedulerStub : public Scheduler { 46 class SchedulerStub : public Scheduler {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 354 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
352 // Add a request to the queue, wait for callbacks to finish. 355 // Add a request to the queue, wait for callbacks to finish.
353 offline_pages::SavePageRequest request( 356 offline_pages::SavePageRequest request(
354 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 357 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
355 coordinator()->queue()->AddRequest( 358 coordinator()->queue()->AddRequest(
356 request, 359 request,
357 base::Bind(&RequestCoordinatorTest::AddRequestDone, 360 base::Bind(&RequestCoordinatorTest::AddRequestDone,
358 base::Unretained(this))); 361 base::Unretained(this)));
359 PumpLoop(); 362 PumpLoop();
360 363
364 // Add second request to the queue to check handling when first fails.
365 offline_pages::SavePageRequest request2(
366 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested);
367 coordinator()->queue()->AddRequest(
368 request2,
369 base::Bind(&RequestCoordinatorTest::AddRequestDone,
370 base::Unretained(this)));
371 PumpLoop();
372
361 // We need to give a callback to the request. 373 // We need to give a callback to the request.
362 base::Callback<void(bool)> callback = 374 base::Callback<void(bool)> callback =
363 base::Bind( 375 base::Bind(
364 &RequestCoordinatorTest::EmptyCallbackFunction, 376 &RequestCoordinatorTest::EmptyCallbackFunction,
365 base::Unretained(this)); 377 base::Unretained(this));
366 coordinator()->SetProcessingCallbackForTest(callback); 378 coordinator()->SetProcessingCallbackForTest(callback);
367 379
368 // Set up device conditions for the test. 380 // Set up device conditions for the test.
369 DeviceConditions device_conditions( 381 DeviceConditions device_conditions(
370 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 382 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
371 SetDeviceConditionsForTest(device_conditions); 383 SetDeviceConditionsForTest(device_conditions);
372 384
373 // Call the OfflinerDoneCallback to simulate the request failed, wait 385 // Call the OfflinerDoneCallback to simulate the request failed, wait
374 // for callbacks. 386 // for callbacks.
375 EnableOfflinerCallback(true); 387 EnableOfflinerCallback(true);
376 SendOfflinerDoneCallback(request, 388 SendOfflinerDoneCallback(request,
377 Offliner::RequestStatus::PRERENDERING_FAILED); 389 Offliner::RequestStatus::PRERENDERING_FAILED);
378 // There will be one request left in the queue after the prerender fails, stop
379 // processing now so that it will remain in the queue for us to check. This
380 // won't affect the offliner done callback other than preventing
381 // TryNextRequest from doing anything.
382 coordinator()->StopProcessing();
383
384 PumpLoop(); 390 PumpLoop();
385 391
386 // Verify the request is not removed from the queue, and wait for callbacks. 392 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
393 // and verifying that there is no attempt to pick another request following
394 // this failure code.
395
396 // Verify neither request is removed from the queue; wait for callbacks.
387 coordinator()->queue()->GetRequests( 397 coordinator()->queue()->GetRequests(
388 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 398 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
389 base::Unretained(this))); 399 base::Unretained(this)));
390 PumpLoop(); 400 PumpLoop();
391 401
392 // Still one request in the queue. 402 // Still two requests in the queue.
393 EXPECT_EQ(1UL, last_requests().size()); 403 EXPECT_EQ(2UL, last_requests().size());
394 // Verify retry count was incremented. 404 // Verify retry count was incremented for first request.
395 const SavePageRequest& found_request = last_requests().front(); 405 const SavePageRequest& found_request = last_requests().front();
396 EXPECT_EQ(1L, found_request.attempt_count()); 406 EXPECT_EQ(1L, found_request.attempt_count());
397 } 407 }
408
409 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestCanceled) {
Pete Williamson 2016/08/02 22:20:00 Why are we removing this test? Intentional?
dougarnett 2016/08/03 15:33:26 Intentional - wasn't really testing anything addit
410 // Add a request to the queue, wait for callbacks to finish.
411 offline_pages::SavePageRequest request(
412 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
413 coordinator()->queue()->AddRequest(
414 request,
415 base::Bind(&RequestCoordinatorTest::AddRequestDone,
416 base::Unretained(this)));
417 PumpLoop();
418
419 // Add second request to the queue to check handling when first cancels.
420 offline_pages::SavePageRequest request2(
421 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested);
422 coordinator()->queue()->AddRequest(
423 request2,
424 base::Bind(&RequestCoordinatorTest::AddRequestDone,
425 base::Unretained(this)));
426 PumpLoop();
427
428 // We need to give a callback to the request.
429 base::Callback<void(bool)> callback =
430 base::Bind(
431 &RequestCoordinatorTest::EmptyCallbackFunction,
432 base::Unretained(this));
433 coordinator()->SetProcessingCallbackForTest(callback);
434
435 // Set up device conditions for the test.
436 DeviceConditions device_conditions(
437 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
438 SetDeviceConditionsForTest(device_conditions);
439
440 // Call the OfflinerDoneCallback to simulate the request failed, wait
441 // for callbacks.
442 EnableOfflinerCallback(true);
443 SendOfflinerDoneCallback(request,
444 Offliner::RequestStatus::PRERENDERING_CANCELED);
445 PumpLoop();
446
447 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
448 // and verifying that there is no attempt to pick another request following
449 // the first one being canceled.
450
451 // Verify neither request is removed from the queue; wait for callbacks.
452 coordinator()->queue()->GetRequests(
453 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
454 base::Unretained(this)));
455 PumpLoop();
456
457 // Still two requests in the queue.
458 EXPECT_EQ(2UL, last_requests().size());
459 // Verify retry count was incremented for first request.
460 const SavePageRequest& found_request = last_requests().front();
461 EXPECT_EQ(1L, found_request.attempt_count());
462 }
398 463
399 // This tests a StopProcessing call before we have actually started the 464 // This tests a StopProcessing call before we have actually started the
400 // prerenderer. 465 // prerenderer.
401 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { 466 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
402 // Add a request to the queue, wait for callbacks to finish. 467 // Add a request to the queue, wait for callbacks to finish.
403 offline_pages::SavePageRequest request( 468 offline_pages::SavePageRequest request(
404 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 469 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
405 coordinator()->queue()->AddRequest( 470 coordinator()->queue()->AddRequest(
406 request, 471 request,
407 base::Bind(&RequestCoordinatorTest::AddRequestDone, 472 base::Bind(&RequestCoordinatorTest::AddRequestDone,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 coordinator()->queue()->GetRequests( 622 coordinator()->queue()->GetRequests(
558 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 623 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
559 base::Unretained(this))); 624 base::Unretained(this)));
560 PumpLoop(); 625 PumpLoop();
561 626
562 // We should find one request in the queue. 627 // We should find one request in the queue.
563 EXPECT_EQ(1UL, last_requests().size()); 628 EXPECT_EQ(1UL, last_requests().size());
564 } 629 }
565 630
566 } // namespace offline_pages 631 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698