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

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

Issue 2303953002: Rename an Enum to a slightly better name. (Closed)
Patch Set: Merged. 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 private: 125 private:
126 std::unique_ptr<OfflinerStub> offliner_; 126 std::unique_ptr<OfflinerStub> offliner_;
127 }; 127 };
128 128
129 class ObserverStub : public RequestCoordinator::Observer { 129 class ObserverStub : public RequestCoordinator::Observer {
130 public: 130 public:
131 ObserverStub() 131 ObserverStub()
132 : added_called_(false), 132 : added_called_(false),
133 completed_called_(false), 133 completed_called_(false),
134 changed_called_(false), 134 changed_called_(false),
135 last_status_(RequestCoordinator::SavePageStatus::SUCCESS), 135 last_status_(RequestCoordinator::BackgroundSavePageResult::SUCCESS),
136 state_(SavePageRequest::RequestState::PRERENDERING) {} 136 state_(SavePageRequest::RequestState::PRERENDERING) {}
137 137
138 void Clear() { 138 void Clear() {
139 added_called_ = false; 139 added_called_ = false;
140 completed_called_ = false; 140 completed_called_ = false;
141 changed_called_ = false; 141 changed_called_ = false;
142 state_ = SavePageRequest::RequestState::PRERENDERING; 142 state_ = SavePageRequest::RequestState::PRERENDERING;
143 last_status_ = RequestCoordinator::SavePageStatus::SUCCESS; 143 last_status_ = RequestCoordinator::BackgroundSavePageResult::SUCCESS;
144 } 144 }
145 145
146 void OnAdded(const SavePageRequest& request) override { 146 void OnAdded(const SavePageRequest& request) override {
147 added_called_ = true; 147 added_called_ = true;
148 } 148 }
149 149
150 void OnCompleted(const SavePageRequest& request, 150 void OnCompleted(
151 RequestCoordinator::SavePageStatus status) override { 151 const SavePageRequest& request,
152 RequestCoordinator::BackgroundSavePageResult status) override {
152 completed_called_ = true; 153 completed_called_ = true;
153 last_status_ = status; 154 last_status_ = status;
154 } 155 }
155 156
156 void OnChanged(const SavePageRequest& request) override { 157 void OnChanged(const SavePageRequest& request) override {
157 changed_called_ = true; 158 changed_called_ = true;
158 state_ = request.request_state(); 159 state_ = request.request_state();
159 } 160 }
160 161
161 bool added_called() { return added_called_; } 162 bool added_called() { return added_called_; }
162 bool completed_called() { return completed_called_; } 163 bool completed_called() { return completed_called_; }
163 bool changed_called() { return changed_called_; } 164 bool changed_called() { return changed_called_; }
164 RequestCoordinator::SavePageStatus last_status() { return last_status_; } 165 RequestCoordinator::BackgroundSavePageResult last_status() {
166 return last_status_;
167 }
165 SavePageRequest::RequestState state() { return state_; } 168 SavePageRequest::RequestState state() { return state_; }
166 169
167 private: 170 private:
168 bool added_called_; 171 bool added_called_;
169 bool completed_called_; 172 bool completed_called_;
170 bool changed_called_; 173 bool changed_called_;
171 RequestCoordinator::SavePageStatus last_status_; 174 RequestCoordinator::BackgroundSavePageResult last_status_;
172 SavePageRequest::RequestState state_; 175 SavePageRequest::RequestState state_;
173 }; 176 };
174 177
175 class RequestCoordinatorTest 178 class RequestCoordinatorTest
176 : public testing::Test { 179 : public testing::Test {
177 public: 180 public:
178 RequestCoordinatorTest(); 181 RequestCoordinatorTest();
179 ~RequestCoordinatorTest() override; 182 ~RequestCoordinatorTest() override;
180 183
181 void SetUp() override; 184 void SetUp() override;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 base::Unretained(this))); 443 base::Unretained(this)));
441 PumpLoop(); 444 PumpLoop();
442 445
443 // We should not find any requests in the queue anymore. 446 // We should not find any requests in the queue anymore.
444 // RequestPicker should *not* have tried to start an additional job, 447 // RequestPicker should *not* have tried to start an additional job,
445 // because the request queue is empty now. 448 // because the request queue is empty now.
446 EXPECT_EQ(0UL, last_requests().size()); 449 EXPECT_EQ(0UL, last_requests().size());
447 // Check that the observer got the notification that we succeeded, and that 450 // Check that the observer got the notification that we succeeded, and that
448 // the request got removed from the queue. 451 // the request got removed from the queue.
449 EXPECT_TRUE(observer().completed_called()); 452 EXPECT_TRUE(observer().completed_called());
450 EXPECT_EQ(RequestCoordinator::SavePageStatus::SUCCESS, 453 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS,
451 observer().last_status()); 454 observer().last_status());
452 } 455 }
453 456
454 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 457 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
455 // Add a request to the queue, wait for callbacks to finish. 458 // Add a request to the queue, wait for callbacks to finish.
456 offline_pages::SavePageRequest request( 459 offline_pages::SavePageRequest request(
457 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 460 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
458 request.MarkAttemptStarted(base::Time::Now()); 461 request.MarkAttemptStarted(base::Time::Now());
459 coordinator()->queue()->AddRequest( 462 coordinator()->queue()->AddRequest(
460 request, 463 request,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 502 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
500 base::Unretained(this))); 503 base::Unretained(this)));
501 PumpLoop(); 504 PumpLoop();
502 505
503 // Now just one request in the queue since failed request removed 506 // Now just one request in the queue since failed request removed
504 // (for single attempt policy). 507 // (for single attempt policy).
505 EXPECT_EQ(1UL, last_requests().size()); 508 EXPECT_EQ(1UL, last_requests().size());
506 // Check that the observer got the notification that we failed (and the 509 // Check that the observer got the notification that we failed (and the
507 // subsequent notification that the request was removed). 510 // subsequent notification that the request was removed).
508 EXPECT_TRUE(observer().completed_called()); 511 EXPECT_TRUE(observer().completed_called());
509 EXPECT_EQ(RequestCoordinator::SavePageStatus::RETRY_COUNT_EXCEEDED, 512 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED,
510 observer().last_status()); 513 observer().last_status());
511 } 514 }
512 515
513 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { 516 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
514 // Add a request to the queue, wait for callbacks to finish. 517 // Add a request to the queue, wait for callbacks to finish.
515 offline_pages::SavePageRequest request( 518 offline_pages::SavePageRequest request(
516 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 519 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
517 request.MarkAttemptStarted(base::Time::Now()); 520 request.MarkAttemptStarted(base::Time::Now());
518 coordinator()->queue()->AddRequest( 521 coordinator()->queue()->AddRequest(
519 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, 522 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 request_ids.push_back(kRequestId1); 934 request_ids.push_back(kRequestId1);
932 coordinator()->RemoveRequests( 935 coordinator()->RemoveRequests(
933 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, 936 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone,
934 base::Unretained(this))); 937 base::Unretained(this)));
935 938
936 PumpLoop(); 939 PumpLoop();
937 WaitForCallback(); 940 WaitForCallback();
938 PumpLoop(); 941 PumpLoop();
939 942
940 EXPECT_TRUE(observer().completed_called()); 943 EXPECT_TRUE(observer().completed_called());
941 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED, 944 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED,
942 observer().last_status()); 945 observer().last_status());
943 EXPECT_EQ(1UL, last_remove_results().size()); 946 EXPECT_EQ(1UL, last_remove_results().size());
944 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); 947 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0)));
945 } 948 }
946 949
947 TEST_F(RequestCoordinatorTest, SavePageStartsProcessingWhenConnected) { 950 TEST_F(RequestCoordinatorTest, SavePageStartsProcessingWhenConnected) {
948 SetNetworkConditionsForTest( 951 SetNetworkConditionsForTest(
949 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); 952 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
950 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 953 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested));
951 PumpLoop(); 954 PumpLoop();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); 996 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
994 997
995 // Resume the request while connected. 998 // Resume the request while connected.
996 coordinator()->ResumeRequests(request_ids); 999 coordinator()->ResumeRequests(request_ids);
997 EXPECT_FALSE(is_busy()); 1000 EXPECT_FALSE(is_busy());
998 PumpLoop(); 1001 PumpLoop();
999 EXPECT_TRUE(is_busy()); 1002 EXPECT_TRUE(is_busy());
1000 } 1003 }
1001 1004
1002 } // namespace offline_pages 1005 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/request_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698