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

Side by Side Diff: components/offline_pages/core/background/request_queue_unittest.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years 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.h" 5 #include "components/offline_pages/core/background/request_queue.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/test/test_simple_task_runner.h" 11 #include "base/test/test_simple_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/offline_pages/background/device_conditions.h" 13 #include "components/offline_pages/core/background/device_conditions.h"
14 #include "components/offline_pages/background/offliner_policy.h" 14 #include "components/offline_pages/core/background/offliner_policy.h"
15 #include "components/offline_pages/background/request_coordinator.h" 15 #include "components/offline_pages/core/background/request_coordinator.h"
16 #include "components/offline_pages/background/request_coordinator_event_logger.h " 16 #include "components/offline_pages/core/background/request_coordinator_event_log ger.h"
17 #include "components/offline_pages/background/request_notifier.h" 17 #include "components/offline_pages/core/background/request_notifier.h"
18 #include "components/offline_pages/background/request_queue_in_memory_store.h" 18 #include "components/offline_pages/core/background/request_queue_in_memory_store .h"
19 #include "components/offline_pages/background/save_page_request.h" 19 #include "components/offline_pages/core/background/save_page_request.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace offline_pages { 22 namespace offline_pages {
23 23
24 using AddRequestResult = AddRequestResult; 24 using AddRequestResult = AddRequestResult;
25 using GetRequestsResult = GetRequestsResult; 25 using GetRequestsResult = GetRequestsResult;
26 using UpdateRequestResult = UpdateRequestResult; 26 using UpdateRequestResult = UpdateRequestResult;
27 27
28 namespace { 28 namespace {
29 // Data for request 1. 29 // Data for request 1.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 std::vector<std::unique_ptr<SavePageRequest>> requests); 98 std::vector<std::unique_ptr<SavePageRequest>> requests);
99 99
100 void UpdateRequestDone(UpdateRequestResult result); 100 void UpdateRequestDone(UpdateRequestResult result);
101 void UpdateRequestsDone(std::unique_ptr<UpdateRequestsResult> result); 101 void UpdateRequestsDone(std::unique_ptr<UpdateRequestsResult> result);
102 102
103 void ClearResults(); 103 void ClearResults();
104 104
105 RequestQueue* queue() { return queue_.get(); } 105 RequestQueue* queue() { return queue_.get(); }
106 106
107 AddRequestResult last_add_result() const { return last_add_result_; } 107 AddRequestResult last_add_result() const { return last_add_result_; }
108 SavePageRequest* last_added_request() { 108 SavePageRequest* last_added_request() { return last_added_request_.get(); }
109 return last_added_request_.get();
110 }
111 109
112 UpdateRequestResult last_update_result() const { return last_update_result_; } 110 UpdateRequestResult last_update_result() const { return last_update_result_; }
113 111
114 GetRequestsResult last_get_requests_result() const { 112 GetRequestsResult last_get_requests_result() const {
115 return last_get_requests_result_; 113 return last_get_requests_result_;
116 } 114 }
117 115
118 const std::vector<std::unique_ptr<SavePageRequest>>& last_requests() const { 116 const std::vector<std::unique_ptr<SavePageRequest>>& last_requests() const {
119 return last_requests_; 117 return last_requests_;
120 } 118 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 TEST_F(RequestQueueTest, GetRequestsEmpty) { 192 TEST_F(RequestQueueTest, GetRequestsEmpty) {
195 queue()->GetRequests( 193 queue()->GetRequests(
196 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 194 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
197 PumpLoop(); 195 PumpLoop();
198 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 196 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
199 ASSERT_EQ(0ul, last_requests().size()); 197 ASSERT_EQ(0ul, last_requests().size());
200 } 198 }
201 199
202 TEST_F(RequestQueueTest, AddRequest) { 200 TEST_F(RequestQueueTest, AddRequest) {
203 base::Time creation_time = base::Time::Now(); 201 base::Time creation_time = base::Time::Now();
204 SavePageRequest request( 202 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
205 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 203 kUserRequested);
206 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone, 204 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone,
207 base::Unretained(this))); 205 base::Unretained(this)));
208 PumpLoop(); 206 PumpLoop();
209 ASSERT_EQ(AddRequestResult::SUCCESS, last_add_result()); 207 ASSERT_EQ(AddRequestResult::SUCCESS, last_add_result());
210 ASSERT_TRUE(last_added_request()); 208 ASSERT_TRUE(last_added_request());
211 ASSERT_EQ(kRequestId, last_added_request()->request_id()); 209 ASSERT_EQ(kRequestId, last_added_request()->request_id());
212 210
213 queue()->GetRequests( 211 queue()->GetRequests(
214 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 212 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
215 PumpLoop(); 213 PumpLoop();
216 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 214 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
217 ASSERT_EQ(1ul, last_requests().size()); 215 ASSERT_EQ(1ul, last_requests().size());
218 } 216 }
219 217
220 TEST_F(RequestQueueTest, RemoveRequest) { 218 TEST_F(RequestQueueTest, RemoveRequest) {
221 base::Time creation_time = base::Time::Now(); 219 base::Time creation_time = base::Time::Now();
222 SavePageRequest request( 220 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
223 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 221 kUserRequested);
224 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone, 222 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone,
225 base::Unretained(this))); 223 base::Unretained(this)));
226 PumpLoop(); 224 PumpLoop();
227 ASSERT_EQ(kRequestId, last_added_request()->request_id()); 225 ASSERT_EQ(kRequestId, last_added_request()->request_id());
228 226
229 std::vector<int64_t> remove_requests{kRequestId}; 227 std::vector<int64_t> remove_requests{kRequestId};
230 queue()->RemoveRequests(remove_requests, 228 queue()->RemoveRequests(remove_requests,
231 base::Bind(&RequestQueueTest::UpdateRequestsDone, 229 base::Bind(&RequestQueueTest::UpdateRequestsDone,
232 base::Unretained(this))); 230 base::Unretained(this)));
233 PumpLoop(); 231 PumpLoop();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 354 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
357 ASSERT_EQ(1ul, last_requests().size()); 355 ASSERT_EQ(1ul, last_requests().size());
358 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE, 356 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE,
359 last_requests().at(0)->request_state()); 357 last_requests().at(0)->request_state());
360 } 358 }
361 359
362 // A longer test populating the request queue with more than one item, properly 360 // A longer test populating the request queue with more than one item, properly
363 // listing multiple items and removing the right item. 361 // listing multiple items and removing the right item.
364 TEST_F(RequestQueueTest, MultipleRequestsAddGetRemove) { 362 TEST_F(RequestQueueTest, MultipleRequestsAddGetRemove) {
365 base::Time creation_time = base::Time::Now(); 363 base::Time creation_time = base::Time::Now();
366 SavePageRequest request1( 364 SavePageRequest request1(kRequestId, kUrl, kClientId, creation_time,
367 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 365 kUserRequested);
368 queue()->AddRequest(request1, base::Bind(&RequestQueueTest::AddRequestDone, 366 queue()->AddRequest(request1, base::Bind(&RequestQueueTest::AddRequestDone,
369 base::Unretained(this))); 367 base::Unretained(this)));
370 PumpLoop(); 368 PumpLoop();
371 ASSERT_EQ(request1.request_id(), last_added_request()->request_id()); 369 ASSERT_EQ(request1.request_id(), last_added_request()->request_id());
372 SavePageRequest request2( 370 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time,
373 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); 371 kUserRequested);
374 queue()->AddRequest(request2, base::Bind(&RequestQueueTest::AddRequestDone, 372 queue()->AddRequest(request2, base::Bind(&RequestQueueTest::AddRequestDone,
375 base::Unretained(this))); 373 base::Unretained(this)));
376 PumpLoop(); 374 PumpLoop();
377 ASSERT_EQ(request2.request_id(), last_added_request()->request_id()); 375 ASSERT_EQ(request2.request_id(), last_added_request()->request_id());
378 376
379 queue()->GetRequests( 377 queue()->GetRequests(
380 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 378 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
381 PumpLoop(); 379 PumpLoop();
382 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 380 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
383 ASSERT_EQ(2ul, last_requests().size()); 381 ASSERT_EQ(2ul, last_requests().size());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // Doing a get should show no entries left in the queue since the expired 569 // Doing a get should show no entries left in the queue since the expired
572 // request has been removed. 570 // request has been removed.
573 queue()->GetRequests( 571 queue()->GetRequests(
574 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 572 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
575 this->PumpLoop(); 573 this->PumpLoop();
576 ASSERT_EQ(GetRequestsResult::SUCCESS, this->last_get_requests_result()); 574 ASSERT_EQ(GetRequestsResult::SUCCESS, this->last_get_requests_result());
577 ASSERT_TRUE(this->last_requests().empty()); 575 ASSERT_TRUE(this->last_requests().empty());
578 } 576 }
579 577
580 } // namespace offline_pages 578 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698