| OLD | NEW |
| 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_picker.h" | 5 #include "components/offline_pages/background/request_picker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 void SetUp() override; | 87 void SetUp() override; |
| 88 | 88 |
| 89 void PumpLoop(); | 89 void PumpLoop(); |
| 90 | 90 |
| 91 void AddRequestDone(RequestQueue::AddRequestResult result, | 91 void AddRequestDone(RequestQueue::AddRequestResult result, |
| 92 const SavePageRequest& request); | 92 const SavePageRequest& request); |
| 93 | 93 |
| 94 void RequestPicked(const SavePageRequest& request); | 94 void RequestPicked(const SavePageRequest& request); |
| 95 | 95 |
| 96 void RequestQueueEmpty(); | 96 void RequestNotPicked(const bool non_user_requested_tasks_remaining); |
| 97 | 97 |
| 98 void QueueRequestsAndChooseOne(const SavePageRequest& request1, | 98 void QueueRequestsAndChooseOne(const SavePageRequest& request1, |
| 99 const SavePageRequest& request2); | 99 const SavePageRequest& request2); |
| 100 | 100 |
| 101 RequestNotifierStub* GetNotifier() { return notifier_.get(); } | 101 RequestNotifierStub* GetNotifier() { return notifier_.get(); } |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 // The request queue is simple enough we will use a real queue with a memory | 104 // The request queue is simple enough we will use a real queue with a memory |
| 105 // store instead of a stub. | 105 // store instead of a stub. |
| 106 std::unique_ptr<RequestQueue> queue_; | 106 std::unique_ptr<RequestQueue> queue_; |
| 107 std::unique_ptr<RequestPicker> picker_; | 107 std::unique_ptr<RequestPicker> picker_; |
| 108 std::unique_ptr<RequestNotifierStub> notifier_; | 108 std::unique_ptr<RequestNotifierStub> notifier_; |
| 109 std::unique_ptr<SavePageRequest> last_picked_; | 109 std::unique_ptr<SavePageRequest> last_picked_; |
| 110 std::unique_ptr<OfflinerPolicy> policy_; | 110 std::unique_ptr<OfflinerPolicy> policy_; |
| 111 bool request_queue_empty_called_; | 111 bool request_queue_not_picked_called_; |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 114 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 115 base::ThreadTaskRunnerHandle task_runner_handle_; | 115 base::ThreadTaskRunnerHandle task_runner_handle_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 RequestPickerTest::RequestPickerTest() | 118 RequestPickerTest::RequestPickerTest() |
| 119 : task_runner_(new base::TestSimpleTaskRunner), | 119 : task_runner_(new base::TestSimpleTaskRunner), |
| 120 task_runner_handle_(task_runner_) {} | 120 task_runner_handle_(task_runner_) {} |
| 121 | 121 |
| 122 RequestPickerTest::~RequestPickerTest() {} | 122 RequestPickerTest::~RequestPickerTest() {} |
| 123 | 123 |
| 124 void RequestPickerTest::SetUp() { | 124 void RequestPickerTest::SetUp() { |
| 125 std::unique_ptr<RequestQueueInMemoryStore> store( | 125 std::unique_ptr<RequestQueueInMemoryStore> store( |
| 126 new RequestQueueInMemoryStore()); | 126 new RequestQueueInMemoryStore()); |
| 127 queue_.reset(new RequestQueue(std::move(store))); | 127 queue_.reset(new RequestQueue(std::move(store))); |
| 128 policy_.reset(new OfflinerPolicy()); | 128 policy_.reset(new OfflinerPolicy()); |
| 129 notifier_.reset(new RequestNotifierStub()); | 129 notifier_.reset(new RequestNotifierStub()); |
| 130 picker_.reset( | 130 picker_.reset( |
| 131 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 131 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 132 request_queue_empty_called_ = false; | 132 request_queue_not_picked_called_ = false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void RequestPickerTest::PumpLoop() { | 135 void RequestPickerTest::PumpLoop() { |
| 136 task_runner_->RunUntilIdle(); | 136 task_runner_->RunUntilIdle(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void RequestPickerTest::AddRequestDone(RequestQueue::AddRequestResult result, | 139 void RequestPickerTest::AddRequestDone(RequestQueue::AddRequestResult result, |
| 140 const SavePageRequest& request) {} | 140 const SavePageRequest& request) {} |
| 141 | 141 |
| 142 void RequestPickerTest::RequestPicked(const SavePageRequest& request) { | 142 void RequestPickerTest::RequestPicked(const SavePageRequest& request) { |
| 143 last_picked_.reset(new SavePageRequest(request)); | 143 last_picked_.reset(new SavePageRequest(request)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void RequestPickerTest::RequestQueueEmpty() { | 146 void RequestPickerTest::RequestNotPicked( |
| 147 request_queue_empty_called_ = true; | 147 const bool non_user_requested_tasks_remaining) { |
| 148 request_queue_not_picked_called_ = true; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Test helper to queue the two given requests and then pick one of them per | 151 // Test helper to queue the two given requests and then pick one of them per |
| 151 // configured policy. | 152 // configured policy. |
| 152 void RequestPickerTest::QueueRequestsAndChooseOne( | 153 void RequestPickerTest::QueueRequestsAndChooseOne( |
| 153 const SavePageRequest& request1, const SavePageRequest& request2) { | 154 const SavePageRequest& request1, const SavePageRequest& request2) { |
| 154 DeviceConditions conditions; | 155 DeviceConditions conditions; |
| 155 // Add test requests on the Queue. | 156 // Add test requests on the Queue. |
| 156 queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone, | 157 queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone, |
| 157 base::Unretained(this))); | 158 base::Unretained(this))); |
| 158 queue_->AddRequest(request2, base::Bind(&RequestPickerTest::AddRequestDone, | 159 queue_->AddRequest(request2, base::Bind(&RequestPickerTest::AddRequestDone, |
| 159 base::Unretained(this))); | 160 base::Unretained(this))); |
| 160 | 161 |
| 161 // Pump the loop to give the async queue the opportunity to do the adds. | 162 // Pump the loop to give the async queue the opportunity to do the adds. |
| 162 PumpLoop(); | 163 PumpLoop(); |
| 163 | 164 |
| 164 // Call the method under test. | 165 // Call the method under test. |
| 165 picker_->ChooseNextRequest( | 166 picker_->ChooseNextRequest( |
| 166 base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), | 167 base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), |
| 167 base::Bind(&RequestPickerTest::RequestQueueEmpty, base::Unretained(this)), | 168 base::Bind(&RequestPickerTest::RequestNotPicked, base::Unretained(this)), |
| 168 &conditions); | 169 &conditions); |
| 169 | 170 |
| 170 // Pump the loop again to give the async queue the opportunity to return | 171 // Pump the loop again to give the async queue the opportunity to return |
| 171 // results from the Get operation, and for the picker to call the "picked" | 172 // results from the Get operation, and for the picker to call the "picked" |
| 172 // callback. | 173 // callback. |
| 173 PumpLoop(); | 174 PumpLoop(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 TEST_F(RequestPickerTest, PickFromEmptyQueue) { | 177 TEST_F(RequestPickerTest, PickFromEmptyQueue) { |
| 177 DeviceConditions conditions; | 178 DeviceConditions conditions; |
| 178 picker_->ChooseNextRequest( | 179 picker_->ChooseNextRequest( |
| 179 base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), | 180 base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), |
| 180 base::Bind(&RequestPickerTest::RequestQueueEmpty, base::Unretained(this)), | 181 base::Bind(&RequestPickerTest::RequestNotPicked, base::Unretained(this)), |
| 181 &conditions); | 182 &conditions); |
| 182 | 183 |
| 183 // Pump the loop again to give the async queue the opportunity to return | 184 // Pump the loop again to give the async queue the opportunity to return |
| 184 // results from the Get operation, and for the picker to call the "QueueEmpty" | 185 // results from the Get operation, and for the picker to call the "QueueEmpty" |
| 185 // callback. | 186 // callback. |
| 186 PumpLoop(); | 187 PumpLoop(); |
| 187 | 188 |
| 188 EXPECT_TRUE(request_queue_empty_called_); | 189 EXPECT_TRUE(request_queue_not_picked_called_); |
| 189 } | 190 } |
| 190 | 191 |
| 191 TEST_F(RequestPickerTest, ChooseRequestWithHigherRetryCount) { | 192 TEST_F(RequestPickerTest, ChooseRequestWithHigherRetryCount) { |
| 192 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, | 193 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, |
| 193 kPreferRetryCount, kMaxStartedTries, | 194 kPreferRetryCount, kMaxStartedTries, |
| 194 kMaxCompletedTries + 1)); | 195 kMaxCompletedTries + 1)); |
| 195 picker_.reset( | 196 picker_.reset( |
| 196 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 197 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 197 | 198 |
| 198 base::Time creation_time = base::Time::Now(); | 199 base::Time creation_time = base::Time::Now(); |
| 199 SavePageRequest request1( | 200 SavePageRequest request1( |
| 200 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested); | 201 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested); |
| 201 SavePageRequest request2( | 202 SavePageRequest request2( |
| 202 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); | 203 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); |
| 203 request2.set_completed_attempt_count(kAttemptCount); | 204 request2.set_completed_attempt_count(kAttemptCount); |
| 204 | 205 |
| 205 QueueRequestsAndChooseOne(request1, request2); | 206 QueueRequestsAndChooseOne(request1, request2); |
| 206 | 207 |
| 207 EXPECT_EQ(kRequestId2, last_picked_->request_id()); | 208 EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| 208 EXPECT_FALSE(request_queue_empty_called_); | 209 EXPECT_FALSE(request_queue_not_picked_called_); |
| 209 } | 210 } |
| 210 | 211 |
| 211 TEST_F(RequestPickerTest, ChooseRequestWithSameRetryCountButEarlier) { | 212 TEST_F(RequestPickerTest, ChooseRequestWithSameRetryCountButEarlier) { |
| 212 base::Time creation_time1 = | 213 base::Time creation_time1 = |
| 213 base::Time::Now() - base::TimeDelta::FromSeconds(10); | 214 base::Time::Now() - base::TimeDelta::FromSeconds(10); |
| 214 base::Time creation_time2 = base::Time::Now(); | 215 base::Time creation_time2 = base::Time::Now(); |
| 215 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, | 216 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, |
| 216 kUserRequested); | 217 kUserRequested); |
| 217 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, | 218 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, |
| 218 kUserRequested); | 219 kUserRequested); |
| 219 | 220 |
| 220 QueueRequestsAndChooseOne(request1, request2); | 221 QueueRequestsAndChooseOne(request1, request2); |
| 221 | 222 |
| 222 EXPECT_EQ(kRequestId1, last_picked_->request_id()); | 223 EXPECT_EQ(kRequestId1, last_picked_->request_id()); |
| 223 EXPECT_FALSE(request_queue_empty_called_); | 224 EXPECT_FALSE(request_queue_not_picked_called_); |
| 224 } | 225 } |
| 225 | 226 |
| 226 TEST_F(RequestPickerTest, ChooseEarlierRequest) { | 227 TEST_F(RequestPickerTest, ChooseEarlierRequest) { |
| 227 // We need a custom policy object prefering recency to retry count. | 228 // We need a custom policy object prefering recency to retry count. |
| 228 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, | 229 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, |
| 229 !kPreferRetryCount, kMaxStartedTries, | 230 !kPreferRetryCount, kMaxStartedTries, |
| 230 kMaxCompletedTries)); | 231 kMaxCompletedTries)); |
| 231 picker_.reset( | 232 picker_.reset( |
| 232 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 233 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 233 | 234 |
| 234 base::Time creation_time1 = | 235 base::Time creation_time1 = |
| 235 base::Time::Now() - base::TimeDelta::FromSeconds(10); | 236 base::Time::Now() - base::TimeDelta::FromSeconds(10); |
| 236 base::Time creation_time2 = base::Time::Now(); | 237 base::Time creation_time2 = base::Time::Now(); |
| 237 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, | 238 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, |
| 238 kUserRequested); | 239 kUserRequested); |
| 239 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, | 240 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, |
| 240 kUserRequested); | 241 kUserRequested); |
| 241 request2.set_completed_attempt_count(kAttemptCount); | 242 request2.set_completed_attempt_count(kAttemptCount); |
| 242 | 243 |
| 243 QueueRequestsAndChooseOne(request1, request2); | 244 QueueRequestsAndChooseOne(request1, request2); |
| 244 | 245 |
| 245 EXPECT_EQ(kRequestId1, last_picked_->request_id()); | 246 EXPECT_EQ(kRequestId1, last_picked_->request_id()); |
| 246 EXPECT_FALSE(request_queue_empty_called_); | 247 EXPECT_FALSE(request_queue_not_picked_called_); |
| 247 } | 248 } |
| 248 | 249 |
| 249 TEST_F(RequestPickerTest, ChooseSameTimeRequestWithHigherRetryCount) { | 250 TEST_F(RequestPickerTest, ChooseSameTimeRequestWithHigherRetryCount) { |
| 250 // We need a custom policy object preferring recency to retry count. | 251 // We need a custom policy object preferring recency to retry count. |
| 251 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, | 252 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, |
| 252 !kPreferRetryCount, kMaxStartedTries, | 253 !kPreferRetryCount, kMaxStartedTries, |
| 253 kMaxCompletedTries + 1)); | 254 kMaxCompletedTries + 1)); |
| 254 picker_.reset( | 255 picker_.reset( |
| 255 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 256 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 256 | 257 |
| 257 base::Time creation_time = base::Time::Now(); | 258 base::Time creation_time = base::Time::Now(); |
| 258 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, | 259 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, |
| 259 kUserRequested); | 260 kUserRequested); |
| 260 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, | 261 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, |
| 261 kUserRequested); | 262 kUserRequested); |
| 262 request2.set_completed_attempt_count(kAttemptCount); | 263 request2.set_completed_attempt_count(kAttemptCount); |
| 263 | 264 |
| 264 QueueRequestsAndChooseOne(request1, request2); | 265 QueueRequestsAndChooseOne(request1, request2); |
| 265 | 266 |
| 266 EXPECT_EQ(kRequestId2, last_picked_->request_id()); | 267 EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| 267 EXPECT_FALSE(request_queue_empty_called_); | 268 EXPECT_FALSE(request_queue_not_picked_called_); |
| 268 } | 269 } |
| 269 | 270 |
| 270 TEST_F(RequestPickerTest, ChooseRequestWithLowerRetryCount) { | 271 TEST_F(RequestPickerTest, ChooseRequestWithLowerRetryCount) { |
| 271 // We need a custom policy object preferring lower retry count. | 272 // We need a custom policy object preferring lower retry count. |
| 272 policy_.reset(new OfflinerPolicy(!kPreferUntried, kPreferEarlier, | 273 policy_.reset(new OfflinerPolicy(!kPreferUntried, kPreferEarlier, |
| 273 kPreferRetryCount, kMaxStartedTries, | 274 kPreferRetryCount, kMaxStartedTries, |
| 274 kMaxCompletedTries + 1)); | 275 kMaxCompletedTries + 1)); |
| 275 picker_.reset( | 276 picker_.reset( |
| 276 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 277 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 277 | 278 |
| 278 base::Time creation_time = base::Time::Now(); | 279 base::Time creation_time = base::Time::Now(); |
| 279 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, | 280 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, |
| 280 kUserRequested); | 281 kUserRequested); |
| 281 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, | 282 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, |
| 282 kUserRequested); | 283 kUserRequested); |
| 283 request2.set_completed_attempt_count(kAttemptCount); | 284 request2.set_completed_attempt_count(kAttemptCount); |
| 284 | 285 |
| 285 QueueRequestsAndChooseOne(request1, request2); | 286 QueueRequestsAndChooseOne(request1, request2); |
| 286 | 287 |
| 287 EXPECT_EQ(kRequestId1, last_picked_->request_id()); | 288 EXPECT_EQ(kRequestId1, last_picked_->request_id()); |
| 288 EXPECT_FALSE(request_queue_empty_called_); | 289 EXPECT_FALSE(request_queue_not_picked_called_); |
| 289 } | 290 } |
| 290 | 291 |
| 291 TEST_F(RequestPickerTest, ChooseLaterRequest) { | 292 TEST_F(RequestPickerTest, ChooseLaterRequest) { |
| 292 // We need a custom policy preferring recency over retry, and later requests. | 293 // We need a custom policy preferring recency over retry, and later requests. |
| 293 policy_.reset(new OfflinerPolicy(kPreferUntried, !kPreferEarlier, | 294 policy_.reset(new OfflinerPolicy(kPreferUntried, !kPreferEarlier, |
| 294 !kPreferRetryCount, kMaxStartedTries, | 295 !kPreferRetryCount, kMaxStartedTries, |
| 295 kMaxCompletedTries)); | 296 kMaxCompletedTries)); |
| 296 picker_.reset( | 297 picker_.reset( |
| 297 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); | 298 new RequestPicker(queue_.get(), policy_.get(), notifier_.get())); |
| 298 | 299 |
| 299 base::Time creation_time1 = | 300 base::Time creation_time1 = |
| 300 base::Time::Now() - base::TimeDelta::FromSeconds(10); | 301 base::Time::Now() - base::TimeDelta::FromSeconds(10); |
| 301 base::Time creation_time2 = base::Time::Now(); | 302 base::Time creation_time2 = base::Time::Now(); |
| 302 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, | 303 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, |
| 303 kUserRequested); | 304 kUserRequested); |
| 304 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, | 305 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, |
| 305 kUserRequested); | 306 kUserRequested); |
| 306 | 307 |
| 307 QueueRequestsAndChooseOne(request1, request2); | 308 QueueRequestsAndChooseOne(request1, request2); |
| 308 | 309 |
| 309 EXPECT_EQ(kRequestId2, last_picked_->request_id()); | 310 EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| 310 EXPECT_FALSE(request_queue_empty_called_); | 311 EXPECT_FALSE(request_queue_not_picked_called_); |
| 311 } | 312 } |
| 312 | 313 |
| 313 TEST_F(RequestPickerTest, ChooseNonExpiredRequest) { | 314 TEST_F(RequestPickerTest, ChooseNonExpiredRequest) { |
| 314 base::Time creation_time = base::Time::Now(); | 315 base::Time creation_time = base::Time::Now(); |
| 315 base::Time expired_time = | 316 base::Time expired_time = |
| 316 creation_time - base::TimeDelta::FromSeconds( | 317 creation_time - base::TimeDelta::FromSeconds( |
| 317 policy_->GetRequestExpirationTimeInSeconds() + 60); | 318 policy_->GetRequestExpirationTimeInSeconds() + 60); |
| 318 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, | 319 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, |
| 319 kUserRequested); | 320 kUserRequested); |
| 320 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, expired_time, | 321 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, expired_time, |
| 321 kUserRequested); | 322 kUserRequested); |
| 322 | 323 |
| 323 QueueRequestsAndChooseOne(request1, request2); | 324 QueueRequestsAndChooseOne(request1, request2); |
| 324 | 325 |
| 325 PumpLoop(); | 326 PumpLoop(); |
| 326 | 327 |
| 327 EXPECT_EQ(kRequestId1, last_picked_->request_id()); | 328 EXPECT_EQ(kRequestId1, last_picked_->request_id()); |
| 328 EXPECT_FALSE(request_queue_empty_called_); | 329 EXPECT_FALSE(request_queue_not_picked_called_); |
| 329 EXPECT_EQ(kRequestId2, GetNotifier()->last_expired_request().request_id()); | 330 EXPECT_EQ(kRequestId2, GetNotifier()->last_expired_request().request_id()); |
| 330 EXPECT_EQ(RequestNotifier::SavePageStatus::EXPIRED, | 331 EXPECT_EQ(RequestNotifier::SavePageStatus::EXPIRED, |
| 331 GetNotifier()->last_request_expiration_status()); | 332 GetNotifier()->last_request_expiration_status()); |
| 332 EXPECT_EQ(1, GetNotifier()->total_expired_requests()); | 333 EXPECT_EQ(1, GetNotifier()->total_expired_requests()); |
| 333 } | 334 } |
| 334 | 335 |
| 335 TEST_F(RequestPickerTest, ChooseRequestThatHasNotExceededStartLimit) { | 336 TEST_F(RequestPickerTest, ChooseRequestThatHasNotExceededStartLimit) { |
| 336 base::Time creation_time1 = | 337 base::Time creation_time1 = |
| 337 base::Time::Now() - base::TimeDelta::FromSeconds(1); | 338 base::Time::Now() - base::TimeDelta::FromSeconds(1); |
| 338 base::Time creation_time2 = base::Time::Now(); | 339 base::Time creation_time2 = base::Time::Now(); |
| 339 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, | 340 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, |
| 340 kUserRequested); | 341 kUserRequested); |
| 341 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, | 342 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, |
| 342 kUserRequested); | 343 kUserRequested); |
| 343 | 344 |
| 344 // With default policy settings, we should choose the earlier request. | 345 // With default policy settings, we should choose the earlier request. |
| 345 // However, we will make the earlier reqeust exceed the limit. | 346 // However, we will make the earlier reqeust exceed the limit. |
| 346 request1.set_started_attempt_count(policy_->GetMaxStartedTries()); | 347 request1.set_started_attempt_count(policy_->GetMaxStartedTries()); |
| 347 | 348 |
| 348 QueueRequestsAndChooseOne(request1, request2); | 349 QueueRequestsAndChooseOne(request1, request2); |
| 349 | 350 |
| 350 EXPECT_EQ(kRequestId2, last_picked_->request_id()); | 351 EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| 351 EXPECT_FALSE(request_queue_empty_called_); | 352 EXPECT_FALSE(request_queue_not_picked_called_); |
| 352 } | 353 } |
| 353 | 354 |
| 354 TEST_F(RequestPickerTest, ChooseRequestThatHasNotExceededCompletionLimit) { | 355 TEST_F(RequestPickerTest, ChooseRequestThatHasNotExceededCompletionLimit) { |
| 355 base::Time creation_time1 = | 356 base::Time creation_time1 = |
| 356 base::Time::Now() - base::TimeDelta::FromSeconds(1); | 357 base::Time::Now() - base::TimeDelta::FromSeconds(1); |
| 357 base::Time creation_time2 = base::Time::Now(); | 358 base::Time creation_time2 = base::Time::Now(); |
| 358 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, | 359 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, |
| 359 kUserRequested); | 360 kUserRequested); |
| 360 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, | 361 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, |
| 361 kUserRequested); | 362 kUserRequested); |
| 362 | 363 |
| 363 // With default policy settings, we should choose the earlier request. | 364 // With default policy settings, we should choose the earlier request. |
| 364 // However, we will make the earlier reqeust exceed the limit. | 365 // However, we will make the earlier reqeust exceed the limit. |
| 365 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries()); | 366 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries()); |
| 366 | 367 |
| 367 QueueRequestsAndChooseOne(request1, request2); | 368 QueueRequestsAndChooseOne(request1, request2); |
| 368 | 369 |
| 369 EXPECT_EQ(kRequestId2, last_picked_->request_id()); | 370 EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| 370 EXPECT_FALSE(request_queue_empty_called_); | 371 EXPECT_FALSE(request_queue_not_picked_called_); |
| 371 } | 372 } |
| 372 } // namespace offline_pages | 373 } // namespace offline_pages |
| OLD | NEW |