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

Side by Side Diff: chrome/browser/sync_file_system/sync_process_runner_unittest.cc

Issue 1873683002: Convert //chrome/browser/sync_file_system from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/sync_file_system/sync_process_runner.h" 5 #include "chrome/browser/sync_file_system/sync_process_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9
10 #include <memory>
9 #include <queue> 11 #include <queue>
10 #include <utility> 12 #include <utility>
11 13
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace sync_file_system { 17 namespace sync_file_system {
17 18
18 namespace { 19 namespace {
19 20
20 class FakeClient : public SyncProcessRunner::Client { 21 class FakeClient : public SyncProcessRunner::Client {
21 public: 22 public:
22 FakeClient() : service_state_(SYNC_SERVICE_RUNNING) {} 23 FakeClient() : service_state_(SYNC_SERVICE_RUNNING) {}
23 ~FakeClient() override {} 24 ~FakeClient() override {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 base::TimeTicks current_time_; 76 base::TimeTicks current_time_;
76 base::TimeTicks scheduled_time_; 77 base::TimeTicks scheduled_time_;
77 base::Closure timer_task_; 78 base::Closure timer_task_;
78 79
79 DISALLOW_COPY_AND_ASSIGN(FakeTimerHelper); 80 DISALLOW_COPY_AND_ASSIGN(FakeTimerHelper);
80 }; 81 };
81 82
82 class FakeSyncProcessRunner : public SyncProcessRunner { 83 class FakeSyncProcessRunner : public SyncProcessRunner {
83 public: 84 public:
84 FakeSyncProcessRunner(SyncProcessRunner::Client* client, 85 FakeSyncProcessRunner(SyncProcessRunner::Client* client,
85 scoped_ptr<TimerHelper> timer_helper, 86 std::unique_ptr<TimerHelper> timer_helper,
86 size_t max_parallel_task) 87 size_t max_parallel_task)
87 : SyncProcessRunner("FakeSyncProcess", 88 : SyncProcessRunner("FakeSyncProcess",
88 client, 89 client,
89 std::move(timer_helper), 90 std::move(timer_helper),
90 max_parallel_task), 91 max_parallel_task),
91 max_parallel_task_(max_parallel_task) {} 92 max_parallel_task_(max_parallel_task) {}
92 93
93 void StartSync(const SyncStatusCallback& callback) override { 94 void StartSync(const SyncStatusCallback& callback) override {
94 EXPECT_LT(running_tasks_.size(), max_parallel_task_); 95 EXPECT_LT(running_tasks_.size(), max_parallel_task_);
95 running_tasks_.push(callback); 96 running_tasks_.push(callback);
(...skipping 22 matching lines...) Expand all
118 119
119 DISALLOW_COPY_AND_ASSIGN(FakeSyncProcessRunner); 120 DISALLOW_COPY_AND_ASSIGN(FakeSyncProcessRunner);
120 }; 121 };
121 122
122 } // namespace 123 } // namespace
123 124
124 TEST(SyncProcessRunnerTest, SingleTaskBasicTest) { 125 TEST(SyncProcessRunnerTest, SingleTaskBasicTest) {
125 FakeClient fake_client; 126 FakeClient fake_client;
126 FakeTimerHelper* fake_timer = new FakeTimerHelper(); 127 FakeTimerHelper* fake_timer = new FakeTimerHelper();
127 FakeSyncProcessRunner fake_runner( 128 FakeSyncProcessRunner fake_runner(
128 &fake_client, 129 &fake_client, std::unique_ptr<SyncProcessRunner::TimerHelper>(fake_timer),
129 scoped_ptr<SyncProcessRunner::TimerHelper>(fake_timer),
130 1 /* max_parallel_task */); 130 1 /* max_parallel_task */);
131 131
132 base::TimeTicks base_time = base::TimeTicks::Now(); 132 base::TimeTicks base_time = base::TimeTicks::Now();
133 fake_timer->SetCurrentTime(base_time); 133 fake_timer->SetCurrentTime(base_time);
134 134
135 // SyncProcessRunner is expected not to run a task initially. 135 // SyncProcessRunner is expected not to run a task initially.
136 EXPECT_FALSE(fake_timer->IsRunning()); 136 EXPECT_FALSE(fake_timer->IsRunning());
137 137
138 // As soon as SyncProcessRunner gets a new update, it should start running 138 // As soon as SyncProcessRunner gets a new update, it should start running
139 // the timer to run a synchronization task. 139 // the timer to run a synchronization task.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 fake_client.set_service_state(SYNC_SERVICE_AUTHENTICATION_REQUIRED); 189 fake_client.set_service_state(SYNC_SERVICE_AUTHENTICATION_REQUIRED);
190 fake_runner.UpdateChanges(100); 190 fake_runner.UpdateChanges(100);
191 EXPECT_EQ(SyncProcessRunner::kSyncDelayMaxInMilliseconds, 191 EXPECT_EQ(SyncProcessRunner::kSyncDelayMaxInMilliseconds,
192 fake_timer->GetCurrentDelay()); 192 fake_timer->GetCurrentDelay());
193 } 193 }
194 194
195 TEST(SyncProcessRunnerTest, MultiTaskBasicTest) { 195 TEST(SyncProcessRunnerTest, MultiTaskBasicTest) {
196 FakeClient fake_client; 196 FakeClient fake_client;
197 FakeTimerHelper* fake_timer = new FakeTimerHelper(); 197 FakeTimerHelper* fake_timer = new FakeTimerHelper();
198 FakeSyncProcessRunner fake_runner( 198 FakeSyncProcessRunner fake_runner(
199 &fake_client, 199 &fake_client, std::unique_ptr<SyncProcessRunner::TimerHelper>(fake_timer),
200 scoped_ptr<SyncProcessRunner::TimerHelper>(fake_timer),
201 2 /* max_parallel_task */); 200 2 /* max_parallel_task */);
202 201
203 base::TimeTicks base_time = base::TimeTicks::Now(); 202 base::TimeTicks base_time = base::TimeTicks::Now();
204 fake_timer->SetCurrentTime(base_time); 203 fake_timer->SetCurrentTime(base_time);
205 204
206 EXPECT_FALSE(fake_timer->IsRunning()); 205 EXPECT_FALSE(fake_timer->IsRunning());
207 206
208 fake_runner.UpdateChanges(100); 207 fake_runner.UpdateChanges(100);
209 EXPECT_TRUE(fake_timer->IsRunning()); 208 EXPECT_TRUE(fake_timer->IsRunning());
210 EXPECT_EQ(SyncProcessRunner::kSyncDelayFastInMilliseconds, 209 EXPECT_EQ(SyncProcessRunner::kSyncDelayFastInMilliseconds,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 262
264 // Then, following failing task should not extend throttling period. 263 // Then, following failing task should not extend throttling period.
265 fake_timer->AdvanceToScheduledTime(); 264 fake_timer->AdvanceToScheduledTime();
266 fake_client.set_service_state(SYNC_SERVICE_TEMPORARY_UNAVAILABLE); 265 fake_client.set_service_state(SYNC_SERVICE_TEMPORARY_UNAVAILABLE);
267 fake_runner.CompleteTask(SYNC_STATUS_FAILED); 266 fake_runner.CompleteTask(SYNC_STATUS_FAILED);
268 EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds, 267 EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds,
269 fake_timer->GetCurrentDelay()); 268 fake_timer->GetCurrentDelay());
270 } 269 }
271 270
272 } // namespace sync_file_system 271 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/sync_process_runner.cc ('k') | chrome/browser/sync_file_system/task_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698