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

Side by Side Diff: google_apis/gcm/engine/heartbeat_manager_unittest.cc

Issue 1873663002: Convert //google_apis 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 "google_apis/gcm/engine/heartbeat_manager.h" 5 #include "google_apis/gcm/engine/heartbeat_manager.h"
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/ptr_util.h"
10 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
14 #include "google_apis/gcm/protocol/mcs.pb.h" 16 #include "google_apis/gcm/protocol/mcs.pb.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace gcm { 19 namespace gcm {
18 20
19 namespace { 21 namespace {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 int reconnects_triggered() const { return reconnects_triggered_; } 56 int reconnects_triggered() const { return reconnects_triggered_; }
55 57
56 // Starts the heartbeat manager. 58 // Starts the heartbeat manager.
57 void StartManager(); 59 void StartManager();
58 60
59 private: 61 private:
60 // Helper functions for verifying heartbeat manager effects. 62 // Helper functions for verifying heartbeat manager effects.
61 void SendHeartbeatClosure(); 63 void SendHeartbeatClosure();
62 void TriggerReconnectClosure(ConnectionFactory::ConnectionResetReason reason); 64 void TriggerReconnectClosure(ConnectionFactory::ConnectionResetReason reason);
63 65
64 scoped_ptr<TestHeartbeatManager> manager_; 66 std::unique_ptr<TestHeartbeatManager> manager_;
65 67
66 int heartbeats_sent_; 68 int heartbeats_sent_;
67 int reconnects_triggered_; 69 int reconnects_triggered_;
68 70
69 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 71 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
70 base::ThreadTaskRunnerHandle task_runner_handle_; 72 base::ThreadTaskRunnerHandle task_runner_handle_;
71 }; 73 };
72 74
73 HeartbeatManagerTest::HeartbeatManagerTest() 75 HeartbeatManagerTest::HeartbeatManagerTest()
74 : manager_(new TestHeartbeatManager()), 76 : manager_(new TestHeartbeatManager()),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 177
176 EXPECT_LE(manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(), 178 EXPECT_LE(manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(),
177 base::TimeDelta::FromMilliseconds(kIntervalMs)); 179 base::TimeDelta::FromMilliseconds(kIntervalMs));
178 EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime()); 180 EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime());
179 } 181 }
180 182
181 // Updating the timer used for heartbeats before starting should not start the 183 // Updating the timer used for heartbeats before starting should not start the
182 // timer. 184 // timer.
183 TEST_F(HeartbeatManagerTest, UpdateTimerBeforeStart) { 185 TEST_F(HeartbeatManagerTest, UpdateTimerBeforeStart) {
184 manager()->UpdateHeartbeatTimer( 186 manager()->UpdateHeartbeatTimer(
185 make_scoped_ptr(new base::Timer(true, false))); 187 base::WrapUnique(new base::Timer(true, false)));
186 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); 188 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null());
187 } 189 }
188 190
189 // Updating the timer used for heartbeats after starting should restart the 191 // Updating the timer used for heartbeats after starting should restart the
190 // timer but not increase the heartbeat time by more than a millisecond. 192 // timer but not increase the heartbeat time by more than a millisecond.
191 TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) { 193 TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) {
192 StartManager(); 194 StartManager();
193 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime(); 195 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime();
194 196
195 manager()->UpdateHeartbeatTimer( 197 manager()->UpdateHeartbeatTimer(
196 make_scoped_ptr(new base::Timer(true, false))); 198 base::WrapUnique(new base::Timer(true, false)));
197 EXPECT_LT(manager()->GetNextHeartbeatTime() - heartbeat, 199 EXPECT_LT(manager()->GetNextHeartbeatTime() - heartbeat,
198 base::TimeDelta::FromMilliseconds(5)); 200 base::TimeDelta::FromMilliseconds(5));
199 } 201 }
200 202
201 // Stopping the manager should reset the heartbeat timer. 203 // Stopping the manager should reset the heartbeat timer.
202 TEST_F(HeartbeatManagerTest, Stop) { 204 TEST_F(HeartbeatManagerTest, Stop) {
203 StartManager(); 205 StartManager();
204 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); 206 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now());
205 207
206 manager()->Stop(); 208 manager()->Stop();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 heartbeat = manager()->GetNextHeartbeatTime(); 308 heartbeat = manager()->GetNextHeartbeatTime();
307 EXPECT_GT(heartbeat - base::TimeTicks::Now(), 309 EXPECT_GT(heartbeat - base::TimeTicks::Now(),
308 base::TimeDelta::FromMilliseconds(kDefaultAckIntervalMs)); 310 base::TimeDelta::FromMilliseconds(kDefaultAckIntervalMs));
309 EXPECT_LE(heartbeat - base::TimeTicks::Now(), 311 EXPECT_LE(heartbeat - base::TimeTicks::Now(),
310 base::TimeDelta::FromMilliseconds(kCustomIntervalMs)); 312 base::TimeDelta::FromMilliseconds(kCustomIntervalMs));
311 } 313 }
312 314
313 } // namespace 315 } // namespace
314 316
315 } // namespace gcm 317 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698