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

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: update Created 4 years, 1 month 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TEST_F(RequestQueueTest, GetRequestsEmpty) { 191 TEST_F(RequestQueueTest, GetRequestsEmpty) {
194 queue()->GetRequests( 192 queue()->GetRequests(
195 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 193 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
196 PumpLoop(); 194 PumpLoop();
197 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 195 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
198 ASSERT_EQ(0ul, last_requests().size()); 196 ASSERT_EQ(0ul, last_requests().size());
199 } 197 }
200 198
201 TEST_F(RequestQueueTest, AddRequest) { 199 TEST_F(RequestQueueTest, AddRequest) {
202 base::Time creation_time = base::Time::Now(); 200 base::Time creation_time = base::Time::Now();
203 SavePageRequest request( 201 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
204 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 202 kUserRequested);
205 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone, 203 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone,
206 base::Unretained(this))); 204 base::Unretained(this)));
207 PumpLoop(); 205 PumpLoop();
208 ASSERT_EQ(AddRequestResult::SUCCESS, last_add_result()); 206 ASSERT_EQ(AddRequestResult::SUCCESS, last_add_result());
209 ASSERT_TRUE(last_added_request()); 207 ASSERT_TRUE(last_added_request());
210 ASSERT_EQ(kRequestId, last_added_request()->request_id()); 208 ASSERT_EQ(kRequestId, last_added_request()->request_id());
211 209
212 queue()->GetRequests( 210 queue()->GetRequests(
213 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 211 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
214 PumpLoop(); 212 PumpLoop();
215 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 213 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
216 ASSERT_EQ(1ul, last_requests().size()); 214 ASSERT_EQ(1ul, last_requests().size());
217 } 215 }
218 216
219 TEST_F(RequestQueueTest, RemoveRequest) { 217 TEST_F(RequestQueueTest, RemoveRequest) {
220 base::Time creation_time = base::Time::Now(); 218 base::Time creation_time = base::Time::Now();
221 SavePageRequest request( 219 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
222 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 220 kUserRequested);
223 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone, 221 queue()->AddRequest(request, base::Bind(&RequestQueueTest::AddRequestDone,
224 base::Unretained(this))); 222 base::Unretained(this)));
225 PumpLoop(); 223 PumpLoop();
226 ASSERT_EQ(kRequestId, last_added_request()->request_id()); 224 ASSERT_EQ(kRequestId, last_added_request()->request_id());
227 225
228 std::vector<int64_t> remove_requests{kRequestId}; 226 std::vector<int64_t> remove_requests{kRequestId};
229 queue()->RemoveRequests(remove_requests, 227 queue()->RemoveRequests(remove_requests,
230 base::Bind(&RequestQueueTest::UpdateRequestsDone, 228 base::Bind(&RequestQueueTest::UpdateRequestsDone,
231 base::Unretained(this))); 229 base::Unretained(this)));
232 PumpLoop(); 230 PumpLoop();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 353 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
356 ASSERT_EQ(1ul, last_requests().size()); 354 ASSERT_EQ(1ul, last_requests().size());
357 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE, 355 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE,
358 last_requests().at(0)->request_state()); 356 last_requests().at(0)->request_state());
359 } 357 }
360 358
361 // A longer test populating the request queue with more than one item, properly 359 // A longer test populating the request queue with more than one item, properly
362 // listing multiple items and removing the right item. 360 // listing multiple items and removing the right item.
363 TEST_F(RequestQueueTest, MultipleRequestsAddGetRemove) { 361 TEST_F(RequestQueueTest, MultipleRequestsAddGetRemove) {
364 base::Time creation_time = base::Time::Now(); 362 base::Time creation_time = base::Time::Now();
365 SavePageRequest request1( 363 SavePageRequest request1(kRequestId, kUrl, kClientId, creation_time,
366 kRequestId, kUrl, kClientId, creation_time, kUserRequested); 364 kUserRequested);
367 queue()->AddRequest(request1, base::Bind(&RequestQueueTest::AddRequestDone, 365 queue()->AddRequest(request1, base::Bind(&RequestQueueTest::AddRequestDone,
368 base::Unretained(this))); 366 base::Unretained(this)));
369 PumpLoop(); 367 PumpLoop();
370 ASSERT_EQ(request1.request_id(), last_added_request()->request_id()); 368 ASSERT_EQ(request1.request_id(), last_added_request()->request_id());
371 SavePageRequest request2( 369 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time,
372 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); 370 kUserRequested);
373 queue()->AddRequest(request2, base::Bind(&RequestQueueTest::AddRequestDone, 371 queue()->AddRequest(request2, base::Bind(&RequestQueueTest::AddRequestDone,
374 base::Unretained(this))); 372 base::Unretained(this)));
375 PumpLoop(); 373 PumpLoop();
376 ASSERT_EQ(request2.request_id(), last_added_request()->request_id()); 374 ASSERT_EQ(request2.request_id(), last_added_request()->request_id());
377 375
378 queue()->GetRequests( 376 queue()->GetRequests(
379 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 377 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
380 PumpLoop(); 378 PumpLoop();
381 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result()); 379 ASSERT_EQ(GetRequestsResult::SUCCESS, last_get_requests_result());
382 ASSERT_EQ(2ul, last_requests().size()); 380 ASSERT_EQ(2ul, last_requests().size());
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 // Doing a get should show no entries left in the queue since the expired 575 // Doing a get should show no entries left in the queue since the expired
578 // request has been removed. 576 // request has been removed.
579 queue()->GetRequests( 577 queue()->GetRequests(
580 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this))); 578 base::Bind(&RequestQueueTest::GetRequestsDone, base::Unretained(this)));
581 this->PumpLoop(); 579 this->PumpLoop();
582 ASSERT_EQ(GetRequestsResult::SUCCESS, this->last_get_requests_result()); 580 ASSERT_EQ(GetRequestsResult::SUCCESS, this->last_get_requests_result());
583 ASSERT_TRUE(this->last_requests().empty()); 581 ASSERT_TRUE(this->last_requests().empty());
584 } 582 }
585 583
586 } // namespace offline_pages 584 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698