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

Side by Side Diff: sync/internal_api/attachments/task_queue_unittest.cc

Issue 1866243002: Convert //sync 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 "sync/internal_api/public/attachments/task_queue.h" 5 #include "sync/internal_api/public/attachments/task_queue.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 void RunLoop() { 36 void RunLoop() {
37 base::RunLoop run_loop; 37 base::RunLoop run_loop;
38 run_loop.RunUntilIdle(); 38 run_loop.RunUntilIdle();
39 } 39 }
40 40
41 void Process(const int& task) { dispatched_.push_back(task); } 41 void Process(const int& task) { dispatched_.push_back(task); }
42 42
43 base::MessageLoop message_loop_; 43 base::MessageLoop message_loop_;
44 scoped_ptr<TaskQueue<int> > queue_; 44 std::unique_ptr<TaskQueue<int>> queue_;
45 std::vector<int> dispatched_; 45 std::vector<int> dispatched_;
46 base::WeakPtrFactory<TaskQueueTest> weak_ptr_factory_; 46 base::WeakPtrFactory<TaskQueueTest> weak_ptr_factory_;
47 }; 47 };
48 48
49 // See that at most one task is dispatched at a time. 49 // See that at most one task is dispatched at a time.
50 TEST_F(TaskQueueTest, AddToQueue_NoConcurrentTasks) { 50 TEST_F(TaskQueueTest, AddToQueue_NoConcurrentTasks) {
51 queue_->AddToQueue(1); 51 queue_->AddToQueue(1);
52 queue_->AddToQueue(2); 52 queue_->AddToQueue(2);
53 RunLoop(); 53 RunLoop();
54 54
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 EXPECT_EQ(2, dispatched_.front()); 92 EXPECT_EQ(2, dispatched_.front());
93 dispatched_.clear(); 93 dispatched_.clear();
94 queue_->MarkAsSucceeded(2); 94 queue_->MarkAsSucceeded(2);
95 RunLoop(); 95 RunLoop();
96 96
97 ASSERT_TRUE(dispatched_.empty()); 97 ASSERT_TRUE(dispatched_.empty());
98 } 98 }
99 99
100 // See that Retry works as expected. 100 // See that Retry works as expected.
101 TEST_F(TaskQueueTest, Retry) { 101 TEST_F(TaskQueueTest, Retry) {
102 scoped_ptr<base::MockTimer> timer_to_pass(new base::MockTimer(false, false)); 102 std::unique_ptr<base::MockTimer> timer_to_pass(
103 new base::MockTimer(false, false));
103 base::MockTimer* mock_timer = timer_to_pass.get(); 104 base::MockTimer* mock_timer = timer_to_pass.get();
104 queue_->SetTimerForTest(std::move(timer_to_pass)); 105 queue_->SetTimerForTest(std::move(timer_to_pass));
105 106
106 // 1st attempt. 107 // 1st attempt.
107 queue_->AddToQueue(1); 108 queue_->AddToQueue(1);
108 ASSERT_TRUE(mock_timer->IsRunning()); 109 ASSERT_TRUE(mock_timer->IsRunning());
109 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay()); 110 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay());
110 TimeDelta last_delay = mock_timer->GetCurrentDelay(); 111 TimeDelta last_delay = mock_timer->GetCurrentDelay();
111 mock_timer->Fire(); 112 mock_timer->Fire();
112 RunLoop(); 113 RunLoop();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_EQ(1, dispatched_.front()); 191 EXPECT_EQ(1, dispatched_.front());
191 dispatched_.clear(); 192 dispatched_.clear();
192 queue_->Cancel(1); 193 queue_->Cancel(1);
193 RunLoop(); 194 RunLoop();
194 195
195 ASSERT_TRUE(dispatched_.empty()); 196 ASSERT_TRUE(dispatched_.empty());
196 } 197 }
197 198
198 // See that ResetBackoff resets the backoff delay. 199 // See that ResetBackoff resets the backoff delay.
199 TEST_F(TaskQueueTest, ResetBackoff) { 200 TEST_F(TaskQueueTest, ResetBackoff) {
200 scoped_ptr<base::MockTimer> timer_to_pass(new base::MockTimer(false, false)); 201 std::unique_ptr<base::MockTimer> timer_to_pass(
202 new base::MockTimer(false, false));
201 base::MockTimer* mock_timer = timer_to_pass.get(); 203 base::MockTimer* mock_timer = timer_to_pass.get();
202 queue_->SetTimerForTest(std::move(timer_to_pass)); 204 queue_->SetTimerForTest(std::move(timer_to_pass));
203 205
204 // Add an item, mark it as failed, re-add it and see that we now have a 206 // Add an item, mark it as failed, re-add it and see that we now have a
205 // backoff delay. 207 // backoff delay.
206 queue_->AddToQueue(1); 208 queue_->AddToQueue(1);
207 ASSERT_TRUE(mock_timer->IsRunning()); 209 ASSERT_TRUE(mock_timer->IsRunning());
208 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay()); 210 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay());
209 mock_timer->Fire(); 211 mock_timer->Fire();
210 RunLoop(); 212 RunLoop();
(...skipping 14 matching lines...) Expand all
225 mock_timer->Fire(); 227 mock_timer->Fire();
226 RunLoop(); 228 RunLoop();
227 ASSERT_FALSE(mock_timer->IsRunning()); 229 ASSERT_FALSE(mock_timer->IsRunning());
228 ASSERT_EQ(1U, dispatched_.size()); 230 ASSERT_EQ(1U, dispatched_.size());
229 EXPECT_EQ(1, dispatched_.front()); 231 EXPECT_EQ(1, dispatched_.front());
230 dispatched_.clear(); 232 dispatched_.clear();
231 queue_->MarkAsSucceeded(1); 233 queue_->MarkAsSucceeded(1);
232 } 234 }
233 235
234 } // namespace syncer 236 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698