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

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

Issue 2543093002: Split the RequestPicker task into two separate tasks. (Closed)
Patch Set: ADD TODO 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_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/test/scoped_feature_list.h" 18 #include "base/test/scoped_feature_list.h"
19 #include "base/test/test_mock_time_task_runner.h" 19 #include "base/test/test_mock_time_task_runner.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "components/offline_pages/background/device_conditions.h" 22 #include "components/offline_pages/background/device_conditions.h"
23 #include "components/offline_pages/background/network_quality_provider_stub.h" 23 #include "components/offline_pages/background/network_quality_provider_stub.h"
24 #include "components/offline_pages/background/offliner.h" 24 #include "components/offline_pages/background/offliner.h"
25 #include "components/offline_pages/background/offliner_factory.h" 25 #include "components/offline_pages/background/offliner_factory.h"
26 #include "components/offline_pages/background/offliner_factory_stub.h" 26 #include "components/offline_pages/background/offliner_factory_stub.h"
27 #include "components/offline_pages/background/offliner_policy.h" 27 #include "components/offline_pages/background/offliner_policy.h"
28 #include "components/offline_pages/background/offliner_stub.h" 28 #include "components/offline_pages/background/offliner_stub.h"
29 #include "components/offline_pages/background/pick_request_task_factory.h"
30 #include "components/offline_pages/background/request_queue.h" 29 #include "components/offline_pages/background/request_queue.h"
31 #include "components/offline_pages/background/request_queue_in_memory_store.h" 30 #include "components/offline_pages/background/request_queue_in_memory_store.h"
32 #include "components/offline_pages/background/save_page_request.h" 31 #include "components/offline_pages/background/save_page_request.h"
33 #include "components/offline_pages/background/scheduler.h" 32 #include "components/offline_pages/background/scheduler.h"
34 #include "components/offline_pages/background/scheduler_stub.h" 33 #include "components/offline_pages/background/scheduler_stub.h"
35 #include "components/offline_pages/offline_page_feature.h" 34 #include "components/offline_pages/offline_page_feature.h"
36 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
37 36
38 namespace offline_pages { 37 namespace offline_pages {
39 38
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 224
226 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); } 225 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); }
227 226
228 void CallRequestNotPicked(bool non_user_requested_tasks_remaining, 227 void CallRequestNotPicked(bool non_user_requested_tasks_remaining,
229 bool disabled_tasks_remaining) { 228 bool disabled_tasks_remaining) {
230 if (disabled_tasks_remaining) 229 if (disabled_tasks_remaining)
231 coordinator_->disabled_requests_.insert(kRequestId1); 230 coordinator_->disabled_requests_.insert(kRequestId1);
232 else 231 else
233 coordinator_->disabled_requests_.clear(); 232 coordinator_->disabled_requests_.clear();
234 233
235 coordinator_->RequestNotPicked(non_user_requested_tasks_remaining); 234 coordinator_->RequestNotPicked(non_user_requested_tasks_remaining, false);
236 } 235 }
237 236
238 void SetDeviceConditionsForTest(DeviceConditions device_conditions) { 237 void SetDeviceConditionsForTest(DeviceConditions device_conditions) {
239 coordinator_->SetDeviceConditionsForTest(device_conditions); 238 coordinator_->SetDeviceConditionsForTest(device_conditions);
240 } 239 }
241 240
242 void WaitForCallback() { 241 void WaitForCallback() {
243 waiter_.Wait(); 242 waiter_.Wait();
244 } 243 }
245 244
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 std::unique_ptr<RequestQueueInMemoryStore> 318 std::unique_ptr<RequestQueueInMemoryStore>
320 store(new RequestQueueInMemoryStore()); 319 store(new RequestQueueInMemoryStore());
321 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); 320 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store)));
322 std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub()); 321 std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub());
323 network_quality_estimator_.reset(new NetworkQualityProviderStub()); 322 network_quality_estimator_.reset(new NetworkQualityProviderStub());
324 coordinator_.reset(new RequestCoordinator( 323 coordinator_.reset(new RequestCoordinator(
325 std::move(policy), std::move(offliner_factory), std::move(queue), 324 std::move(policy), std::move(offliner_factory), std::move(queue),
326 std::move(scheduler_stub), network_quality_estimator_.get())); 325 std::move(scheduler_stub), network_quality_estimator_.get()));
327 coordinator_->AddObserver(&observer_); 326 coordinator_->AddObserver(&observer_);
328 SetNetworkConnected(true); 327 SetNetworkConnected(true);
329 std::unique_ptr<PickRequestTaskFactory> picker_factory(
330 new PickRequestTaskFactory(
331 coordinator_->policy(),
332 static_cast<RequestNotifier*>(coordinator_.get()),
333 coordinator_->GetLogger()));
334 coordinator_->queue()->SetPickerFactory(std::move(picker_factory));
335 immediate_callback_ = 328 immediate_callback_ =
336 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, 329 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction,
337 base::Unretained(this)); 330 base::Unretained(this));
338 // Override the normal immediate callback with a wait releasing callback. 331 // Override the normal immediate callback with a wait releasing callback.
339 waiting_callback_ = base::Bind( 332 waiting_callback_ = base::Bind(
340 &RequestCoordinatorTest::WaitingCallbackFunction, base::Unretained(this)); 333 &RequestCoordinatorTest::WaitingCallbackFunction, base::Unretained(this));
341 SetDeviceConditionsForTest(device_conditions_); 334 SetDeviceConditionsForTest(device_conditions_);
342 EnableOfflinerCallback(true); 335 EnableOfflinerCallback(true);
343 } 336 }
344 337
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 // Now whether processing triggered immediately depends on whether test 1351 // Now whether processing triggered immediately depends on whether test
1359 // is run on svelte device or not. 1352 // is run on svelte device or not.
1360 if (base::SysInfo::IsLowEndDevice()) { 1353 if (base::SysInfo::IsLowEndDevice()) {
1361 EXPECT_FALSE(is_busy()); 1354 EXPECT_FALSE(is_busy());
1362 } else { 1355 } else {
1363 EXPECT_TRUE(is_busy()); 1356 EXPECT_TRUE(is_busy());
1364 } 1357 }
1365 } 1358 }
1366 1359
1367 } // namespace offline_pages 1360 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/request_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698