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

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

Issue 2361883002: [Offline Pages] Adds classification of some prerender FinalStatus codes as canceled operations or a… (Closed)
Patch Set: Fixed a comment Created 4 years, 3 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // Now just one request in the queue since failed request removed 537 // Now just one request in the queue since failed request removed
538 // (for single attempt policy). 538 // (for single attempt policy).
539 EXPECT_EQ(1UL, last_requests().size()); 539 EXPECT_EQ(1UL, last_requests().size());
540 // Check that the observer got the notification that we failed (and the 540 // Check that the observer got the notification that we failed (and the
541 // subsequent notification that the request was removed). 541 // subsequent notification that the request was removed).
542 EXPECT_TRUE(observer().completed_called()); 542 EXPECT_TRUE(observer().completed_called());
543 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, 543 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED,
544 observer().last_status()); 544 observer().last_status());
545 } 545 }
546 546
547 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) {
548 // Add a request to the queue, wait for callbacks to finish.
549 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
550 base::Time::Now(), kUserRequested);
551 request.MarkAttemptStarted(base::Time::Now());
552 coordinator()->queue()->AddRequest(
553 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
554 base::Unretained(this)));
555 PumpLoop();
chili 2016/09/23 00:44:18 Just for my information... what does this do?
dougarnett 2016/09/23 18:20:01 Drives posted tasks on the task runner - eg, to ge
Pete Williamson 2016/09/27 19:25:07 To clarify a bit more, many tasks that the request
556
557 // Add second request to the queue to check handling when first fails.
558 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2,
559 base::Time::Now(), kUserRequested);
560 coordinator()->queue()->AddRequest(
561 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone,
562 base::Unretained(this)));
563 PumpLoop();
564
565 // We need to give a callback to the request.
566 base::Callback<void(bool)> callback = base::Bind(
567 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
568 coordinator()->SetProcessingCallbackForTest(callback);
569
570 // Set up device conditions for the test.
571 DeviceConditions device_conditions(false, 75,
572 net::NetworkChangeNotifier::CONNECTION_3G);
573 SetDeviceConditionsForTest(device_conditions);
574
575 // Call the OfflinerDoneCallback to simulate the request failed, wait
576 // for callbacks.
577 EnableOfflinerCallback(true);
Pete Williamson 2016/09/27 19:25:08 I don't think we want this line. As I recall, it
dougarnett 2016/09/29 01:11:23 Good catch - cleaning up the other identical cases
578 SendOfflinerDoneCallback(
579 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY);
580 PumpLoop();
581
582 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
583 // and verifying that there is as attempt to pick another request following
584 // this non-retryable failure code.
585
586 // Verify neither request is removed from the queue; wait for callbacks.
Pete Williamson 2016/09/27 19:25:07 Comment looks old and may need updating (since the
dougarnett 2016/09/29 01:11:23 Done.
587 coordinator()->queue()->GetRequests(base::Bind(
588 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
589 PumpLoop();
590
591 // Now just one request in the queue since non-retryable failure.
592 EXPECT_EQ(1UL, last_requests().size());
593 // Check that the observer got the notification that we failed (and the
594 // subsequent notification that the request was removed).
595 EXPECT_TRUE(observer().completed_called());
596 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE,
597 observer().last_status());
598 }
599
547 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { 600 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
548 // Add a request to the queue, wait for callbacks to finish. 601 // Add a request to the queue, wait for callbacks to finish.
549 offline_pages::SavePageRequest request( 602 offline_pages::SavePageRequest request(
550 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 603 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
551 request.MarkAttemptStarted(base::Time::Now()); 604 request.MarkAttemptStarted(base::Time::Now());
552 coordinator()->queue()->AddRequest( 605 coordinator()->queue()->AddRequest(
553 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, 606 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
554 base::Unretained(this))); 607 base::Unretained(this)));
555 PumpLoop(); 608 PumpLoop();
556 609
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 // Now whether processing triggered immediately depends on whether test 1110 // Now whether processing triggered immediately depends on whether test
1058 // is run on svelte device or not. 1111 // is run on svelte device or not.
1059 if (base::SysInfo::IsLowEndDevice()) { 1112 if (base::SysInfo::IsLowEndDevice()) {
1060 EXPECT_FALSE(is_busy()); 1113 EXPECT_FALSE(is_busy());
1061 } else { 1114 } else {
1062 EXPECT_TRUE(is_busy()); 1115 EXPECT_TRUE(is_busy());
1063 } 1116 }
1064 } 1117 }
1065 1118
1066 } // namespace offline_pages 1119 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698