| 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" |
| 8 #include "base/bind_helpers.h" |
| 7 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 8 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/timer/timer.h" |
| 9 #include "google_apis/gcm/protocol/mcs.pb.h" | 12 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 14 |
| 12 namespace gcm { | 15 namespace gcm { |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 mcs_proto::HeartbeatConfig BuildHeartbeatConfig(int interval_ms) { | 19 mcs_proto::HeartbeatConfig BuildHeartbeatConfig(int interval_ms) { |
| 17 mcs_proto::HeartbeatConfig config; | 20 mcs_proto::HeartbeatConfig config; |
| 18 config.set_interval_ms(interval_ms); | 21 config.set_interval_ms(interval_ms); |
| 19 return config; | 22 return config; |
| 20 } | 23 } |
| 21 | 24 |
| 22 class TestHeartbeatManager : public HeartbeatManager { | 25 class TestHeartbeatManager : public HeartbeatManager { |
| 23 public: | 26 public: |
| 24 TestHeartbeatManager() {} | 27 TestHeartbeatManager() |
| 28 : HeartbeatManager(make_scoped_ptr( |
| 29 new base::Timer(true, /* retain user task */ |
| 30 false /* non repeating */))) {} |
| 25 virtual ~TestHeartbeatManager() {} | 31 virtual ~TestHeartbeatManager() {} |
| 26 | 32 |
| 27 // Bypass the heartbeat timer, and send the heartbeat now. | 33 // Bypass the heartbeat timer, and send the heartbeat now. |
| 28 void TriggerHearbeat(); | 34 void TriggerHearbeat(); |
| 29 }; | 35 }; |
| 30 | 36 |
| 31 void TestHeartbeatManager::TriggerHearbeat() { | 37 void TestHeartbeatManager::TriggerHearbeat() { |
| 32 OnHeartbeatTriggered(); | 38 OnHeartbeatTriggered(); |
| 33 } | 39 } |
| 34 | 40 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 StartManager(); | 173 StartManager(); |
| 168 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); | 174 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); |
| 169 | 175 |
| 170 manager()->Stop(); | 176 manager()->Stop(); |
| 171 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); | 177 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); |
| 172 } | 178 } |
| 173 | 179 |
| 174 } // namespace | 180 } // namespace |
| 175 | 181 |
| 176 } // namespace gcm | 182 } // namespace gcm |
| OLD | NEW |