| 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/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Triggering and acking the heartbeat should result in a heartbeat being | 280 // Triggering and acking the heartbeat should result in a heartbeat being |
| 281 // posted with the new interval. | 281 // posted with the new interval. |
| 282 manager()->TriggerHearbeat(); | 282 manager()->TriggerHearbeat(); |
| 283 manager()->OnHeartbeatAcked(); | 283 manager()->OnHeartbeatAcked(); |
| 284 | 284 |
| 285 till_heartbeat = manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(); | 285 till_heartbeat = manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(); |
| 286 EXPECT_LE(till_heartbeat, base::TimeDelta::FromMilliseconds( | 286 EXPECT_LE(till_heartbeat, base::TimeDelta::FromMilliseconds( |
| 287 manager()->GetMaxClientHeartbeatIntervalMs())); | 287 manager()->GetMaxClientHeartbeatIntervalMs())); |
| 288 } | 288 } |
| 289 | 289 |
| 290 // Verifies that client interval is reset appropriately after the heartbeat is |
| 291 // triggered. See http://crbug.com/591490 for details. |
| 292 TEST_F(HeartbeatManagerTest, ClientIntervalAfterHeartbeatTriggered) { |
| 293 const int kCustomIntervalMs = 180 * 1000; // 180 seconds. |
| 294 manager()->SetClientHeartbeatIntervalMs(kCustomIntervalMs); |
| 295 StartManager(); |
| 296 |
| 297 // This changes the interval as manager awaits a heartbeat ack. |
| 298 manager()->TriggerHearbeat(); |
| 299 const int kDefaultAckIntervalMs = 60 * 1000; // 60 seconds. |
| 300 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime(); |
| 301 EXPECT_LE(heartbeat - base::TimeTicks::Now(), |
| 302 base::TimeDelta::FromMilliseconds(kDefaultAckIntervalMs)); |
| 303 |
| 304 // This should reset the interval to the custom interval. |
| 305 manager()->OnHeartbeatAcked(); |
| 306 heartbeat = manager()->GetNextHeartbeatTime(); |
| 307 EXPECT_GT(heartbeat - base::TimeTicks::Now(), |
| 308 base::TimeDelta::FromMilliseconds(kDefaultAckIntervalMs)); |
| 309 EXPECT_LE(heartbeat - base::TimeTicks::Now(), |
| 310 base::TimeDelta::FromMilliseconds(kCustomIntervalMs)); |
| 311 } |
| 312 |
| 290 } // namespace | 313 } // namespace |
| 291 | 314 |
| 292 } // namespace gcm | 315 } // namespace gcm |
| OLD | NEW |