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

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

Issue 2425873003: [Offline Pages] Add evaluation test support in RequestCoordinator. (Closed)
Patch Set: Created 4 years, 2 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 <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 conditions_ = trigger_conditions; 61 conditions_ = trigger_conditions;
62 } 62 }
63 63
64 void BackupSchedule(const TriggerConditions& trigger_conditions, 64 void BackupSchedule(const TriggerConditions& trigger_conditions,
65 long delay_in_seconds) override { 65 long delay_in_seconds) override {
66 backup_schedule_called_ = true; 66 backup_schedule_called_ = true;
67 schedule_delay_ = delay_in_seconds; 67 schedule_delay_ = delay_in_seconds;
68 conditions_ = trigger_conditions; 68 conditions_ = trigger_conditions;
69 } 69 }
70 70
71
72 // Unschedules the currently scheduled task, if any. 71 // Unschedules the currently scheduled task, if any.
73 void Unschedule() override { 72 void Unschedule() override {
74 unschedule_called_ = true; 73 unschedule_called_ = true;
75 } 74 }
76 75
77 bool schedule_called() const { return schedule_called_; } 76 bool schedule_called() const { return schedule_called_; }
78 77
79 bool backup_schedule_called() const { return backup_schedule_called_;} 78 bool backup_schedule_called() const { return backup_schedule_called_;}
80 79
81 bool unschedule_called() const { return unschedule_called_; } 80 bool unschedule_called() const { return unschedule_called_; }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return coordinator_.get(); 231 return coordinator_.get();
233 } 232 }
234 233
235 bool is_busy() { 234 bool is_busy() {
236 return coordinator_->is_busy(); 235 return coordinator_->is_busy();
237 } 236 }
238 237
239 bool is_starting() { return coordinator_->is_starting(); } 238 bool is_starting() { return coordinator_->is_starting(); }
240 239
241 // Empty callback function. 240 // Empty callback function.
242 void EmptyCallbackFunction(bool result) { 241 void EmptyCallbackFunction(bool result) {
Pete Williamson 2016/10/18 19:24:32 This should be renamed consistent with whatever na
romax 2016/10/18 20:31:51 Done.
242 last_empty_callback_called_ = true;
243 } 243 }
244 244
245 // Callback function which releases a wait for it. 245 // Callback function which releases a wait for it.
246 void WaitingCallbackFunction(bool result) { 246 void WaitingCallbackFunction(bool result) {
247 waiter_.Signal(); 247 waiter_.Signal();
248 } 248 }
249 249
250 // Callback for Add requests. 250 // Callback for Add requests.
251 void AddRequestDone(RequestQueue::AddRequestResult result, 251 void AddRequestDone(RequestQueue::AddRequestResult result,
252 const SavePageRequest& request); 252 const SavePageRequest& request);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 319 }
320 320
321 Offliner::RequestStatus last_offlining_status() const { 321 Offliner::RequestStatus last_offlining_status() const {
322 return coordinator_->last_offlining_status_; 322 return coordinator_->last_offlining_status_;
323 } 323 }
324 324
325 bool OfflinerWasCanceled() const { return offliner_->cancel_called(); } 325 bool OfflinerWasCanceled() const { return offliner_->cancel_called(); }
326 326
327 ObserverStub observer() { return observer_; } 327 ObserverStub observer() { return observer_; }
328 328
329 bool last_empty_callback_called() const {
dougarnett 2016/10/18 17:26:32 don't like this naming - maybe immediate_schedule_
romax 2016/10/18 20:31:51 Done.
330 return last_empty_callback_called_;
331 }
332
329 private: 333 private:
330 RequestQueue::GetRequestsResult last_get_requests_result_; 334 RequestQueue::GetRequestsResult last_get_requests_result_;
331 MultipleItemStatuses last_remove_results_; 335 MultipleItemStatuses last_remove_results_;
332 std::vector<std::unique_ptr<SavePageRequest>> last_requests_; 336 std::vector<std::unique_ptr<SavePageRequest>> last_requests_;
333 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; 337 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
334 base::ThreadTaskRunnerHandle task_runner_handle_; 338 base::ThreadTaskRunnerHandle task_runner_handle_;
335 std::unique_ptr<NetworkQualityEstimatorStub> network_quality_estimator_; 339 std::unique_ptr<NetworkQualityEstimatorStub> network_quality_estimator_;
336 std::unique_ptr<RequestCoordinator> coordinator_; 340 std::unique_ptr<RequestCoordinator> coordinator_;
337 OfflinerStub* offliner_; 341 OfflinerStub* offliner_;
338 base::WaitableEvent waiter_; 342 base::WaitableEvent waiter_;
339 ObserverStub observer_; 343 ObserverStub observer_;
344 bool last_empty_callback_called_;
340 }; 345 };
341 346
342 RequestCoordinatorTest::RequestCoordinatorTest() 347 RequestCoordinatorTest::RequestCoordinatorTest()
343 : last_get_requests_result_(RequestQueue::GetRequestsResult::STORE_FAILURE), 348 : last_get_requests_result_(RequestQueue::GetRequestsResult::STORE_FAILURE),
344 task_runner_(new base::TestMockTimeTaskRunner), 349 task_runner_(new base::TestMockTimeTaskRunner),
345 task_runner_handle_(task_runner_), 350 task_runner_handle_(task_runner_),
346 offliner_(nullptr), 351 offliner_(nullptr),
347 waiter_(base::WaitableEvent::ResetPolicy::MANUAL, 352 waiter_(base::WaitableEvent::ResetPolicy::MANUAL,
348 base::WaitableEvent::InitialState::NOT_SIGNALED) {} 353 base::WaitableEvent::InitialState::NOT_SIGNALED),
354 last_empty_callback_called_(false) {}
349 355
350 RequestCoordinatorTest::~RequestCoordinatorTest() {} 356 RequestCoordinatorTest::~RequestCoordinatorTest() {}
351 357
352 void RequestCoordinatorTest::SetUp() { 358 void RequestCoordinatorTest::SetUp() {
353 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy()); 359 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy());
354 std::unique_ptr<OfflinerFactory> factory(new OfflinerFactoryStub()); 360 std::unique_ptr<OfflinerFactory> factory(new OfflinerFactoryStub());
355 // Save the offliner for use by the tests. 361 // Save the offliner for use by the tests.
356 offliner_ = 362 offliner_ =
357 reinterpret_cast<OfflinerStub*>(factory->GetOffliner(policy.get())); 363 reinterpret_cast<OfflinerStub*>(factory->GetOffliner(policy.get()));
358 std::unique_ptr<RequestQueueInMemoryStore> 364 std::unique_ptr<RequestQueueInMemoryStore>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 410 }
405 411
406 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { 412 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
407 DeviceConditions device_conditions(false, 75, 413 DeviceConditions device_conditions(false, 75,
408 net::NetworkChangeNotifier::CONNECTION_3G); 414 net::NetworkChangeNotifier::CONNECTION_3G);
409 base::Callback<void(bool)> callback = 415 base::Callback<void(bool)> callback =
410 base::Bind( 416 base::Bind(
411 &RequestCoordinatorTest::EmptyCallbackFunction, 417 &RequestCoordinatorTest::EmptyCallbackFunction,
412 base::Unretained(this)); 418 base::Unretained(this));
413 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 419 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
420 PumpLoop();
421 EXPECT_TRUE(last_empty_callback_called());
414 } 422 }
415 423
416 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { 424 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
417 // Put the request on the queue. 425 // Put the request on the queue.
418 EXPECT_NE( 426 EXPECT_NE(
419 coordinator()->SavePageLater( 427 coordinator()->SavePageLater(
420 kUrl1, kClientId1, kUserRequested, 428 kUrl1, kClientId1, kUserRequested,
421 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 429 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
422 430
423 // Set up for the call to StartProcessing by building arguments. 431 // Set up for the call to StartProcessing by building arguments.
424 DeviceConditions device_conditions( 432 DeviceConditions device_conditions(
425 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 433 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
426 base::Callback<void(bool)> callback = 434 base::Callback<void(bool)> callback =
427 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, 435 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction,
428 base::Unretained(this)); 436 base::Unretained(this));
429 437
430 // Ensure that the forthcoming request does not finish - we simulate it being 438 // Ensure that the forthcoming request does not finish - we simulate it being
431 // in progress by asking it to skip making the completion callback. 439 // in progress by asking it to skip making the completion callback.
432 EnableOfflinerCallback(false); 440 EnableOfflinerCallback(false);
433 441
434 // Sending the request to the offliner should make it busy. 442 // Sending the request to the offliner should make it busy.
435 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 443 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
436 PumpLoop(); 444 PumpLoop();
437 EXPECT_TRUE(is_busy()); 445 EXPECT_TRUE(is_busy());
446 // Since the offliner is disabled, this callback should not be called.
447 EXPECT_FALSE(last_empty_callback_called());
438 448
439 // Now trying to start processing on another request should return false. 449 // Now trying to start processing on another request should return false.
440 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); 450 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback));
441 } 451 }
442 452
443 TEST_F(RequestCoordinatorTest, SavePageLater) { 453 TEST_F(RequestCoordinatorTest, SavePageLater) {
454 // Set up device conditions for the test and enable the offliner.
455 DeviceConditions device_conditions(false, 75,
456 net::NetworkChangeNotifier::CONNECTION_3G);
457 SetDeviceConditionsForTest(device_conditions);
458 SetEffectiveConnectionTypeForTest(
459 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
460 EnableOfflinerCallback(true);
461 base::Callback<void(bool)> callback = base::Bind(
462 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
463
464 // The user-requested request which gets processed by SavePageLater
465 // would invoke user request callback.
466 coordinator()->SetUserRequestCallbackForTest(callback);
467
444 EXPECT_NE( 468 EXPECT_NE(
445 coordinator()->SavePageLater( 469 coordinator()->SavePageLater(
446 kUrl1, kClientId1, kUserRequested, 470 kUrl1, kClientId1, kUserRequested,
447 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 471 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
448 472
449 // Expect that a request got placed on the queue. 473 // Expect that a request got placed on the queue.
474 coordinator()->queue()->GetRequests(base::Bind(
475 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
476
477 // Wait for callbacks to finish, both request queue and offliner.
478 PumpLoop();
479 EXPECT_TRUE(last_empty_callback_called());
480
481 // Check the request queue is as expected.
482 EXPECT_EQ(1UL, last_requests().size());
483 EXPECT_EQ(kUrl1, last_requests().at(0)->url());
484 EXPECT_EQ(kClientId1, last_requests().at(0)->client_id());
485
486 // Expect that the scheduler got notified.
487 SchedulerStub* scheduler_stub =
488 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
489 EXPECT_TRUE(scheduler_stub->schedule_called());
490 EXPECT_EQ(coordinator()
491 ->GetTriggerConditions(last_requests()[0]->user_requested())
492 .minimum_battery_percentage,
493 scheduler_stub->conditions()->minimum_battery_percentage);
494
495 // Check that the observer got the notification that a page is available
496 EXPECT_TRUE(observer().added_called());
497 }
498
499 TEST_F(RequestCoordinatorTest, SavePageLaterFailed) {
500 // Set up device conditions for the test and enable the offliner.
501 DeviceConditions device_conditions(false, 75,
502 net::NetworkChangeNotifier::CONNECTION_3G);
503 SetDeviceConditionsForTest(device_conditions);
504 SetEffectiveConnectionTypeForTest(
505 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
506 EnableOfflinerCallback(true);
507 base::Callback<void(bool)> callback = base::Bind(
508 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
509 // The user-requested request which gets processed by SavePageLater
510 // would invoke user request callback.
511 coordinator()->SetUserRequestCallbackForTest(callback);
512
513 EXPECT_TRUE(
514 coordinator()->SavePageLater(
515 kUrl1, kClientId1, kUserRequested,
516 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
517
518 // Expect that a request got placed on the queue.
450 coordinator()->queue()->GetRequests( 519 coordinator()->queue()->GetRequests(
451 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 520 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
452 base::Unretained(this))); 521 base::Unretained(this)));
453 522
454 // Wait for callbacks to finish, both request queue and offliner. 523 // Wait for callbacks to finish, both request queue and offliner.
455 PumpLoop(); 524 PumpLoop();
525 EXPECT_TRUE(last_empty_callback_called());
456 526
457 // Check the request queue is as expected. 527 // Check the request queue is as expected.
458 EXPECT_EQ(1UL, last_requests().size()); 528 EXPECT_EQ(1UL, last_requests().size());
459 EXPECT_EQ(kUrl1, last_requests().at(0)->url()); 529 EXPECT_EQ(kUrl1, last_requests().at(0)->url());
460 EXPECT_EQ(kClientId1, last_requests().at(0)->client_id()); 530 EXPECT_EQ(kClientId1, last_requests().at(0)->client_id());
461 531
462 // Expect that the scheduler got notified. 532 // Expect that the scheduler got notified.
463 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( 533 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
464 coordinator()->scheduler()); 534 coordinator()->scheduler());
465 EXPECT_TRUE(scheduler_stub->schedule_called()); 535 EXPECT_TRUE(scheduler_stub->schedule_called());
(...skipping 26 matching lines...) Expand all
492 562
493 // Set up device conditions for the test. 563 // Set up device conditions for the test.
494 DeviceConditions device_conditions( 564 DeviceConditions device_conditions(
495 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 565 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
496 SetDeviceConditionsForTest(device_conditions); 566 SetDeviceConditionsForTest(device_conditions);
497 567
498 // Call the OfflinerDoneCallback to simulate the page being completed, wait 568 // Call the OfflinerDoneCallback to simulate the page being completed, wait
499 // for callbacks. 569 // for callbacks.
500 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); 570 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED);
501 PumpLoop(); 571 PumpLoop();
572 EXPECT_TRUE(last_empty_callback_called());
502 573
503 // Verify the request gets removed from the queue, and wait for callbacks. 574 // Verify the request gets removed from the queue, and wait for callbacks.
504 coordinator()->queue()->GetRequests( 575 coordinator()->queue()->GetRequests(
505 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 576 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
506 base::Unretained(this))); 577 base::Unretained(this)));
507 PumpLoop(); 578 PumpLoop();
508 579
509 // We should not find any requests in the queue anymore. 580 // We should not find any requests in the queue anymore.
510 // RequestPicker should *not* have tried to start an additional job, 581 // RequestPicker should *not* have tried to start an additional job,
511 // because the request queue is empty now. 582 // because the request queue is empty now.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 // Set up device conditions for the test. 618 // Set up device conditions for the test.
548 DeviceConditions device_conditions( 619 DeviceConditions device_conditions(
549 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 620 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
550 SetDeviceConditionsForTest(device_conditions); 621 SetDeviceConditionsForTest(device_conditions);
551 622
552 // Call the OfflinerDoneCallback to simulate the request failed, wait 623 // Call the OfflinerDoneCallback to simulate the request failed, wait
553 // for callbacks. 624 // for callbacks.
554 SendOfflinerDoneCallback(request, 625 SendOfflinerDoneCallback(request,
555 Offliner::RequestStatus::PRERENDERING_FAILED); 626 Offliner::RequestStatus::PRERENDERING_FAILED);
556 PumpLoop(); 627 PumpLoop();
628 EXPECT_TRUE(last_empty_callback_called());
557 629
558 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 630 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
559 // and verifying that there is no attempt to pick another request following 631 // and verifying that there is no attempt to pick another request following
560 // this failure code. 632 // this failure code.
561 633
562 coordinator()->queue()->GetRequests( 634 coordinator()->queue()->GetRequests(
563 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 635 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
564 base::Unretained(this))); 636 base::Unretained(this)));
565 PumpLoop(); 637 PumpLoop();
566 638
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 // Set up device conditions for the test. 672 // Set up device conditions for the test.
601 DeviceConditions device_conditions(false, 75, 673 DeviceConditions device_conditions(false, 75,
602 net::NetworkChangeNotifier::CONNECTION_3G); 674 net::NetworkChangeNotifier::CONNECTION_3G);
603 SetDeviceConditionsForTest(device_conditions); 675 SetDeviceConditionsForTest(device_conditions);
604 676
605 // Call the OfflinerDoneCallback to simulate the request failed, wait 677 // Call the OfflinerDoneCallback to simulate the request failed, wait
606 // for callbacks. 678 // for callbacks.
607 SendOfflinerDoneCallback( 679 SendOfflinerDoneCallback(
608 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY); 680 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY);
609 PumpLoop(); 681 PumpLoop();
682 EXPECT_TRUE(last_empty_callback_called());
610 683
611 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 684 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
612 // and verifying that there is as attempt to pick another request following 685 // and verifying that there is as attempt to pick another request following
613 // this non-retryable failure code. 686 // this non-retryable failure code.
614 687
615 coordinator()->queue()->GetRequests(base::Bind( 688 coordinator()->queue()->GetRequests(base::Bind(
616 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 689 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
617 PumpLoop(); 690 PumpLoop();
618 691
619 // Now just one request in the queue since non-retryable failure. 692 // Now just one request in the queue since non-retryable failure.
(...skipping 23 matching lines...) Expand all
643 // Set up device conditions for the test. 716 // Set up device conditions for the test.
644 DeviceConditions device_conditions(false, 75, 717 DeviceConditions device_conditions(false, 75,
645 net::NetworkChangeNotifier::CONNECTION_3G); 718 net::NetworkChangeNotifier::CONNECTION_3G);
646 SetDeviceConditionsForTest(device_conditions); 719 SetDeviceConditionsForTest(device_conditions);
647 720
648 // Call the OfflinerDoneCallback to simulate the request failed, wait 721 // Call the OfflinerDoneCallback to simulate the request failed, wait
649 // for callbacks. 722 // for callbacks.
650 SendOfflinerDoneCallback(request, 723 SendOfflinerDoneCallback(request,
651 Offliner::RequestStatus::FOREGROUND_CANCELED); 724 Offliner::RequestStatus::FOREGROUND_CANCELED);
652 PumpLoop(); 725 PumpLoop();
726 EXPECT_TRUE(last_empty_callback_called());
653 727
654 // Verify the request is not removed from the queue, and wait for callbacks. 728 // Verify the request is not removed from the queue, and wait for callbacks.
655 coordinator()->queue()->GetRequests(base::Bind( 729 coordinator()->queue()->GetRequests(base::Bind(
656 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 730 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
657 PumpLoop(); 731 PumpLoop();
658 732
659 // Request no longer in the queue (for single attempt policy). 733 // Request no longer in the queue (for single attempt policy).
660 EXPECT_EQ(1UL, last_requests().size()); 734 EXPECT_EQ(1UL, last_requests().size());
661 // Verify foreground cancel not counted as an attempt after all. 735 // Verify foreground cancel not counted as an attempt after all.
662 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count()); 736 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count());
(...skipping 17 matching lines...) Expand all
680 // Set up device conditions for the test. 754 // Set up device conditions for the test.
681 DeviceConditions device_conditions(false, 75, 755 DeviceConditions device_conditions(false, 75,
682 net::NetworkChangeNotifier::CONNECTION_3G); 756 net::NetworkChangeNotifier::CONNECTION_3G);
683 SetDeviceConditionsForTest(device_conditions); 757 SetDeviceConditionsForTest(device_conditions);
684 758
685 // Call the OfflinerDoneCallback to simulate the request failed, wait 759 // Call the OfflinerDoneCallback to simulate the request failed, wait
686 // for callbacks. 760 // for callbacks.
687 SendOfflinerDoneCallback(request, 761 SendOfflinerDoneCallback(request,
688 Offliner::RequestStatus::PRERENDERING_CANCELED); 762 Offliner::RequestStatus::PRERENDERING_CANCELED);
689 PumpLoop(); 763 PumpLoop();
764 EXPECT_TRUE(last_empty_callback_called());
690 765
691 // Verify the request is not removed from the queue, and wait for callbacks. 766 // Verify the request is not removed from the queue, and wait for callbacks.
692 coordinator()->queue()->GetRequests(base::Bind( 767 coordinator()->queue()->GetRequests(base::Bind(
693 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 768 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
694 PumpLoop(); 769 PumpLoop();
695 770
696 // Request still in the queue. 771 // Request still in the queue.
697 EXPECT_EQ(1UL, last_requests().size()); 772 EXPECT_EQ(1UL, last_requests().size());
698 // Verify prerendering cancel not counted as an attempt after all. 773 // Verify prerendering cancel not counted as an attempt after all.
699 const std::unique_ptr<SavePageRequest>& found_request = 774 const std::unique_ptr<SavePageRequest>& found_request =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 811 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
737 coordinator()->StartProcessing(device_conditions, callback); 812 coordinator()->StartProcessing(device_conditions, callback);
738 EXPECT_TRUE(is_starting()); 813 EXPECT_TRUE(is_starting());
739 814
740 // Call RequestNotPicked, and make sure we pick schedule a task for non user 815 // Call RequestNotPicked, and make sure we pick schedule a task for non user
741 // requested conditions, with no tasks on the disabled list. 816 // requested conditions, with no tasks on the disabled list.
742 CallRequestNotPicked(true, false); 817 CallRequestNotPicked(true, false);
743 PumpLoop(); 818 PumpLoop();
744 819
745 EXPECT_FALSE(is_starting()); 820 EXPECT_FALSE(is_starting());
821 EXPECT_TRUE(last_empty_callback_called());
746 822
747 // The scheduler should have been called to schedule the non-user requested 823 // The scheduler should have been called to schedule the non-user requested
748 // task. 824 // task.
749 SchedulerStub* scheduler_stub = 825 SchedulerStub* scheduler_stub =
750 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); 826 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
751 EXPECT_TRUE(scheduler_stub->schedule_called()); 827 EXPECT_TRUE(scheduler_stub->schedule_called());
752 EXPECT_TRUE(scheduler_stub->unschedule_called()); 828 EXPECT_TRUE(scheduler_stub->unschedule_called());
753 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions(); 829 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
754 EXPECT_EQ(conditions->require_power_connected, 830 EXPECT_EQ(conditions->require_power_connected,
755 coordinator()->policy()->PowerRequired(!kUserRequested)); 831 coordinator()->policy()->PowerRequired(!kUserRequested));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 net::NetworkChangeNotifier::CONNECTION_3G); 883 net::NetworkChangeNotifier::CONNECTION_3G);
808 DisableLoading(); 884 DisableLoading();
809 base::Callback<void(bool)> callback = 885 base::Callback<void(bool)> callback =
810 base::Bind( 886 base::Bind(
811 &RequestCoordinatorTest::EmptyCallbackFunction, 887 &RequestCoordinatorTest::EmptyCallbackFunction,
812 base::Unretained(this)); 888 base::Unretained(this));
813 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 889 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
814 890
815 // Let the async callbacks in the request coordinator run. 891 // Let the async callbacks in the request coordinator run.
816 PumpLoop(); 892 PumpLoop();
893 EXPECT_TRUE(last_empty_callback_called());
817 894
818 EXPECT_FALSE(is_starting()); 895 EXPECT_FALSE(is_starting());
819 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status()); 896 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status());
820 } 897 }
821 898
822 // This tests a StopProcessing call before we have actually started the 899 // This tests a StopProcessing call before we have actually started the
823 // prerenderer. 900 // prerenderer.
824 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { 901 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
825 // Add a request to the queue, wait for callbacks to finish. 902 // Add a request to the queue, wait for callbacks to finish.
826 offline_pages::SavePageRequest request( 903 offline_pages::SavePageRequest request(
(...skipping 11 matching lines...) Expand all
838 &RequestCoordinatorTest::EmptyCallbackFunction, 915 &RequestCoordinatorTest::EmptyCallbackFunction,
839 base::Unretained(this)); 916 base::Unretained(this));
840 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 917 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
841 EXPECT_TRUE(is_starting()); 918 EXPECT_TRUE(is_starting());
842 919
843 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. 920 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it.
844 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); 921 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED);
845 922
846 // Let the async callbacks in the request coordinator run. 923 // Let the async callbacks in the request coordinator run.
847 PumpLoop(); 924 PumpLoop();
925 EXPECT_TRUE(last_empty_callback_called());
848 926
849 EXPECT_FALSE(is_starting()); 927 EXPECT_FALSE(is_starting());
850 928
851 // OfflinerDoneCallback will not end up getting called with status SAVED, 929 // OfflinerDoneCallback will not end up getting called with status SAVED,
852 // since we cancelled the event before it called offliner_->LoadAndSave(). 930 // since we cancelled the event before it called offliner_->LoadAndSave().
853 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, 931 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
854 last_offlining_status()); 932 last_offlining_status());
855 933
856 // Since offliner was not started, it will not have seen cancel call. 934 // Since offliner was not started, it will not have seen cancel call.
857 EXPECT_FALSE(OfflinerWasCanceled()); 935 EXPECT_FALSE(OfflinerWasCanceled());
(...skipping 17 matching lines...) Expand all
875 net::NetworkChangeNotifier::CONNECTION_3G); 953 net::NetworkChangeNotifier::CONNECTION_3G);
876 base::Callback<void(bool)> callback = 954 base::Callback<void(bool)> callback =
877 base::Bind( 955 base::Bind(
878 &RequestCoordinatorTest::EmptyCallbackFunction, 956 &RequestCoordinatorTest::EmptyCallbackFunction,
879 base::Unretained(this)); 957 base::Unretained(this));
880 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 958 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
881 EXPECT_TRUE(is_starting()); 959 EXPECT_TRUE(is_starting());
882 960
883 // Let all the async parts of the start processing pipeline run to completion. 961 // Let all the async parts of the start processing pipeline run to completion.
884 PumpLoop(); 962 PumpLoop();
963 // Since the offliner is disabled, this callback should not be called.
964 EXPECT_FALSE(last_empty_callback_called());
885 965
886 // Coordinator should now be busy. 966 // Coordinator should now be busy.
887 EXPECT_TRUE(is_busy()); 967 EXPECT_TRUE(is_busy());
888 EXPECT_FALSE(is_starting()); 968 EXPECT_FALSE(is_starting());
889 969
890 // Now we cancel it while the prerenderer is busy. 970 // Now we cancel it while the prerenderer is busy.
891 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); 971 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED);
892 972
893 // Let the async callbacks in the cancel run. 973 // Let the async callbacks in the cancel run.
894 PumpLoop(); 974 PumpLoop();
(...skipping 24 matching lines...) Expand all
919 EnableOfflinerCallback(false); 999 EnableOfflinerCallback(false);
920 1000
921 DeviceConditions device_conditions(false, 75, 1001 DeviceConditions device_conditions(false, 75,
922 net::NetworkChangeNotifier::CONNECTION_3G); 1002 net::NetworkChangeNotifier::CONNECTION_3G);
923 base::Callback<void(bool)> callback = base::Bind( 1003 base::Callback<void(bool)> callback = base::Bind(
924 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 1004 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
925 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 1005 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
926 1006
927 // Let all the async parts of the start processing pipeline run to completion. 1007 // Let all the async parts of the start processing pipeline run to completion.
928 PumpLoop(); 1008 PumpLoop();
1009 // Since the offliner is disabled, this callback should not be called.
1010 EXPECT_FALSE(last_empty_callback_called());
929 1011
930 // Remove the request while it is processing. 1012 // Remove the request while it is processing.
931 std::vector<int64_t> request_ids{kRequestId1}; 1013 std::vector<int64_t> request_ids{kRequestId1};
932 coordinator()->RemoveRequests( 1014 coordinator()->RemoveRequests(
933 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, 1015 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone,
934 base::Unretained(this))); 1016 base::Unretained(this)));
935 1017
936 // Let the async callbacks in the cancel run. 1018 // Let the async callbacks in the cancel run.
937 PumpLoop(); 1019 PumpLoop();
938 1020
(...skipping 16 matching lines...) Expand all
955 1037
956 DeviceConditions device_conditions(false, 75, 1038 DeviceConditions device_conditions(false, 75,
957 net::NetworkChangeNotifier::CONNECTION_3G); 1039 net::NetworkChangeNotifier::CONNECTION_3G);
958 base::Callback<void(bool)> callback = base::Bind( 1040 base::Callback<void(bool)> callback = base::Bind(
959 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 1041 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
960 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 1042 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
961 1043
962 // Call the method under test, making sure we send SUCCESS to the observer. 1044 // Call the method under test, making sure we send SUCCESS to the observer.
963 coordinator()->MarkRequestCompleted(request_id); 1045 coordinator()->MarkRequestCompleted(request_id);
964 PumpLoop(); 1046 PumpLoop();
1047 EXPECT_TRUE(last_empty_callback_called());
965 1048
966 // Our observer should have seen SUCCESS instead of REMOVED. 1049 // Our observer should have seen SUCCESS instead of REMOVED.
967 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, 1050 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS,
968 observer().last_status()); 1051 observer().last_status());
969 EXPECT_TRUE(observer().completed_called()); 1052 EXPECT_TRUE(observer().completed_called());
970 } 1053 }
971 1054
972 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { 1055 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) {
973 // Build a request to use with the pre-renderer, and put it on the queue. 1056 // Build a request to use with the pre-renderer, and put it on the queue.
974 offline_pages::SavePageRequest request( 1057 offline_pages::SavePageRequest request(
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 // Now whether processing triggered immediately depends on whether test 1351 // Now whether processing triggered immediately depends on whether test
1269 // is run on svelte device or not. 1352 // is run on svelte device or not.
1270 if (base::SysInfo::IsLowEndDevice()) { 1353 if (base::SysInfo::IsLowEndDevice()) {
1271 EXPECT_FALSE(is_busy()); 1354 EXPECT_FALSE(is_busy());
1272 } else { 1355 } else {
1273 EXPECT_TRUE(is_busy()); 1356 EXPECT_TRUE(is_busy());
1274 } 1357 }
1275 } 1358 }
1276 1359
1277 } // namespace offline_pages 1360 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698