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

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

Issue 2219393004: Adds an observer for the request coordinator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resumeAPI
Patch Set: Fix nits. Created 4 years, 4 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_queue_store.h" 5 #include "components/offline_pages/background/request_queue_store.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 void TearDown() override; 60 void TearDown() override;
61 61
62 void PumpLoop(); 62 void PumpLoop();
63 void ClearResults(); 63 void ClearResults();
64 64
65 // Callback used for get requests. 65 // Callback used for get requests.
66 void GetRequestsDone(bool result, 66 void GetRequestsDone(bool result,
67 const std::vector<SavePageRequest>& requests); 67 const std::vector<SavePageRequest>& requests);
68 // Callback used for add/update request. 68 // Callback used for add/update request.
69 void AddOrUpdateDone(UpdateStatus result); 69 void AddOrUpdateDone(UpdateStatus result);
70 void UpdateMultipleRequestsDone(
71 const RequestQueue::UpdateMultipleRequestResults& results,
72 const std::vector<SavePageRequest>& requests);
70 // Callback used for remove requests. 73 // Callback used for remove requests.
71 void RemoveDone(const RequestQueue::UpdateMultipleRequestResults& results); 74 void RemoveDone(const RequestQueue::UpdateMultipleRequestResults& results,
75 const std::vector<SavePageRequest>& requests);
72 // Callback used for reset. 76 // Callback used for reset.
73 void ResetDone(bool result); 77 void ResetDone(bool result);
74 78
75 LastResult last_result() const { return last_result_; } 79 LastResult last_result() const { return last_result_; }
76 UpdateStatus last_update_status() const { return last_update_status_; } 80 UpdateStatus last_update_status() const { return last_update_status_; }
81 const RequestQueue::UpdateMultipleRequestResults&
82 last_multiple_update_results() const {
83 return last_multiple_update_results_;
84 }
77 const RequestQueue::UpdateMultipleRequestResults& last_remove_results() 85 const RequestQueue::UpdateMultipleRequestResults& last_remove_results()
78 const { 86 const {
79 return last_remove_results_; 87 return last_remove_results_;
80 } 88 }
81 const std::vector<SavePageRequest>& last_requests() const { 89 const std::vector<SavePageRequest>& last_requests() const {
82 return last_requests_; 90 return last_requests_;
83 } 91 }
84 92
85 protected: 93 protected:
86 base::ScopedTempDir temp_directory_; 94 base::ScopedTempDir temp_directory_;
87 95
88 private: 96 private:
89 LastResult last_result_; 97 LastResult last_result_;
90 UpdateStatus last_update_status_; 98 UpdateStatus last_update_status_;
99 RequestQueue::UpdateMultipleRequestResults last_multiple_update_results_;
91 RequestQueue::UpdateMultipleRequestResults last_remove_results_; 100 RequestQueue::UpdateMultipleRequestResults last_remove_results_;
92 std::vector<SavePageRequest> last_requests_; 101 std::vector<SavePageRequest> last_requests_;
93 102
94 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 103 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
95 base::ThreadTaskRunnerHandle task_runner_handle_; 104 base::ThreadTaskRunnerHandle task_runner_handle_;
96 }; 105 };
97 106
98 RequestQueueStoreTestBase::RequestQueueStoreTestBase() 107 RequestQueueStoreTestBase::RequestQueueStoreTestBase()
99 : last_result_(LastResult::kNone), 108 : last_result_(LastResult::kNone),
100 last_update_status_(UpdateStatus::FAILED), 109 last_update_status_(UpdateStatus::FAILED),
(...skipping 22 matching lines...) Expand all
123 bool result, 132 bool result,
124 const std::vector<SavePageRequest>& requests) { 133 const std::vector<SavePageRequest>& requests) {
125 last_result_ = result ? LastResult::kTrue : LastResult::kFalse; 134 last_result_ = result ? LastResult::kTrue : LastResult::kFalse;
126 last_requests_ = requests; 135 last_requests_ = requests;
127 } 136 }
128 137
129 void RequestQueueStoreTestBase::AddOrUpdateDone(UpdateStatus status) { 138 void RequestQueueStoreTestBase::AddOrUpdateDone(UpdateStatus status) {
130 last_update_status_ = status; 139 last_update_status_ = status;
131 } 140 }
132 141
142 void RequestQueueStoreTestBase::UpdateMultipleRequestsDone(
143 const RequestQueue::UpdateMultipleRequestResults& results,
144 const std::vector<SavePageRequest>& requests) {
145 last_multiple_update_results_ = results;
146 last_requests_ = requests;
147 }
148
133 void RequestQueueStoreTestBase::RemoveDone( 149 void RequestQueueStoreTestBase::RemoveDone(
134 const RequestQueue::UpdateMultipleRequestResults& results) { 150 const RequestQueue::UpdateMultipleRequestResults& results,
151 const std::vector<SavePageRequest>& requests) {
135 last_remove_results_ = results; 152 last_remove_results_ = results;
153 last_requests_ = requests;
136 } 154 }
137 155
138 void RequestQueueStoreTestBase::ResetDone(bool result) { 156 void RequestQueueStoreTestBase::ResetDone(bool result) {
139 last_result_ = result ? LastResult::kTrue : LastResult::kFalse; 157 last_result_ = result ? LastResult::kTrue : LastResult::kFalse;
140 } 158 }
141 159
142 // Defines interface for the store factory. 160 // Defines interface for the store factory.
143 class RequestQueueStoreFactory { 161 class RequestQueueStoreFactory {
144 public: 162 public:
145 virtual RequestQueueStore* BuildStore(const base::FilePath& path) = 0; 163 virtual RequestQueueStore* BuildStore(const base::FilePath& path) = 0;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 store->RemoveRequests(request_ids, 298 store->RemoveRequests(request_ids,
281 base::Bind(&RequestQueueStoreTestBase::RemoveDone, 299 base::Bind(&RequestQueueStoreTestBase::RemoveDone,
282 base::Unretained(this))); 300 base::Unretained(this)));
283 ASSERT_EQ(0ul, this->last_remove_results().size()); 301 ASSERT_EQ(0ul, this->last_remove_results().size());
284 this->PumpLoop(); 302 this->PumpLoop();
285 ASSERT_EQ(2ul, this->last_remove_results().size()); 303 ASSERT_EQ(2ul, this->last_remove_results().size());
286 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS, 304 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS,
287 this->last_remove_results().at(0).second); 305 this->last_remove_results().at(0).second);
288 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS, 306 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS,
289 this->last_remove_results().at(1).second); 307 this->last_remove_results().at(1).second);
308 ASSERT_EQ(kRequestId, this->last_requests().at(0).request_id());
290 this->ClearResults(); 309 this->ClearResults();
291 310
292 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone, 311 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone,
293 base::Unretained(this))); 312 base::Unretained(this)));
294 this->PumpLoop(); 313 this->PumpLoop();
295 ASSERT_EQ(LastResult::kTrue, this->last_result()); 314 ASSERT_EQ(LastResult::kTrue, this->last_result());
296 ASSERT_TRUE(this->last_requests().empty()); 315 ASSERT_TRUE(this->last_requests().empty());
297 this->ClearResults(); 316 this->ClearResults();
298 317
299 // Try to remove a request that is not in the queue. 318 // Try to remove a request that is not in the queue.
(...skipping 22 matching lines...) Expand all
322 store->AddOrUpdateRequest( 341 store->AddOrUpdateRequest(
323 request1, base::Bind(&RequestQueueStoreTestBase::AddOrUpdateDone, 342 request1, base::Bind(&RequestQueueStoreTestBase::AddOrUpdateDone,
324 base::Unretained(this))); 343 base::Unretained(this)));
325 this->PumpLoop(); 344 this->PumpLoop();
326 this->ClearResults(); 345 this->ClearResults();
327 346
328 // Pause a request. 347 // Pause a request.
329 std::vector<int64_t> request_ids{kRequestId}; 348 std::vector<int64_t> request_ids{kRequestId};
330 store->ChangeRequestsState( 349 store->ChangeRequestsState(
331 request_ids, SavePageRequest::RequestState::PAUSED, 350 request_ids, SavePageRequest::RequestState::PAUSED,
332 base::Bind(&RequestQueueStoreTestBase::AddOrUpdateDone, 351 base::Bind(&RequestQueueStoreTestBase::UpdateMultipleRequestsDone,
333 base::Unretained(this))); 352 base::Unretained(this)));
334 ASSERT_EQ(LastResult::kNone, this->last_result()); 353 ASSERT_EQ(LastResult::kNone, this->last_result());
335 this->PumpLoop(); 354 this->PumpLoop();
336 355
337 // Verify pause succeeded 356 // Verify pause succeeded
338 ASSERT_EQ(UpdateStatus::UPDATED, this->last_update_status()); 357 ASSERT_EQ(1ul, this->last_multiple_update_results().size());
358 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS,
359 this->last_multiple_update_results().at(0).second);
360 ASSERT_EQ(kRequestId, this->last_requests().at(0).request_id());
339 this->ClearResults(); 361 this->ClearResults();
340 362
341 // Get the request from the queue to check it out 363 // Get the request from the queue to check it out
342 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone, 364 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone,
343 base::Unretained(this))); 365 base::Unretained(this)));
344 this->PumpLoop(); 366 this->PumpLoop();
345 ASSERT_EQ(LastResult::kTrue, this->last_result()); 367 ASSERT_EQ(LastResult::kTrue, this->last_result());
346 // The request should still be in the queue. 368 // The request should still be in the queue.
347 ASSERT_EQ(1UL, this->last_requests().size()); 369 ASSERT_EQ(1UL, this->last_requests().size());
348 // Request 1 should be paused. 370 // Request 1 should be paused.
349 ASSERT_EQ(SavePageRequest::RequestState::PAUSED, 371 ASSERT_EQ(SavePageRequest::RequestState::PAUSED,
350 this->last_requests().at(0).request_state()); 372 this->last_requests().at(0).request_state());
351 this->ClearResults(); 373 this->ClearResults();
352 374
353 // Now resume the same request we paused. 375 // Now resume the same request we paused.
354 store->ChangeRequestsState( 376 store->ChangeRequestsState(
355 request_ids, SavePageRequest::RequestState::AVAILABLE, 377 request_ids, SavePageRequest::RequestState::AVAILABLE,
356 base::Bind(&RequestQueueStoreTestBase::AddOrUpdateDone, 378 base::Bind(&RequestQueueStoreTestBase::UpdateMultipleRequestsDone,
357 base::Unretained(this))); 379 base::Unretained(this)));
358 ASSERT_EQ(LastResult::kNone, this->last_result()); 380 ASSERT_EQ(LastResult::kNone, this->last_result());
359 this->PumpLoop(); 381 this->PumpLoop();
360 382
361 // Verify resume succeeded. 383 // Verify resume succeeded.
362 ASSERT_EQ(UpdateStatus::UPDATED, this->last_update_status()); 384 ASSERT_EQ(1ul, this->last_multiple_update_results().size());
385 ASSERT_EQ(RequestQueue::UpdateRequestResult::SUCCESS,
386 this->last_multiple_update_results().at(0).second);
387 ASSERT_EQ(kRequestId, this->last_requests().at(0).request_id());
363 this->ClearResults(); 388 this->ClearResults();
364 389
365 // Get the request from the queue to check it out 390 // Get the request from the queue to check it out
366 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone, 391 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone,
367 base::Unretained(this))); 392 base::Unretained(this)));
368 this->PumpLoop(); 393 this->PumpLoop();
369 ASSERT_EQ(LastResult::kTrue, this->last_result()); 394 ASSERT_EQ(LastResult::kTrue, this->last_result());
370 // The request should still be in the queue. 395 // The request should still be in the queue.
371 ASSERT_EQ(1UL, this->last_requests().size()); 396 ASSERT_EQ(1UL, this->last_requests().size());
372 // Request 1 should be paused. 397 // Request 1 should be paused.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone, 448 store->GetRequests(base::Bind(&RequestQueueStoreTestBase::GetRequestsDone,
424 base::Unretained(this))); 449 base::Unretained(this)));
425 ASSERT_EQ(LastResult::kNone, this->last_result()); 450 ASSERT_EQ(LastResult::kNone, this->last_result());
426 this->PumpLoop(); 451 this->PumpLoop();
427 ASSERT_EQ(LastResult::kTrue, this->last_result()); 452 ASSERT_EQ(LastResult::kTrue, this->last_result());
428 ASSERT_EQ(1ul, this->last_requests().size()); 453 ASSERT_EQ(1ul, this->last_requests().size());
429 ASSERT_TRUE(original_request == this->last_requests()[0]); 454 ASSERT_TRUE(original_request == this->last_requests()[0]);
430 } 455 }
431 456
432 } // offline_pages 457 } // offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698