Index: google_apis/gcm/engine/heartbeat_manager_unittest.cc |
diff --git a/google_apis/gcm/engine/heartbeat_manager_unittest.cc b/google_apis/gcm/engine/heartbeat_manager_unittest.cc |
index e09707b2a21e9ffcc655257959622cebf4595b19..5d6838f8375c132c646c08ce85d0737bbbba038a 100644 |
--- a/google_apis/gcm/engine/heartbeat_manager_unittest.cc |
+++ b/google_apis/gcm/engine/heartbeat_manager_unittest.cc |
@@ -6,7 +6,9 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/threading/platform_thread.h" |
#include "base/time/time.h" |
#include "base/timer/timer.h" |
#include "google_apis/gcm/protocol/mcs.pb.h" |
@@ -175,6 +177,27 @@ TEST_F(HeartbeatManagerTest, StartThenUpdateInterval) { |
EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime()); |
} |
+// Updating the timer used for heartbeats before starting should not start the |
+// timer. |
+TEST_F(HeartbeatManagerTest, UpdateTimerBeforeStart) { |
+ manager()->UpdateHeartbeatTimer( |
+ make_scoped_ptr(new base::Timer(true, false))); |
+ EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); |
+} |
+ |
+// Updating the timer used for heartbeats after starting should restart the |
+// timer and update the heartbeat time. |
+TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) { |
+ StartManager(); |
+ base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime(); |
+ |
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(2)); |
Nicolas Zea
2014/12/05 00:53:05
why is this necessary?
Chirantan Ekbote
2014/12/05 21:49:05
Because otherwise the test would be too fast to re
|
+ |
+ manager()->UpdateHeartbeatTimer( |
+ make_scoped_ptr(new base::Timer(true, false))); |
+ EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime()); |
+} |
+ |
// Stopping the manager should reset the heartbeat timer. |
TEST_F(HeartbeatManagerTest, Stop) { |
StartManager(); |