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

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: Addressed comments. 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 ImmediateScheduleCallbackFunction(bool result) {
242 immediate_schedule_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 immediate_schedule_callback_called() const {
330 return immediate_schedule_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 immediate_schedule_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 immediate_schedule_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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 void RequestCoordinatorTest::SendOfflinerDoneCallback( 406 void RequestCoordinatorTest::SendOfflinerDoneCallback(
401 const SavePageRequest& request, Offliner::RequestStatus status) { 407 const SavePageRequest& request, Offliner::RequestStatus status) {
402 // Using the fact that the test class is a friend, call to the callback 408 // Using the fact that the test class is a friend, call to the callback
403 coordinator_->OfflinerDoneCallback(request, status); 409 coordinator_->OfflinerDoneCallback(request, status);
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(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
411 &RequestCoordinatorTest::EmptyCallbackFunction, 417 base::Unretained(this));
412 base::Unretained(this));
413 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 418 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
419 PumpLoop();
420 EXPECT_TRUE(immediate_schedule_callback_called());
414 } 421 }
415 422
416 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { 423 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
417 // Put the request on the queue. 424 // Put the request on the queue.
418 EXPECT_NE( 425 EXPECT_NE(
419 coordinator()->SavePageLater( 426 coordinator()->SavePageLater(
420 kUrl1, kClientId1, kUserRequested, 427 kUrl1, kClientId1, kUserRequested,
421 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 428 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
422 429
423 // Set up for the call to StartProcessing by building arguments. 430 // Set up for the call to StartProcessing by building arguments.
424 DeviceConditions device_conditions( 431 DeviceConditions device_conditions(
425 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 432 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
426 base::Callback<void(bool)> callback = 433 base::Callback<void(bool)> callback =
427 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, 434 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
428 base::Unretained(this)); 435 base::Unretained(this));
429 436
430 // Ensure that the forthcoming request does not finish - we simulate it being 437 // Ensure that the forthcoming request does not finish - we simulate it being
431 // in progress by asking it to skip making the completion callback. 438 // in progress by asking it to skip making the completion callback.
432 EnableOfflinerCallback(false); 439 EnableOfflinerCallback(false);
433 440
434 // Sending the request to the offliner should make it busy. 441 // Sending the request to the offliner should make it busy.
435 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 442 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
436 PumpLoop(); 443 PumpLoop();
437 EXPECT_TRUE(is_busy()); 444 EXPECT_TRUE(is_busy());
445 // Since the offliner is disabled, this callback should not be called.
446 EXPECT_FALSE(immediate_schedule_callback_called());
438 447
439 // Now trying to start processing on another request should return false. 448 // Now trying to start processing on another request should return false.
440 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); 449 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback));
441 } 450 }
442 451
443 TEST_F(RequestCoordinatorTest, SavePageLater) { 452 TEST_F(RequestCoordinatorTest, SavePageLater) {
453 // Set up device conditions for the test and enable the offliner.
454 DeviceConditions device_conditions(false, 75,
455 net::NetworkChangeNotifier::CONNECTION_3G);
456 SetDeviceConditionsForTest(device_conditions);
457 SetEffectiveConnectionTypeForTest(
458 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
459 EnableOfflinerCallback(true);
460 base::Callback<void(bool)> callback =
461 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
462 base::Unretained(this));
463
464 // The user-requested request which gets processed by SavePageLater
465 // would invoke user request callback.
466 coordinator()->SetImmediateScheduleCallbackForTest(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(immediate_schedule_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 base::Callback<void(bool)> callback =
507 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
508 base::Unretained(this));
509 // The user-requested request which gets processed by SavePageLater
510 // would invoke user request callback.
511 coordinator()->SetImmediateScheduleCallbackForTest(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 // Will not be called since the offliner is disabled.
526 EXPECT_FALSE(immediate_schedule_callback_called());
456 527
457 // Check the request queue is as expected. 528 // Check the request queue is as expected.
458 EXPECT_EQ(1UL, last_requests().size()); 529 EXPECT_EQ(1UL, last_requests().size());
459 EXPECT_EQ(kUrl1, last_requests().at(0)->url()); 530 EXPECT_EQ(kUrl1, last_requests().at(0)->url());
460 EXPECT_EQ(kClientId1, last_requests().at(0)->client_id()); 531 EXPECT_EQ(kClientId1, last_requests().at(0)->client_id());
461 532
462 // Expect that the scheduler got notified. 533 // Expect that the scheduler got notified.
463 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( 534 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
464 coordinator()->scheduler()); 535 coordinator()->scheduler());
465 EXPECT_TRUE(scheduler_stub->schedule_called()); 536 EXPECT_TRUE(scheduler_stub->schedule_called());
(...skipping 12 matching lines...) Expand all
478 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 549 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
479 request.MarkAttemptStarted(base::Time::Now()); 550 request.MarkAttemptStarted(base::Time::Now());
480 coordinator()->queue()->AddRequest( 551 coordinator()->queue()->AddRequest(
481 request, 552 request,
482 base::Bind(&RequestCoordinatorTest::AddRequestDone, 553 base::Bind(&RequestCoordinatorTest::AddRequestDone,
483 base::Unretained(this))); 554 base::Unretained(this)));
484 PumpLoop(); 555 PumpLoop();
485 556
486 // We need to give a callback to the request. 557 // We need to give a callback to the request.
487 base::Callback<void(bool)> callback = 558 base::Callback<void(bool)> callback =
488 base::Bind( 559 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
489 &RequestCoordinatorTest::EmptyCallbackFunction, 560 base::Unretained(this));
490 base::Unretained(this));
491 coordinator()->SetProcessingCallbackForTest(callback); 561 coordinator()->SetProcessingCallbackForTest(callback);
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(immediate_schedule_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 20 matching lines...) Expand all
532 offline_pages::SavePageRequest request2( 603 offline_pages::SavePageRequest request2(
533 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); 604 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested);
534 coordinator()->queue()->AddRequest( 605 coordinator()->queue()->AddRequest(
535 request2, 606 request2,
536 base::Bind(&RequestCoordinatorTest::AddRequestDone, 607 base::Bind(&RequestCoordinatorTest::AddRequestDone,
537 base::Unretained(this))); 608 base::Unretained(this)));
538 PumpLoop(); 609 PumpLoop();
539 610
540 // We need to give a callback to the request. 611 // We need to give a callback to the request.
541 base::Callback<void(bool)> callback = 612 base::Callback<void(bool)> callback =
542 base::Bind( 613 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
543 &RequestCoordinatorTest::EmptyCallbackFunction, 614 base::Unretained(this));
544 base::Unretained(this));
545 coordinator()->SetProcessingCallbackForTest(callback); 615 coordinator()->SetProcessingCallbackForTest(callback);
546 616
547 // Set up device conditions for the test. 617 // Set up device conditions for the test.
548 DeviceConditions device_conditions( 618 DeviceConditions device_conditions(
549 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 619 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
550 SetDeviceConditionsForTest(device_conditions); 620 SetDeviceConditionsForTest(device_conditions);
551 621
552 // Call the OfflinerDoneCallback to simulate the request failed, wait 622 // Call the OfflinerDoneCallback to simulate the request failed, wait
553 // for callbacks. 623 // for callbacks.
554 SendOfflinerDoneCallback(request, 624 SendOfflinerDoneCallback(request,
555 Offliner::RequestStatus::PRERENDERING_FAILED); 625 Offliner::RequestStatus::PRERENDERING_FAILED);
556 PumpLoop(); 626 PumpLoop();
627 EXPECT_TRUE(immediate_schedule_callback_called());
557 628
558 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 629 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
559 // and verifying that there is no attempt to pick another request following 630 // and verifying that there is no attempt to pick another request following
560 // this failure code. 631 // this failure code.
561 632
562 coordinator()->queue()->GetRequests( 633 coordinator()->queue()->GetRequests(
563 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 634 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
564 base::Unretained(this))); 635 base::Unretained(this)));
565 PumpLoop(); 636 PumpLoop();
566 637
(...skipping 19 matching lines...) Expand all
586 657
587 // Add second request to the queue to check handling when first fails. 658 // Add second request to the queue to check handling when first fails.
588 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2, 659 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2,
589 base::Time::Now(), kUserRequested); 660 base::Time::Now(), kUserRequested);
590 coordinator()->queue()->AddRequest( 661 coordinator()->queue()->AddRequest(
591 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone, 662 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone,
592 base::Unretained(this))); 663 base::Unretained(this)));
593 PumpLoop(); 664 PumpLoop();
594 665
595 // We need to give a callback to the request. 666 // We need to give a callback to the request.
596 base::Callback<void(bool)> callback = base::Bind( 667 base::Callback<void(bool)> callback =
597 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 668 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
669 base::Unretained(this));
598 coordinator()->SetProcessingCallbackForTest(callback); 670 coordinator()->SetProcessingCallbackForTest(callback);
599 671
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(immediate_schedule_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.
620 EXPECT_EQ(1UL, last_requests().size()); 693 EXPECT_EQ(1UL, last_requests().size());
621 // Check that the observer got the notification that we failed (and the 694 // Check that the observer got the notification that we failed (and the
622 // subsequent notification that the request was removed). 695 // subsequent notification that the request was removed).
623 EXPECT_TRUE(observer().completed_called()); 696 EXPECT_TRUE(observer().completed_called());
624 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE, 697 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE,
625 observer().last_status()); 698 observer().last_status());
626 } 699 }
627 700
628 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { 701 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
629 // Add a request to the queue, wait for callbacks to finish. 702 // Add a request to the queue, wait for callbacks to finish.
630 offline_pages::SavePageRequest request( 703 offline_pages::SavePageRequest request(
631 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 704 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
632 request.MarkAttemptStarted(base::Time::Now()); 705 request.MarkAttemptStarted(base::Time::Now());
633 coordinator()->queue()->AddRequest( 706 coordinator()->queue()->AddRequest(
634 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, 707 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
635 base::Unretained(this))); 708 base::Unretained(this)));
636 PumpLoop(); 709 PumpLoop();
637 710
638 // We need to give a callback to the request. 711 // We need to give a callback to the request.
639 base::Callback<void(bool)> callback = base::Bind( 712 base::Callback<void(bool)> callback =
640 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 713 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
714 base::Unretained(this));
641 coordinator()->SetProcessingCallbackForTest(callback); 715 coordinator()->SetProcessingCallbackForTest(callback);
642 716
643 // Set up device conditions for the test. 717 // Set up device conditions for the test.
644 DeviceConditions device_conditions(false, 75, 718 DeviceConditions device_conditions(false, 75,
645 net::NetworkChangeNotifier::CONNECTION_3G); 719 net::NetworkChangeNotifier::CONNECTION_3G);
646 SetDeviceConditionsForTest(device_conditions); 720 SetDeviceConditionsForTest(device_conditions);
647 721
648 // Call the OfflinerDoneCallback to simulate the request failed, wait 722 // Call the OfflinerDoneCallback to simulate the request failed, wait
649 // for callbacks. 723 // for callbacks.
650 SendOfflinerDoneCallback(request, 724 SendOfflinerDoneCallback(request,
651 Offliner::RequestStatus::FOREGROUND_CANCELED); 725 Offliner::RequestStatus::FOREGROUND_CANCELED);
652 PumpLoop(); 726 PumpLoop();
727 EXPECT_TRUE(immediate_schedule_callback_called());
653 728
654 // Verify the request is not removed from the queue, and wait for callbacks. 729 // Verify the request is not removed from the queue, and wait for callbacks.
655 coordinator()->queue()->GetRequests(base::Bind( 730 coordinator()->queue()->GetRequests(base::Bind(
656 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 731 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
657 PumpLoop(); 732 PumpLoop();
658 733
659 // Request no longer in the queue (for single attempt policy). 734 // Request no longer in the queue (for single attempt policy).
660 EXPECT_EQ(1UL, last_requests().size()); 735 EXPECT_EQ(1UL, last_requests().size());
661 // Verify foreground cancel not counted as an attempt after all. 736 // Verify foreground cancel not counted as an attempt after all.
662 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count()); 737 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count());
663 } 738 }
664 739
665 TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) { 740 TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) {
666 // Add a request to the queue, wait for callbacks to finish. 741 // Add a request to the queue, wait for callbacks to finish.
667 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, 742 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
668 base::Time::Now(), kUserRequested); 743 base::Time::Now(), kUserRequested);
669 request.MarkAttemptStarted(base::Time::Now()); 744 request.MarkAttemptStarted(base::Time::Now());
670 coordinator()->queue()->AddRequest( 745 coordinator()->queue()->AddRequest(
671 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, 746 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
672 base::Unretained(this))); 747 base::Unretained(this)));
673 PumpLoop(); 748 PumpLoop();
674 749
675 // We need to give a callback to the request. 750 // We need to give a callback to the request.
676 base::Callback<void(bool)> callback = base::Bind( 751 base::Callback<void(bool)> callback =
677 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 752 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
753 base::Unretained(this));
678 coordinator()->SetProcessingCallbackForTest(callback); 754 coordinator()->SetProcessingCallbackForTest(callback);
679 755
680 // Set up device conditions for the test. 756 // Set up device conditions for the test.
681 DeviceConditions device_conditions(false, 75, 757 DeviceConditions device_conditions(false, 75,
682 net::NetworkChangeNotifier::CONNECTION_3G); 758 net::NetworkChangeNotifier::CONNECTION_3G);
683 SetDeviceConditionsForTest(device_conditions); 759 SetDeviceConditionsForTest(device_conditions);
684 760
685 // Call the OfflinerDoneCallback to simulate the request failed, wait 761 // Call the OfflinerDoneCallback to simulate the request failed, wait
686 // for callbacks. 762 // for callbacks.
687 SendOfflinerDoneCallback(request, 763 SendOfflinerDoneCallback(request,
688 Offliner::RequestStatus::PRERENDERING_CANCELED); 764 Offliner::RequestStatus::PRERENDERING_CANCELED);
689 PumpLoop(); 765 PumpLoop();
766 EXPECT_TRUE(immediate_schedule_callback_called());
690 767
691 // Verify the request is not removed from the queue, and wait for callbacks. 768 // Verify the request is not removed from the queue, and wait for callbacks.
692 coordinator()->queue()->GetRequests(base::Bind( 769 coordinator()->queue()->GetRequests(base::Bind(
693 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 770 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
694 PumpLoop(); 771 PumpLoop();
695 772
696 // Request still in the queue. 773 // Request still in the queue.
697 EXPECT_EQ(1UL, last_requests().size()); 774 EXPECT_EQ(1UL, last_requests().size());
698 // Verify prerendering cancel not counted as an attempt after all. 775 // Verify prerendering cancel not counted as an attempt after all.
699 const std::unique_ptr<SavePageRequest>& found_request = 776 const std::unique_ptr<SavePageRequest>& found_request =
700 last_requests().front(); 777 last_requests().front();
701 EXPECT_EQ(0L, found_request->completed_attempt_count()); 778 EXPECT_EQ(0L, found_request->completed_attempt_count());
702 } 779 }
703 780
704 // If one item completes, and there are no more user requeted items left, 781 // If one item completes, and there are no more user requeted items left,
705 // we should make a scheduler entry for a non-user requested item. 782 // we should make a scheduler entry for a non-user requested item.
706 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { 783 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) {
707 // Call start processing just to set up a scheduler callback. 784 // Call start processing just to set up a scheduler callback.
708 DeviceConditions device_conditions(false, 75, 785 DeviceConditions device_conditions(false, 75,
709 net::NetworkChangeNotifier::CONNECTION_3G); 786 net::NetworkChangeNotifier::CONNECTION_3G);
710 base::Callback<void(bool)> callback = base::Bind( 787 base::Callback<void(bool)> callback =
711 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 788 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
789 base::Unretained(this));
712 coordinator()->StartProcessing(device_conditions, callback); 790 coordinator()->StartProcessing(device_conditions, callback);
713 EXPECT_TRUE(is_starting()); 791 EXPECT_TRUE(is_starting());
714 792
715 // Call RequestNotPicked, simulating a request on the disabled list. 793 // Call RequestNotPicked, simulating a request on the disabled list.
716 CallRequestNotPicked(false, true); 794 CallRequestNotPicked(false, true);
717 PumpLoop(); 795 PumpLoop();
718 796
719 EXPECT_FALSE(is_starting()); 797 EXPECT_FALSE(is_starting());
720 798
721 // The scheduler should have been called to schedule the disabled task for 799 // The scheduler should have been called to schedule the disabled task for
722 // 5 minutes from now. 800 // 5 minutes from now.
723 SchedulerStub* scheduler_stub = 801 SchedulerStub* scheduler_stub =
724 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); 802 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
725 EXPECT_TRUE(scheduler_stub->backup_schedule_called()); 803 EXPECT_TRUE(scheduler_stub->backup_schedule_called());
726 EXPECT_TRUE(scheduler_stub->unschedule_called()); 804 EXPECT_TRUE(scheduler_stub->unschedule_called());
727 } 805 }
728 806
729 // If one item completes, and there are no more user requeted items left, 807 // If one item completes, and there are no more user requeted items left,
730 // we should make a scheduler entry for a non-user requested item. 808 // we should make a scheduler entry for a non-user requested item.
731 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { 809 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {
732 // Call start processing just to set up a scheduler callback. 810 // Call start processing just to set up a scheduler callback.
733 DeviceConditions device_conditions(false, 75, 811 DeviceConditions device_conditions(false, 75,
734 net::NetworkChangeNotifier::CONNECTION_3G); 812 net::NetworkChangeNotifier::CONNECTION_3G);
735 base::Callback<void(bool)> callback = base::Bind( 813 base::Callback<void(bool)> callback =
736 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 814 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
815 base::Unretained(this));
737 coordinator()->StartProcessing(device_conditions, callback); 816 coordinator()->StartProcessing(device_conditions, callback);
738 EXPECT_TRUE(is_starting()); 817 EXPECT_TRUE(is_starting());
739 818
740 // Call RequestNotPicked, and make sure we pick schedule a task for non user 819 // Call RequestNotPicked, and make sure we pick schedule a task for non user
741 // requested conditions, with no tasks on the disabled list. 820 // requested conditions, with no tasks on the disabled list.
742 CallRequestNotPicked(true, false); 821 CallRequestNotPicked(true, false);
743 PumpLoop(); 822 PumpLoop();
744 823
745 EXPECT_FALSE(is_starting()); 824 EXPECT_FALSE(is_starting());
825 EXPECT_TRUE(immediate_schedule_callback_called());
746 826
747 // The scheduler should have been called to schedule the non-user requested 827 // The scheduler should have been called to schedule the non-user requested
748 // task. 828 // task.
749 SchedulerStub* scheduler_stub = 829 SchedulerStub* scheduler_stub =
750 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); 830 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
751 EXPECT_TRUE(scheduler_stub->schedule_called()); 831 EXPECT_TRUE(scheduler_stub->schedule_called());
752 EXPECT_TRUE(scheduler_stub->unschedule_called()); 832 EXPECT_TRUE(scheduler_stub->unschedule_called());
753 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions(); 833 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
754 EXPECT_EQ(conditions->require_power_connected, 834 EXPECT_EQ(conditions->require_power_connected,
755 coordinator()->policy()->PowerRequired(!kUserRequested)); 835 coordinator()->policy()->PowerRequired(!kUserRequested));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 coordinator()->queue()->AddRequest( 880 coordinator()->queue()->AddRequest(
801 request, 881 request,
802 base::Bind(&RequestCoordinatorTest::AddRequestDone, 882 base::Bind(&RequestCoordinatorTest::AddRequestDone,
803 base::Unretained(this))); 883 base::Unretained(this)));
804 PumpLoop(); 884 PumpLoop();
805 885
806 DeviceConditions device_conditions(false, 75, 886 DeviceConditions device_conditions(false, 75,
807 net::NetworkChangeNotifier::CONNECTION_3G); 887 net::NetworkChangeNotifier::CONNECTION_3G);
808 DisableLoading(); 888 DisableLoading();
809 base::Callback<void(bool)> callback = 889 base::Callback<void(bool)> callback =
810 base::Bind( 890 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
811 &RequestCoordinatorTest::EmptyCallbackFunction, 891 base::Unretained(this));
812 base::Unretained(this));
813 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 892 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
814 893
815 // Let the async callbacks in the request coordinator run. 894 // Let the async callbacks in the request coordinator run.
816 PumpLoop(); 895 PumpLoop();
896 EXPECT_TRUE(immediate_schedule_callback_called());
817 897
818 EXPECT_FALSE(is_starting()); 898 EXPECT_FALSE(is_starting());
819 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status()); 899 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status());
820 } 900 }
821 901
822 // This tests a StopProcessing call before we have actually started the 902 // This tests a StopProcessing call before we have actually started the
823 // prerenderer. 903 // prerenderer.
824 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { 904 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
825 // Add a request to the queue, wait for callbacks to finish. 905 // Add a request to the queue, wait for callbacks to finish.
826 offline_pages::SavePageRequest request( 906 offline_pages::SavePageRequest request(
827 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 907 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
828 coordinator()->queue()->AddRequest( 908 coordinator()->queue()->AddRequest(
829 request, 909 request,
830 base::Bind(&RequestCoordinatorTest::AddRequestDone, 910 base::Bind(&RequestCoordinatorTest::AddRequestDone,
831 base::Unretained(this))); 911 base::Unretained(this)));
832 PumpLoop(); 912 PumpLoop();
833 913
834 DeviceConditions device_conditions(false, 75, 914 DeviceConditions device_conditions(false, 75,
835 net::NetworkChangeNotifier::CONNECTION_3G); 915 net::NetworkChangeNotifier::CONNECTION_3G);
836 base::Callback<void(bool)> callback = 916 base::Callback<void(bool)> callback =
837 base::Bind( 917 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
838 &RequestCoordinatorTest::EmptyCallbackFunction, 918 base::Unretained(this));
839 base::Unretained(this));
840 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 919 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
841 EXPECT_TRUE(is_starting()); 920 EXPECT_TRUE(is_starting());
842 921
843 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. 922 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it.
844 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); 923 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED);
845 924
846 // Let the async callbacks in the request coordinator run. 925 // Let the async callbacks in the request coordinator run.
847 PumpLoop(); 926 PumpLoop();
927 EXPECT_TRUE(immediate_schedule_callback_called());
848 928
849 EXPECT_FALSE(is_starting()); 929 EXPECT_FALSE(is_starting());
850 930
851 // OfflinerDoneCallback will not end up getting called with status SAVED, 931 // OfflinerDoneCallback will not end up getting called with status SAVED,
852 // since we cancelled the event before it called offliner_->LoadAndSave(). 932 // since we cancelled the event before it called offliner_->LoadAndSave().
853 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, 933 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
854 last_offlining_status()); 934 last_offlining_status());
855 935
856 // Since offliner was not started, it will not have seen cancel call. 936 // Since offliner was not started, it will not have seen cancel call.
857 EXPECT_FALSE(OfflinerWasCanceled()); 937 EXPECT_FALSE(OfflinerWasCanceled());
858 } 938 }
859 939
860 // This tests a StopProcessing call after the prerenderer has been started. 940 // This tests a StopProcessing call after the prerenderer has been started.
861 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingLater) { 941 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingLater) {
862 // Add a request to the queue, wait for callbacks to finish. 942 // Add a request to the queue, wait for callbacks to finish.
863 offline_pages::SavePageRequest request( 943 offline_pages::SavePageRequest request(
864 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 944 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
865 coordinator()->queue()->AddRequest( 945 coordinator()->queue()->AddRequest(
866 request, 946 request,
867 base::Bind(&RequestCoordinatorTest::AddRequestDone, 947 base::Bind(&RequestCoordinatorTest::AddRequestDone,
868 base::Unretained(this))); 948 base::Unretained(this)));
869 PumpLoop(); 949 PumpLoop();
870 950
871 // Ensure the start processing request stops before the completion callback. 951 // Ensure the start processing request stops before the completion callback.
872 EnableOfflinerCallback(false); 952 EnableOfflinerCallback(false);
873 953
874 DeviceConditions device_conditions(false, 75, 954 DeviceConditions device_conditions(false, 75,
875 net::NetworkChangeNotifier::CONNECTION_3G); 955 net::NetworkChangeNotifier::CONNECTION_3G);
876 base::Callback<void(bool)> callback = 956 base::Callback<void(bool)> callback =
877 base::Bind( 957 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
878 &RequestCoordinatorTest::EmptyCallbackFunction, 958 base::Unretained(this));
879 base::Unretained(this));
880 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 959 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
881 EXPECT_TRUE(is_starting()); 960 EXPECT_TRUE(is_starting());
882 961
883 // Let all the async parts of the start processing pipeline run to completion. 962 // Let all the async parts of the start processing pipeline run to completion.
884 PumpLoop(); 963 PumpLoop();
964 // Since the offliner is disabled, this callback should not be called.
965 EXPECT_FALSE(immediate_schedule_callback_called());
885 966
886 // Coordinator should now be busy. 967 // Coordinator should now be busy.
887 EXPECT_TRUE(is_busy()); 968 EXPECT_TRUE(is_busy());
888 EXPECT_FALSE(is_starting()); 969 EXPECT_FALSE(is_starting());
889 970
890 // Now we cancel it while the prerenderer is busy. 971 // Now we cancel it while the prerenderer is busy.
891 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); 972 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED);
892 973
893 // Let the async callbacks in the cancel run. 974 // Let the async callbacks in the cancel run.
894 PumpLoop(); 975 PumpLoop();
(...skipping 18 matching lines...) Expand all
913 coordinator()->queue()->AddRequest( 994 coordinator()->queue()->AddRequest(
914 request1, base::Bind(&RequestCoordinatorTest::AddRequestDone, 995 request1, base::Bind(&RequestCoordinatorTest::AddRequestDone,
915 base::Unretained(this))); 996 base::Unretained(this)));
916 PumpLoop(); 997 PumpLoop();
917 998
918 // Ensure the start processing request stops before the completion callback. 999 // Ensure the start processing request stops before the completion callback.
919 EnableOfflinerCallback(false); 1000 EnableOfflinerCallback(false);
920 1001
921 DeviceConditions device_conditions(false, 75, 1002 DeviceConditions device_conditions(false, 75,
922 net::NetworkChangeNotifier::CONNECTION_3G); 1003 net::NetworkChangeNotifier::CONNECTION_3G);
923 base::Callback<void(bool)> callback = base::Bind( 1004 base::Callback<void(bool)> callback =
924 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 1005 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
1006 base::Unretained(this));
925 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 1007 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
926 1008
927 // Let all the async parts of the start processing pipeline run to completion. 1009 // Let all the async parts of the start processing pipeline run to completion.
928 PumpLoop(); 1010 PumpLoop();
1011 // Since the offliner is disabled, this callback should not be called.
1012 EXPECT_FALSE(immediate_schedule_callback_called());
929 1013
930 // Remove the request while it is processing. 1014 // Remove the request while it is processing.
931 std::vector<int64_t> request_ids{kRequestId1}; 1015 std::vector<int64_t> request_ids{kRequestId1};
932 coordinator()->RemoveRequests( 1016 coordinator()->RemoveRequests(
933 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, 1017 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone,
934 base::Unretained(this))); 1018 base::Unretained(this)));
935 1019
936 // Let the async callbacks in the cancel run. 1020 // Let the async callbacks in the cancel run.
937 PumpLoop(); 1021 PumpLoop();
938 1022
939 // Since offliner was started, it will have seen cancel call. 1023 // Since offliner was started, it will have seen cancel call.
940 EXPECT_TRUE(OfflinerWasCanceled()); 1024 EXPECT_TRUE(OfflinerWasCanceled());
941 } 1025 }
942 1026
943 TEST_F(RequestCoordinatorTest, MarkRequestCompleted) { 1027 TEST_F(RequestCoordinatorTest, MarkRequestCompleted) {
944 // Add a request to the queue. 1028 // Add a request to the queue.
945 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1, 1029 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1,
946 base::Time::Now(), kUserRequested); 1030 base::Time::Now(), kUserRequested);
947 int64_t request_id = coordinator()->SavePageLater( 1031 int64_t request_id = coordinator()->SavePageLater(
948 kUrl1, kClientId1, kUserRequested, 1032 kUrl1, kClientId1, kUserRequested,
949 RequestCoordinator::RequestAvailability::DISABLED_FOR_OFFLINER); 1033 RequestCoordinator::RequestAvailability::DISABLED_FOR_OFFLINER);
950 PumpLoop(); 1034 PumpLoop();
951 EXPECT_NE(request_id, 0l); 1035 EXPECT_NE(request_id, 0l);
952 1036
953 // Ensure the start processing request stops before the completion callback. 1037 // Ensure the start processing request stops before the completion callback.
954 EnableOfflinerCallback(false); 1038 EnableOfflinerCallback(false);
955 1039
956 DeviceConditions device_conditions(false, 75, 1040 DeviceConditions device_conditions(false, 75,
957 net::NetworkChangeNotifier::CONNECTION_3G); 1041 net::NetworkChangeNotifier::CONNECTION_3G);
958 base::Callback<void(bool)> callback = base::Bind( 1042 base::Callback<void(bool)> callback =
959 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 1043 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
1044 base::Unretained(this));
960 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 1045 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
961 1046
962 // Call the method under test, making sure we send SUCCESS to the observer. 1047 // Call the method under test, making sure we send SUCCESS to the observer.
963 coordinator()->MarkRequestCompleted(request_id); 1048 coordinator()->MarkRequestCompleted(request_id);
964 PumpLoop(); 1049 PumpLoop();
1050 EXPECT_TRUE(immediate_schedule_callback_called());
965 1051
966 // Our observer should have seen SUCCESS instead of REMOVED. 1052 // Our observer should have seen SUCCESS instead of REMOVED.
967 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, 1053 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS,
968 observer().last_status()); 1054 observer().last_status());
969 EXPECT_TRUE(observer().completed_called()); 1055 EXPECT_TRUE(observer().completed_called());
970 } 1056 }
971 1057
972 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { 1058 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) {
973 // Build a request to use with the pre-renderer, and put it on the queue. 1059 // Build a request to use with the pre-renderer, and put it on the queue.
974 offline_pages::SavePageRequest request( 1060 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 1354 // Now whether processing triggered immediately depends on whether test
1269 // is run on svelte device or not. 1355 // is run on svelte device or not.
1270 if (base::SysInfo::IsLowEndDevice()) { 1356 if (base::SysInfo::IsLowEndDevice()) {
1271 EXPECT_FALSE(is_busy()); 1357 EXPECT_FALSE(is_busy());
1272 } else { 1358 } else {
1273 EXPECT_TRUE(is_busy()); 1359 EXPECT_TRUE(is_busy());
1274 } 1360 }
1275 } 1361 }
1276 1362
1277 } // namespace offline_pages 1363 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698