Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: google_apis/gcm/engine/heartbeat_manager_unittest.cc

Issue 745123002: Link GCM heartbeat with wake on wifi preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up includes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
12 #include "google_apis/gcm/protocol/mcs.pb.h" 13 #include "google_apis/gcm/protocol/mcs.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace gcm { 16 namespace gcm {
16 17
17 namespace { 18 namespace {
18 19
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Triggering and acking the heartbeat should result in a heartbeat being 169 // Triggering and acking the heartbeat should result in a heartbeat being
169 // posted with the new interval. 170 // posted with the new interval.
170 manager()->TriggerHearbeat(); 171 manager()->TriggerHearbeat();
171 manager()->OnHeartbeatAcked(); 172 manager()->OnHeartbeatAcked();
172 173
173 EXPECT_LE(manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(), 174 EXPECT_LE(manager()->GetNextHeartbeatTime() - base::TimeTicks::Now(),
174 base::TimeDelta::FromMilliseconds(kIntervalMs)); 175 base::TimeDelta::FromMilliseconds(kIntervalMs));
175 EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime()); 176 EXPECT_NE(heartbeat, manager()->GetNextHeartbeatTime());
176 } 177 }
177 178
179 // Updating the timer used for heartbeats before starting should not start the
180 // timer.
181 TEST_F(HeartbeatManagerTest, UpdateTimerBeforeStart) {
182 manager()->UpdateHeartbeatTimer(
183 make_scoped_ptr(new base::Timer(true, false)));
184 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null());
185 }
186
187 // Updating the timer used for heartbeats after starting should restart the
188 // timer but not change the heartbeat time.
189 TEST_F(HeartbeatManagerTest, UpdateTimerAfterStart) {
190 StartManager();
191 base::TimeTicks heartbeat = manager()->GetNextHeartbeatTime();
192
193 manager()->UpdateHeartbeatTimer(
194 make_scoped_ptr(new base::Timer(true, false)));
195 EXPECT_EQ(heartbeat, manager()->GetNextHeartbeatTime());
196 }
197
178 // Stopping the manager should reset the heartbeat timer. 198 // Stopping the manager should reset the heartbeat timer.
179 TEST_F(HeartbeatManagerTest, Stop) { 199 TEST_F(HeartbeatManagerTest, Stop) {
180 StartManager(); 200 StartManager();
181 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now()); 201 EXPECT_GT(manager()->GetNextHeartbeatTime(), base::TimeTicks::Now());
182 202
183 manager()->Stop(); 203 manager()->Stop();
184 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null()); 204 EXPECT_TRUE(manager()->GetNextHeartbeatTime().is_null());
185 } 205 }
186 206
187 // Simulate missing a heartbeat by manually invoking the check method. The 207 // Simulate missing a heartbeat by manually invoking the check method. The
188 // heartbeat should only be triggered once, and only if the heartbeat timer 208 // heartbeat should only be triggered once, and only if the heartbeat timer
189 // is running. Because the period is several minutes, none should fire. 209 // is running. Because the period is several minutes, none should fire.
190 TEST_F(HeartbeatManagerTest, MissedHeartbeat) { 210 TEST_F(HeartbeatManagerTest, MissedHeartbeat) {
191 // Do nothing while stopped. 211 // Do nothing while stopped.
192 manager()->TriggerMissedHeartbeatCheck(); 212 manager()->TriggerMissedHeartbeatCheck();
193 StartManager(); 213 StartManager();
194 EXPECT_EQ(0, heartbeats_sent()); 214 EXPECT_EQ(0, heartbeats_sent());
195 215
196 // Do nothing before the period is reached. 216 // Do nothing before the period is reached.
197 manager()->TriggerMissedHeartbeatCheck(); 217 manager()->TriggerMissedHeartbeatCheck();
198 EXPECT_EQ(0, heartbeats_sent()); 218 EXPECT_EQ(0, heartbeats_sent());
199 } 219 }
200 220
201 } // namespace 221 } // namespace
202 222
203 } // namespace gcm 223 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698