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

Side by Side Diff: google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc

Issue 261573002: Add checkin activity recording to gcm recorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolve conflicts. Created 6 years, 7 months 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
« no previous file with comments | « google_apis/gcm/monitoring/gcm_stats_recorder.cc ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/monitoring/gcm_stats_recorder.h" 5 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "google_apis/gcm/engine/mcs_client.h" 11 #include "google_apis/gcm/engine/mcs_client.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace gcm { 14 namespace gcm {
15 15
16 namespace { 16 namespace {
17 17
18 static uint64 kAndroidId = 4U;
19 static const char kCheckinStatus[] = "URL_FETCHING_FAILED";
18 static const char kHost[] = "www.example.com"; 20 static const char kHost[] = "www.example.com";
19 static const char kAppId[] = "app id 1"; 21 static const char kAppId[] = "app id 1";
20 static const char kFrom[] = "from"; 22 static const char kFrom[] = "from";
21 static const char kSenderIds[] = "s1,s2"; 23 static const char kSenderIds[] = "s1,s2";
22 static const char kReceiverId[] = "receiver 1"; 24 static const char kReceiverId[] = "receiver 1";
23 static const char kMessageId[] = "message id 1"; 25 static const char kMessageId[] = "message id 1";
24 static const int kQueuedSec = 5; 26 static const int kQueuedSec = 5;
25 static const gcm::MCSClient::MessageSendStatus kMessageSendStatus = 27 static const gcm::MCSClient::MessageSendStatus kMessageSendStatus =
26 gcm::MCSClient::QUEUED; 28 gcm::MCSClient::QUEUED;
27 static const int kByteSize = 99; 29 static const int kByteSize = 99;
28 static const int kTTL = 7; 30 static const int kTTL = 7;
29 static const int kRetries = 3; 31 static const int kRetries = 3;
30 static const int64 kDelay = 15000; 32 static const int64 kDelay = 15000;
31 static const ConnectionFactory::ConnectionResetReason kReason = 33 static const ConnectionFactory::ConnectionResetReason kReason =
32 ConnectionFactory::NETWORK_CHANGE; 34 ConnectionFactory::NETWORK_CHANGE;
33 static const int kNetworkError = 1; 35 static const int kNetworkError = 1;
34 36
35 static const RegistrationRequest::Status kRegistrationStatus = 37 static const RegistrationRequest::Status kRegistrationStatus =
36 RegistrationRequest::SUCCESS; 38 RegistrationRequest::SUCCESS;
37 static const UnregistrationRequest::Status kUnregistrationStatus = 39 static const UnregistrationRequest::Status kUnregistrationStatus =
38 UnregistrationRequest::SUCCESS; 40 UnregistrationRequest::SUCCESS;
39 41
42 static const char kCheckinInitiatedEvent[] = "Checkin initiated";
43 static const char kCheckinInitiatedDetails[] = "Android Id: 4";
44 static const char kCheckinDelayedDueToBackoffEvent[] = "Checkin backoff";
45 static const char kCheckinDelayedDueToBackoffDetails[] =
46 "Delayed for 15000 msec";
47 static const char kCheckinSuccessEvent[] = "Checkin succeeded";
48 static const char kCheckinSuccessDetails[] = "";
49 static const char kCheckinFailureEvent[] = "Checkin failed";
50 static const char kCheckinFailureDetails[] = "URL_FETCHING_FAILED. Will retry.";
51
40 static const char kConnectionInitiatedEvent[] = "Connection initiated"; 52 static const char kConnectionInitiatedEvent[] = "Connection initiated";
41 static const char kConnectionInitiatedDetails[] = "www.example.com"; 53 static const char kConnectionInitiatedDetails[] = "www.example.com";
42 static const char kConnectionDelayedDueToBackoffEvent[] = "Connection backoff"; 54 static const char kConnectionDelayedDueToBackoffEvent[] = "Connection backoff";
43 static const char kConnectionDelayedDueToBackoffDetails[] = 55 static const char kConnectionDelayedDueToBackoffDetails[] =
44 "Delayed for 15000 msec"; 56 "Delayed for 15000 msec";
45 static const char kConnectionSuccessEvent[] = "Connection succeeded"; 57 static const char kConnectionSuccessEvent[] = "Connection succeeded";
46 static const char kConnectionSuccessDetails[] = ""; 58 static const char kConnectionSuccessDetails[] = "";
47 static const char kConnectionFailureEvent[] = "Connection failed"; 59 static const char kConnectionFailureEvent[] = "Connection failed";
48 static const char kConnectionFailureDetails[] = "With network error 1"; 60 static const char kConnectionFailureDetails[] = "With network error 1";
49 static const char kConnectionResetSignaledEvent[] = "Connection reset"; 61 static const char kConnectionResetSignaledEvent[] = "Connection reset";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 static const char kIncomingSendErrorDetails[] = ""; 96 static const char kIncomingSendErrorDetails[] = "";
85 97
86 } // namespace 98 } // namespace
87 99
88 class GCMStatsRecorderTest : public testing::Test { 100 class GCMStatsRecorderTest : public testing::Test {
89 public: 101 public:
90 GCMStatsRecorderTest(); 102 GCMStatsRecorderTest();
91 virtual ~GCMStatsRecorderTest(); 103 virtual ~GCMStatsRecorderTest();
92 virtual void SetUp() OVERRIDE; 104 virtual void SetUp() OVERRIDE;
93 105
106 void VerifyRecordedCheckinCount(int expected_count) {
107 EXPECT_EQ(expected_count,
108 static_cast<int>(recorder_.checkin_activities().size()));
109 }
94 void VerifyRecordedConnectionCount(int expected_count) { 110 void VerifyRecordedConnectionCount(int expected_count) {
95 EXPECT_EQ(expected_count, 111 EXPECT_EQ(expected_count,
96 static_cast<int>(recorder_.connection_activities().size())); 112 static_cast<int>(recorder_.connection_activities().size()));
97 } 113 }
98 void VerifyRecordedRegistrationCount(int expected_count) { 114 void VerifyRecordedRegistrationCount(int expected_count) {
99 EXPECT_EQ(expected_count, 115 EXPECT_EQ(expected_count,
100 static_cast<int>(recorder_.registration_activities().size())); 116 static_cast<int>(recorder_.registration_activities().size()));
101 } 117 }
102 void VerifyRecordedReceivingCount(int expected_count) { 118 void VerifyRecordedReceivingCount(int expected_count) {
103 EXPECT_EQ(expected_count, 119 EXPECT_EQ(expected_count,
104 static_cast<int>(recorder_.receiving_activities().size())); 120 static_cast<int>(recorder_.receiving_activities().size()));
105 } 121 }
106 void VerifyRecordedSendingCount(int expected_count) { 122 void VerifyRecordedSendingCount(int expected_count) {
107 EXPECT_EQ(expected_count, 123 EXPECT_EQ(expected_count,
108 static_cast<int>(recorder_.sending_activities().size())); 124 static_cast<int>(recorder_.sending_activities().size()));
109 } 125 }
110 126
127 void VerifyCheckinInitiated(const std::string& remark) {
128 VerifyCheckin(recorder_.checkin_activities(),
129 kCheckinInitiatedEvent,
130 kCheckinInitiatedDetails,
131 remark);
132 }
133
134 void VerifyCheckinDelayedDueToBackoff(const std::string& remark) {
135 VerifyCheckin(recorder_.checkin_activities(),
136 kCheckinDelayedDueToBackoffEvent,
137 kCheckinDelayedDueToBackoffDetails,
138 remark);
139 }
140
141 void VerifyCheckinSuccess(const std::string& remark) {
142 VerifyCheckin(recorder_.checkin_activities(),
143 kCheckinSuccessEvent,
144 kCheckinSuccessDetails,
145 remark);
146 }
147
148 void VerifyCheckinFailure(const std::string& remark) {
149 VerifyCheckin(recorder_.checkin_activities(),
150 kCheckinFailureEvent,
151 kCheckinFailureDetails,
152 remark);
153 }
154
111 void VerifyConnectionInitiated(const std::string& remark) { 155 void VerifyConnectionInitiated(const std::string& remark) {
112 VerifyConnection(recorder_.connection_activities(), 156 VerifyConnection(recorder_.connection_activities(),
113 kConnectionInitiatedEvent, 157 kConnectionInitiatedEvent,
114 kConnectionInitiatedDetails, 158 kConnectionInitiatedDetails,
115 remark); 159 remark);
116 } 160 }
117 161
118 void VerifyConnectionDelayedDueToBackoff(const std::string& remark) { 162 void VerifyConnectionDelayedDueToBackoff(const std::string& remark) {
119 VerifyConnection(recorder_.connection_activities(), 163 VerifyConnection(recorder_.connection_activities(),
120 kConnectionDelayedDueToBackoffEvent, 164 kConnectionDelayedDueToBackoffEvent,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 271 }
228 272
229 void VerifyIncomingSendError(const std::string& remark) { 273 void VerifyIncomingSendError(const std::string& remark) {
230 VerifySendingData(recorder_.sending_activities(), 274 VerifySendingData(recorder_.sending_activities(),
231 kIncomingSendErrorEvent, 275 kIncomingSendErrorEvent,
232 kIncomingSendErrorDetails, 276 kIncomingSendErrorDetails,
233 remark); 277 remark);
234 } 278 }
235 279
236 protected: 280 protected:
281 void VerifyCheckin(
282 const std::deque<GCMStatsRecorder::CheckinActivity>& queue,
283 const std::string& event,
284 const std::string& details,
285 const std::string& remark) {
286 EXPECT_EQ(event, queue.front().event) << remark;
287 EXPECT_EQ(details, queue.front().details) << remark;
288 }
289
237 void VerifyConnection( 290 void VerifyConnection(
238 const std::deque<GCMStatsRecorder::ConnectionActivity>& queue, 291 const std::deque<GCMStatsRecorder::ConnectionActivity>& queue,
239 const std::string& event, 292 const std::string& event,
240 const std::string& details, 293 const std::string& details,
241 const std::string& remark) { 294 const std::string& remark) {
242 EXPECT_EQ(event, queue.front().event) << remark; 295 EXPECT_EQ(event, queue.front().event) << remark;
243 EXPECT_EQ(details, queue.front().details) << remark; 296 EXPECT_EQ(details, queue.front().details) << remark;
244 } 297 }
245 298
246 void VerifyRegistration( 299 void VerifyRegistration(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 366
314 recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId, 367 recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
315 kMessageSendStatus, kByteSize, kTTL); 368 kMessageSendStatus, kByteSize, kTTL);
316 VerifyRecordedSendingCount(2); 369 VerifyRecordedSendingCount(2);
317 VerifyNotifySendStatus("2nd call"); 370 VerifyNotifySendStatus("2nd call");
318 371
319 recorder_.Clear(); 372 recorder_.Clear();
320 VerifyRecordedSendingCount(0); 373 VerifyRecordedSendingCount(0);
321 } 374 }
322 375
376 TEST_F(GCMStatsRecorderTest, CheckinTest) {
377 recorder_.RecordCheckinInitiated(kAndroidId);
378 VerifyRecordedCheckinCount(1);
379 VerifyCheckinInitiated("1st call");
380
381 recorder_.RecordCheckinDelayedDueToBackoff(kDelay);
382 VerifyRecordedCheckinCount(2);
383 VerifyCheckinDelayedDueToBackoff("2nd call");
384
385 recorder_.RecordCheckinSuccess();
386 VerifyRecordedCheckinCount(3);
387 VerifyCheckinSuccess("3rd call");
388
389 recorder_.RecordCheckinFailure(kCheckinStatus, true);
390 VerifyRecordedCheckinCount(4);
391 VerifyCheckinFailure("4th call");
392 }
393
323 TEST_F(GCMStatsRecorderTest, ConnectionTest) { 394 TEST_F(GCMStatsRecorderTest, ConnectionTest) {
324 recorder_.RecordConnectionInitiated(kHost); 395 recorder_.RecordConnectionInitiated(kHost);
325 VerifyRecordedConnectionCount(1); 396 VerifyRecordedConnectionCount(1);
326 VerifyConnectionInitiated("1st call"); 397 VerifyConnectionInitiated("1st call");
327 398
328 recorder_.RecordConnectionDelayedDueToBackoff(kDelay); 399 recorder_.RecordConnectionDelayedDueToBackoff(kDelay);
329 VerifyRecordedConnectionCount(2); 400 VerifyRecordedConnectionCount(2);
330 VerifyConnectionDelayedDueToBackoff("2nd call"); 401 VerifyConnectionDelayedDueToBackoff("2nd call");
331 402
332 recorder_.RecordConnectionSuccess(); 403 recorder_.RecordConnectionSuccess();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId); 470 recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId);
400 VerifyRecordedSendingCount(3); 471 VerifyRecordedSendingCount(3);
401 VerifyIncomingSendError("3rd call"); 472 VerifyIncomingSendError("3rd call");
402 473
403 recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); 474 recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
404 VerifyRecordedSendingCount(4); 475 VerifyRecordedSendingCount(4);
405 VerifyDataSentToWire("4th call"); 476 VerifyDataSentToWire("4th call");
406 } 477 }
407 478
408 } // namespace gcm 479 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/monitoring/gcm_stats_recorder.cc ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698