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

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

Issue 2209813002: [Offline Pages] Moves Coordinator to using MarkAttemptStarted/MarkAttemptCompleted API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ(coordinator() 325 EXPECT_EQ(coordinator()
326 ->GetTriggerConditionsForUserRequest() 326 ->GetTriggerConditionsForUserRequest()
327 .minimum_battery_percentage, 327 .minimum_battery_percentage,
328 scheduler_stub->conditions()->minimum_battery_percentage); 328 scheduler_stub->conditions()->minimum_battery_percentage);
329 } 329 }
330 330
331 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { 331 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
332 // Add a request to the queue, wait for callbacks to finish. 332 // Add a request to the queue, wait for callbacks to finish.
333 offline_pages::SavePageRequest request( 333 offline_pages::SavePageRequest request(
334 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 334 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
335 request.MarkAttemptStarted(base::Time::Now());
335 coordinator()->queue()->AddRequest( 336 coordinator()->queue()->AddRequest(
336 request, 337 request,
337 base::Bind(&RequestCoordinatorTest::AddRequestDone, 338 base::Bind(&RequestCoordinatorTest::AddRequestDone,
338 base::Unretained(this))); 339 base::Unretained(this)));
339 PumpLoop(); 340 PumpLoop();
340 341
341 // We need to give a callback to the request. 342 // We need to give a callback to the request.
342 base::Callback<void(bool)> callback = 343 base::Callback<void(bool)> callback =
343 base::Bind( 344 base::Bind(
344 &RequestCoordinatorTest::EmptyCallbackFunction, 345 &RequestCoordinatorTest::EmptyCallbackFunction,
(...skipping 20 matching lines...) Expand all
365 // We should not find any requests in the queue anymore. 366 // We should not find any requests in the queue anymore.
366 // RequestPicker should *not* have tried to start an additional job, 367 // RequestPicker should *not* have tried to start an additional job,
367 // because the request queue is empty now. 368 // because the request queue is empty now.
368 EXPECT_EQ(0UL, last_requests().size()); 369 EXPECT_EQ(0UL, last_requests().size());
369 } 370 }
370 371
371 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 372 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
372 // Add a request to the queue, wait for callbacks to finish. 373 // Add a request to the queue, wait for callbacks to finish.
373 offline_pages::SavePageRequest request( 374 offline_pages::SavePageRequest request(
374 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 375 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
376 request.MarkAttemptStarted(base::Time::Now());
375 coordinator()->queue()->AddRequest( 377 coordinator()->queue()->AddRequest(
376 request, 378 request,
377 base::Bind(&RequestCoordinatorTest::AddRequestDone, 379 base::Bind(&RequestCoordinatorTest::AddRequestDone,
378 base::Unretained(this))); 380 base::Unretained(this)));
379 PumpLoop(); 381 PumpLoop();
380 382
381 // Add second request to the queue to check handling when first fails. 383 // Add second request to the queue to check handling when first fails.
382 offline_pages::SavePageRequest request2( 384 offline_pages::SavePageRequest request2(
383 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); 385 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested);
384 coordinator()->queue()->AddRequest( 386 coordinator()->queue()->AddRequest(
(...skipping 24 matching lines...) Expand all
409 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 411 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
410 // and verifying that there is no attempt to pick another request following 412 // and verifying that there is no attempt to pick another request following
411 // this failure code. 413 // this failure code.
412 414
413 // Verify neither request is removed from the queue; wait for callbacks. 415 // Verify neither request is removed from the queue; wait for callbacks.
414 coordinator()->queue()->GetRequests( 416 coordinator()->queue()->GetRequests(
415 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 417 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
416 base::Unretained(this))); 418 base::Unretained(this)));
417 PumpLoop(); 419 PumpLoop();
418 420
419 // Still two requests in the queue. 421 // Now just one request in the queue since failed request removed
420 EXPECT_EQ(2UL, last_requests().size()); 422 // (for single attempt policy).
421 // Verify retry count was incremented for first request. 423 EXPECT_EQ(1UL, last_requests().size());
424 }
425
426 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
427 // Add a request to the queue, wait for callbacks to finish.
428 offline_pages::SavePageRequest request(
429 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
430 request.MarkAttemptStarted(base::Time::Now());
431 coordinator()->queue()->AddRequest(
432 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
433 base::Unretained(this)));
434 PumpLoop();
435
436 // We need to give a callback to the request.
437 base::Callback<void(bool)> callback = base::Bind(
438 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
439 coordinator()->SetProcessingCallbackForTest(callback);
440
441 // Set up device conditions for the test.
442 DeviceConditions device_conditions(false, 75,
443 net::NetworkChangeNotifier::CONNECTION_3G);
444 SetDeviceConditionsForTest(device_conditions);
445
446 // Call the OfflinerDoneCallback to simulate the request failed, wait
447 // for callbacks.
448 EnableOfflinerCallback(true);
449 SendOfflinerDoneCallback(request,
450 Offliner::RequestStatus::FOREGROUND_CANCELED);
451 PumpLoop();
452
453 // Verify the request is not removed from the queue, and wait for callbacks.
454 coordinator()->queue()->GetRequests(base::Bind(
455 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
456 PumpLoop();
457
458 // Request no longer in the queue (for single attempt policy).
459 EXPECT_EQ(1UL, last_requests().size());
460 // Verify foreground cancel not counted as an attempt after all.
422 const SavePageRequest& found_request = last_requests().front(); 461 const SavePageRequest& found_request = last_requests().front();
423 EXPECT_EQ(1L, found_request.attempt_count()); 462 EXPECT_EQ(0L, found_request.attempt_count());
424 } 463 }
425 464
426 // This tests a StopProcessing call before we have actually started the 465 // This tests a StopProcessing call before we have actually started the
427 // prerenderer. 466 // prerenderer.
428 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { 467 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
429 // Add a request to the queue, wait for callbacks to finish. 468 // Add a request to the queue, wait for callbacks to finish.
430 offline_pages::SavePageRequest request( 469 offline_pages::SavePageRequest request(
431 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 470 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
432 coordinator()->queue()->AddRequest( 471 coordinator()->queue()->AddRequest(
433 request, 472 request,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 530
492 // OfflinerDoneCallback will not end up getting called with status SAVED, 531 // OfflinerDoneCallback will not end up getting called with status SAVED,
493 // since we cancelled the event before the LoadAndSave completed. 532 // since we cancelled the event before the LoadAndSave completed.
494 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, 533 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
495 last_offlining_status()); 534 last_offlining_status());
496 535
497 // Since offliner was started, it will have seen cancel call. 536 // Since offliner was started, it will have seen cancel call.
498 EXPECT_TRUE(OfflinerWasCanceled()); 537 EXPECT_TRUE(OfflinerWasCanceled());
499 } 538 }
500 539
501 TEST_F(RequestCoordinatorTest, PrerendererTimeout) { 540 TEST_F(RequestCoordinatorTest, WatchdogTimeout) {
502 // Build a request to use with the pre-renderer, and put it on the queue. 541 // Build a request to use with the pre-renderer, and put it on the queue.
503 offline_pages::SavePageRequest request( 542 offline_pages::SavePageRequest request(
504 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 543 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
505 coordinator()->queue()->AddRequest( 544 coordinator()->queue()->AddRequest(
506 request, 545 request,
507 base::Bind(&RequestCoordinatorTest::AddRequestDone, 546 base::Bind(&RequestCoordinatorTest::AddRequestDone,
508 base::Unretained(this))); 547 base::Unretained(this)));
509 PumpLoop(); 548 PumpLoop();
510 549
511 // Set up for the call to StartProcessing. 550 // Set up for the call to StartProcessing.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 WaitForCallback(); 653 WaitForCallback();
615 PumpLoop(); 654 PumpLoop();
616 655
617 // Check that the statuses found in the callback match what we expect. 656 // Check that the statuses found in the callback match what we expect.
618 EXPECT_EQ(2UL, last_client_ids().size()); 657 EXPECT_EQ(2UL, last_client_ids().size());
619 EXPECT_EQ(kId1, last_client_ids().at(0).id); 658 EXPECT_EQ(kId1, last_client_ids().at(0).id);
620 EXPECT_EQ(kId2, last_client_ids().at(1).id); 659 EXPECT_EQ(kId2, last_client_ids().at(1).id);
621 } 660 }
622 661
623 } // namespace offline_pages 662 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698