| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "google_apis/gcm/protocol/mcs.pb.h" | 13 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace gcm { | 16 namespace gcm { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 mcs_proto::HeartbeatConfig BuildHeartbeatConfig(int interval_ms) { | 20 mcs_proto::HeartbeatConfig BuildHeartbeatConfig(int interval_ms) { |
| 21 mcs_proto::HeartbeatConfig config; | 21 mcs_proto::HeartbeatConfig config; |
| 22 config.set_interval_ms(interval_ms); | 22 config.set_interval_ms(interval_ms); |
| 23 return config; | 23 return config; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class TestHeartbeatManager : public HeartbeatManager { | 26 class TestHeartbeatManager : public HeartbeatManager { |
| 27 public: | 27 public: |
| 28 TestHeartbeatManager() {} | 28 TestHeartbeatManager() {} |
| 29 virtual ~TestHeartbeatManager() {} | 29 ~TestHeartbeatManager() override {} |
| 30 | 30 |
| 31 // Bypass the heartbeat timer, and send the heartbeat now. | 31 // Bypass the heartbeat timer, and send the heartbeat now. |
| 32 void TriggerHearbeat(); | 32 void TriggerHearbeat(); |
| 33 | 33 |
| 34 // Check for a missed heartbeat now. | 34 // Check for a missed heartbeat now. |
| 35 void TriggerMissedHeartbeatCheck(); | 35 void TriggerMissedHeartbeatCheck(); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 void TestHeartbeatManager::TriggerHearbeat() { | 38 void TestHeartbeatManager::TriggerHearbeat() { |
| 39 OnHeartbeatTriggered(); | 39 OnHeartbeatTriggered(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |