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

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

Issue 2078113002: Don't start a second pre-render if one is in progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 4 years, 6 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
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h"
13 #include "base/test/test_simple_task_runner.h" 14 #include "base/test/test_simple_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/offline_pages/background/device_conditions.h" 16 #include "components/offline_pages/background/device_conditions.h"
16 #include "components/offline_pages/background/offliner.h" 17 #include "components/offline_pages/background/offliner.h"
17 #include "components/offline_pages/background/offliner_factory.h" 18 #include "components/offline_pages/background/offliner_factory.h"
18 #include "components/offline_pages/background/offliner_policy.h" 19 #include "components/offline_pages/background/offliner_policy.h"
19 #include "components/offline_pages/background/request_queue.h" 20 #include "components/offline_pages/background/request_queue.h"
20 #include "components/offline_pages/background/request_queue_in_memory_store.h" 21 #include "components/offline_pages/background/request_queue_in_memory_store.h"
21 #include "components/offline_pages/background/save_page_request.h" 22 #include "components/offline_pages/background/save_page_request.h"
22 #include "components/offline_pages/background/scheduler.h" 23 #include "components/offline_pages/background/scheduler.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ~RequestCoordinatorTest() override; 86 ~RequestCoordinatorTest() override;
86 87
87 void SetUp() override; 88 void SetUp() override;
88 89
89 void PumpLoop(); 90 void PumpLoop();
90 91
91 RequestCoordinator* coordinator() { 92 RequestCoordinator* coordinator() {
92 return coordinator_.get(); 93 return coordinator_.get();
93 } 94 }
94 95
96 bool request_in_progress() {
97 return coordinator_->is_busy();
98 }
99
100 void SendRequestToOffliner(SavePageRequest& request) {
101 coordinator_->SendRequestToOffliner(request);
102 }
103
95 // Empty callback function 104 // Empty callback function
96 void EmptyCallbackFunction(bool result) { 105 void EmptyCallbackFunction(bool result) {
97 } 106 }
98 107
99 // Callback for Add requests 108 // Callback for Add requests
100 void AddRequestDone(RequestQueue::AddRequestResult result, 109 void AddRequestDone(RequestQueue::AddRequestResult result,
101 const SavePageRequest& request); 110 const SavePageRequest& request);
102 111
103 // Callback for getting requests. 112 // Callback for getting requests.
104 void GetRequestsDone(RequestQueue::GetRequestsResult result, 113 void GetRequestsDone(RequestQueue::GetRequestsResult result,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { 177 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
169 DeviceConditions device_conditions(false, 75, 178 DeviceConditions device_conditions(false, 75,
170 net::NetworkChangeNotifier::CONNECTION_3G); 179 net::NetworkChangeNotifier::CONNECTION_3G);
171 base::Callback<void(bool)> callback = 180 base::Callback<void(bool)> callback =
172 base::Bind( 181 base::Bind(
173 &RequestCoordinatorTest::EmptyCallbackFunction, 182 &RequestCoordinatorTest::EmptyCallbackFunction,
174 base::Unretained(this)); 183 base::Unretained(this));
175 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 184 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
176 } 185 }
177 186
187 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
188 // Build a request.
189 offline_pages::SavePageRequest request(
190 kRequestId, kUrl, kClientId, base::Time::Now());
191 // Sending the request to the offliner should make it busy.
192 SendRequestToOffliner(request);
193 EXPECT_TRUE(request_in_progress());
dougarnett 2016/06/22 17:25:47 suggest using the is_busy() naming for the test cl
Pete Williamson 2016/06/22 22:32:27 Done.
194 // Now trying to start processing on another request should return false.
195 DeviceConditions device_conditions(false, 75,
196 net::NetworkChangeNotifier::CONNECTION_3G);
197 base::Callback<void(bool)> callback =
198 base::Bind(
199 &RequestCoordinatorTest::EmptyCallbackFunction,
200 base::Unretained(this));
201 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback));
202 }
203
178 TEST_F(RequestCoordinatorTest, SavePageLater) { 204 TEST_F(RequestCoordinatorTest, SavePageLater) {
179 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId)); 205 EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId));
180 206
181 // Expect that a request got placed on the queue. 207 // Expect that a request got placed on the queue.
182 coordinator()->queue()->GetRequests( 208 coordinator()->queue()->GetRequests(
183 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 209 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
184 base::Unretained(this))); 210 base::Unretained(this)));
185 211
186 // Wait for callbacks to finish, both request queue and offliner. 212 // Wait for callbacks to finish, both request queue and offliner.
187 PumpLoop(); 213 PumpLoop();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 284 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
259 base::Unretained(this))); 285 base::Unretained(this)));
260 PumpLoop(); 286 PumpLoop();
261 287
262 // Still one request in the queue. 288 // Still one request in the queue.
263 EXPECT_EQ(1UL, last_requests().size()); 289 EXPECT_EQ(1UL, last_requests().size());
264 // TODO(dougarnett): Verify retry count gets incremented. 290 // TODO(dougarnett): Verify retry count gets incremented.
265 } 291 }
266 292
267 } // namespace offline_pages 293 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698