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 "components/gcm_driver/gcm_stats_recorder_impl.h" | 5 #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" |
13 #include "google_apis/gcm/engine/mcs_client.h" | 14 #include "google_apis/gcm/engine/mcs_client.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace gcm { | 17 namespace gcm { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 static uint64_t kAndroidId = 4U; | 21 static uint64_t kAndroidId = 4U; |
21 static const char kCheckinStatus[] = "URL_FETCHING_FAILED"; | 22 static const char kCheckinStatus[] = "URL_FETCHING_FAILED"; |
22 static const char kHost[] = "www.example.com"; | 23 static const char kHost[] = "www.example.com"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 static const char kDataDeletedMessageDetails[] = | 92 static const char kDataDeletedMessageDetails[] = |
92 "Message has been deleted on server"; | 93 "Message has been deleted on server"; |
93 | 94 |
94 static const char kDataSentToWireEvent[] = "Data msg sent to wire"; | 95 static const char kDataSentToWireEvent[] = "Data msg sent to wire"; |
95 static const char kSentToWireDetails[] = "Msg queued for 5 seconds"; | 96 static const char kSentToWireDetails[] = "Msg queued for 5 seconds"; |
96 static const char kNotifySendStatusEvent[] = "SEND status: QUEUED"; | 97 static const char kNotifySendStatusEvent[] = "SEND status: QUEUED"; |
97 static const char kNotifySendStatusDetails[] = "Msg size: 99 bytes, TTL: 7"; | 98 static const char kNotifySendStatusDetails[] = "Msg size: 99 bytes, TTL: 7"; |
98 static const char kIncomingSendErrorEvent[] = "Received 'send error' msg"; | 99 static const char kIncomingSendErrorEvent[] = "Received 'send error' msg"; |
99 static const char kIncomingSendErrorDetails[] = ""; | 100 static const char kIncomingSendErrorDetails[] = ""; |
100 | 101 |
| 102 static const GCMEncryptionProvider::DecryptionFailure kDecryptionFailureReason = |
| 103 GCMEncryptionProvider::DECRYPTION_FAILURE_INVALID_PAYLOAD; |
| 104 |
101 } // namespace | 105 } // namespace |
102 | 106 |
103 class GCMStatsRecorderImplTest : public testing::Test { | 107 class GCMStatsRecorderImplTest : public testing::Test { |
104 public: | 108 public: |
105 GCMStatsRecorderImplTest(); | 109 GCMStatsRecorderImplTest(); |
106 ~GCMStatsRecorderImplTest() override; | 110 ~GCMStatsRecorderImplTest() override; |
107 void SetUp() override; | 111 void SetUp() override; |
108 | 112 |
109 void VerifyRecordedCheckinCount(int expected_count) { | 113 void VerifyRecordedCheckinCount(int expected_count) { |
110 EXPECT_EQ(expected_count, | 114 EXPECT_EQ(expected_count, |
111 static_cast<int>(recorder_.checkin_activities().size())); | 115 static_cast<int>(recorder_.checkin_activities().size())); |
112 } | 116 } |
113 void VerifyRecordedConnectionCount(int expected_count) { | 117 void VerifyRecordedConnectionCount(int expected_count) { |
114 EXPECT_EQ(expected_count, | 118 EXPECT_EQ(expected_count, |
115 static_cast<int>(recorder_.connection_activities().size())); | 119 static_cast<int>(recorder_.connection_activities().size())); |
116 } | 120 } |
117 void VerifyRecordedRegistrationCount(int expected_count) { | 121 void VerifyRecordedRegistrationCount(int expected_count) { |
118 EXPECT_EQ(expected_count, | 122 EXPECT_EQ(expected_count, |
119 static_cast<int>(recorder_.registration_activities().size())); | 123 static_cast<int>(recorder_.registration_activities().size())); |
120 } | 124 } |
121 void VerifyRecordedReceivingCount(int expected_count) { | 125 void VerifyRecordedReceivingCount(int expected_count) { |
122 EXPECT_EQ(expected_count, | 126 EXPECT_EQ(expected_count, |
123 static_cast<int>(recorder_.receiving_activities().size())); | 127 static_cast<int>(recorder_.receiving_activities().size())); |
124 } | 128 } |
125 void VerifyRecordedSendingCount(int expected_count) { | 129 void VerifyRecordedSendingCount(int expected_count) { |
126 EXPECT_EQ(expected_count, | 130 EXPECT_EQ(expected_count, |
127 static_cast<int>(recorder_.sending_activities().size())); | 131 static_cast<int>(recorder_.sending_activities().size())); |
128 } | 132 } |
| 133 void VerifyRecordedDecryptionFailureCount(int expected_count) { |
| 134 EXPECT_EQ( |
| 135 expected_count, |
| 136 static_cast<int>(recorder_.decryption_failure_activities().size())); |
| 137 } |
129 void VerifyAllActivityQueueEmpty(const std::string& remark) { | 138 void VerifyAllActivityQueueEmpty(const std::string& remark) { |
130 EXPECT_TRUE(recorder_.checkin_activities().empty()) << remark; | 139 EXPECT_TRUE(recorder_.checkin_activities().empty()) << remark; |
131 EXPECT_TRUE(recorder_.connection_activities().empty()) << remark; | 140 EXPECT_TRUE(recorder_.connection_activities().empty()) << remark; |
132 EXPECT_TRUE(recorder_.registration_activities().empty()) << remark; | 141 EXPECT_TRUE(recorder_.registration_activities().empty()) << remark; |
133 EXPECT_TRUE(recorder_.receiving_activities().empty()) << remark; | 142 EXPECT_TRUE(recorder_.receiving_activities().empty()) << remark; |
134 EXPECT_TRUE(recorder_.sending_activities().empty()) << remark; | 143 EXPECT_TRUE(recorder_.sending_activities().empty()) << remark; |
| 144 EXPECT_TRUE(recorder_.decryption_failure_activities().empty()) << remark; |
135 } | 145 } |
136 | 146 |
137 void VerifyCheckinInitiated(const std::string& remark) { | 147 void VerifyCheckinInitiated(const std::string& remark) { |
138 VerifyCheckin(recorder_.checkin_activities(), | 148 VerifyCheckin(recorder_.checkin_activities(), |
139 kCheckinInitiatedEvent, | 149 kCheckinInitiatedEvent, |
140 kCheckinInitiatedDetails, | 150 kCheckinInitiatedDetails, |
141 remark); | 151 remark); |
142 } | 152 } |
143 | 153 |
144 void VerifyCheckinDelayedDueToBackoff(const std::string& remark) { | 154 void VerifyCheckinDelayedDueToBackoff(const std::string& remark) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 remark); | 290 remark); |
281 } | 291 } |
282 | 292 |
283 void VerifyIncomingSendError(const std::string& remark) { | 293 void VerifyIncomingSendError(const std::string& remark) { |
284 VerifySendingData(recorder_.sending_activities(), | 294 VerifySendingData(recorder_.sending_activities(), |
285 kIncomingSendErrorEvent, | 295 kIncomingSendErrorEvent, |
286 kIncomingSendErrorDetails, | 296 kIncomingSendErrorDetails, |
287 remark); | 297 remark); |
288 } | 298 } |
289 | 299 |
| 300 void VerifyRecordedDecryptionFailure(const std::string& remark) { |
| 301 const auto& queue = recorder_.decryption_failure_activities(); |
| 302 |
| 303 EXPECT_EQ(kAppId, queue.front().app_id) << remark; |
| 304 EXPECT_EQ( |
| 305 GCMEncryptionProvider::ToDecryptionFailureDetailsString( |
| 306 kDecryptionFailureReason), |
| 307 queue.front().details) << remark; |
| 308 } |
| 309 |
290 protected: | 310 protected: |
291 void VerifyCheckin( | 311 void VerifyCheckin( |
292 const std::deque<CheckinActivity>& queue, | 312 const std::deque<CheckinActivity>& queue, |
293 const std::string& event, | 313 const std::string& event, |
294 const std::string& details, | 314 const std::string& details, |
295 const std::string& remark) { | 315 const std::string& remark) { |
296 EXPECT_EQ(event, queue.front().event) << remark; | 316 EXPECT_EQ(event, queue.front().event) << remark; |
297 EXPECT_EQ(details, queue.front().details) << remark; | 317 EXPECT_EQ(details, queue.front().details) << remark; |
298 } | 318 } |
299 | 319 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 539 |
520 recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId); | 540 recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId); |
521 VerifyRecordedSendingCount(3); | 541 VerifyRecordedSendingCount(3); |
522 VerifyIncomingSendError("3rd call"); | 542 VerifyIncomingSendError("3rd call"); |
523 | 543 |
524 recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); | 544 recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); |
525 VerifyRecordedSendingCount(4); | 545 VerifyRecordedSendingCount(4); |
526 VerifyDataSentToWire("4th call"); | 546 VerifyDataSentToWire("4th call"); |
527 } | 547 } |
528 | 548 |
| 549 TEST_F(GCMStatsRecorderImplTest, RecordDecryptionFailureTest) { |
| 550 recorder_.RecordDecryptionFailure(kAppId, kDecryptionFailureReason); |
| 551 VerifyRecordedDecryptionFailureCount(1); |
| 552 |
| 553 VerifyRecordedDecryptionFailure("1st call"); |
| 554 } |
| 555 |
529 } // namespace gcm | 556 } // namespace gcm |
OLD | NEW |