| OLD | NEW |
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 // Updating the timer used for heartbeats after starting should restart the | 184 // Updating the timer used for heartbeats after starting should restart the |
| 185 // timer but not increase the heartbeat time by more than a millisecond. | 185 // timer but not increase the heartbeat time by more than a millisecond. |
| 186 TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) { | 186 TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) { |
| 187 StartManager(); | 187 StartManager(); |
| 188 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime(); | 188 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime(); |
| 189 | 189 |
| 190 manager()->UpdateHeartbeatTimer( | 190 manager()->UpdateHeartbeatTimer( |
| 191 make_scoped_ptr(new base::Timer(true, false))); | 191 make_scoped_ptr(new base::Timer(true, false))); |
| 192 EXPECT_LT(manager()->GetNextHeartbeatTime() - heartbeat, | 192 EXPECT_LT(manager()->GetNextHeartbeatTime() - heartbeat, |
| 193 base::TimeDelta::FromMilliseconds(1)); | 193 base::TimeDelta::FromMilliseconds(5)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Stopping the manager should reset the heartbeat timer. | 196 // Stopping the manager should reset the heartbeat timer. |
| 197 TEST_F(HeartbeatManagerTest, Stop) { | 197 TEST_F(HeartbeatManagerTest, Stop) { |
| 198 StartManager(); | 198 StartManager(); |
| 199 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); | 199 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); |
| 200 | 200 |
| 201 manager()->Stop(); | 201 manager()->Stop(); |
| 202 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); | 202 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Simulate missing a heartbeat by manually invoking the check method. The | 205 // Simulate missing a heartbeat by manually invoking the check method. The |
| 206 // heartbeat should only be triggered once, and only if the heartbeat timer | 206 // heartbeat should only be triggered once, and only if the heartbeat timer |
| 207 // is running. Because the period is several minutes, none should fire. | 207 // is running. Because the period is several minutes, none should fire. |
| 208 TEST_F(HeartbeatManagerTest, MissedHeartbeat) { | 208 TEST_F(HeartbeatManagerTest, MissedHeartbeat) { |
| 209 // Do nothing while stopped. | 209 // Do nothing while stopped. |
| 210 manager()->TriggerMissedHeartbeatCheck(); | 210 manager()->TriggerMissedHeartbeatCheck(); |
| 211 StartManager(); | 211 StartManager(); |
| 212 EXPECT_EQ(0, heartbeats_sent()); | 212 EXPECT_EQ(0, heartbeats_sent()); |
| 213 | 213 |
| 214 // Do nothing before the period is reached. | 214 // Do nothing before the period is reached. |
| 215 manager()->TriggerMissedHeartbeatCheck(); | 215 manager()->TriggerMissedHeartbeatCheck(); |
| 216 EXPECT_EQ(0, heartbeats_sent()); | 216 EXPECT_EQ(0, heartbeats_sent()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace | 219 } // namespace |
| 220 | 220 |
| 221 } // namespace gcm | 221 } // namespace gcm |
| OLD | NEW |