Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "google_apis/gcm/gcm_stats_recorder.h" | |
| 6 | |
| 7 #include <deque> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "google_apis/gcm/engine/mcs_client.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace gcm { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const std::string kAppId = "app id 1"; | |
| 18 const std::string kReceiverId = "receiver 1"; | |
| 19 const std::string kMessageId = "message id 1"; | |
| 20 const int kQueuedSec = 5; | |
| 21 const gcm::MCSClient::MessageSendStatus kMessageSendStatus = | |
| 22 gcm::MCSClient::QUEUED; | |
| 23 const int kByteSize = 99; | |
| 24 const int kTTL = 7; | |
| 25 | |
| 26 const std::string kSentToWireEvent = "Sent to wire"; | |
| 27 const std::string kSentToWireDetails = "Msg queued for 5 seconds"; | |
| 28 const std::string kNotifySendStatusEvent = "SEND status: QUEUED"; | |
| 29 const std::string kNotifySendStatusDetails = "Msg size: 99 bytes, TTL: 7"; | |
| 30 const std::string kSendCalledEvent = "SEND is called"; | |
| 31 const std::string kSendCalledDetails = "Msg size: 99 bytes, TTL: 7"; | |
| 32 const std::string kIncomingSendErrorEvent = "Received 'send error' msg"; | |
| 33 const std::string kIncomingSendErrorDetails = "Msg size: 99 bytes, TTL: 7"; | |
| 34 | |
|
Nicolas Zea
2014/03/27 18:55:42
remove extra newline
juyik
2014/03/27 20:05:11
Done.
| |
| 35 | |
| 36 class TestGCMStatsRecorder : public GCMStatsRecorder { | |
| 37 public: | |
| 38 TestGCMStatsRecorder() {}; | |
| 39 virtual ~TestGCMStatsRecorder() {}; | |
| 40 | |
| 41 std::deque<gcm::GCMStatsRecorder::SendingActivity>* sending_activities() { | |
| 42 return &sending_activities_; | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 class GCMStatsRecorderTest : public testing::Test { | |
| 49 public: | |
| 50 GCMStatsRecorderTest(); | |
| 51 virtual ~GCMStatsRecorderTest(); | |
| 52 virtual void SetUp() OVERRIDE; | |
| 53 | |
| 54 void VerifyRecordedSendingCount(int expected_count) { | |
| 55 EXPECT_EQ(expected_count, | |
| 56 static_cast<int>(recorder_.sending_activities()->size())); | |
| 57 } | |
| 58 | |
| 59 void VerifySentToWire(){ | |
| 60 VerifyData(*recorder_.sending_activities(), | |
| 61 kSentToWireEvent, | |
| 62 kSentToWireDetails); | |
| 63 } | |
| 64 | |
| 65 void VerifyNotifySendStatus(){ | |
| 66 VerifyData(*recorder_.sending_activities(), | |
| 67 kNotifySendStatusEvent, | |
| 68 kNotifySendStatusDetails); | |
| 69 } | |
| 70 | |
| 71 void VerifyIncomingSendError(){ | |
| 72 VerifyData(*recorder_.sending_activities(), | |
| 73 kIncomingSendErrorEvent, | |
| 74 kIncomingSendErrorDetails); | |
| 75 } | |
| 76 | |
| 77 protected: | |
| 78 template <typename T> | |
| 79 void VerifyData(const std::deque<T>& queue, const std::string& event, | |
| 80 const std::string& details) { | |
| 81 EXPECT_EQ(kAppId, queue.front().app_id); | |
| 82 EXPECT_EQ(kReceiverId, queue.front().receiver_id); | |
| 83 EXPECT_EQ(kMessageId, queue.front().message_id); | |
| 84 EXPECT_EQ(event, queue.front().event); | |
| 85 EXPECT_EQ(details, queue.front().details); | |
| 86 } | |
| 87 | |
| 88 TestGCMStatsRecorder recorder_; | |
| 89 }; | |
| 90 | |
| 91 GCMStatsRecorderTest::GCMStatsRecorderTest(){ | |
| 92 } | |
| 93 | |
| 94 GCMStatsRecorderTest::~GCMStatsRecorderTest() {} | |
| 95 | |
| 96 void GCMStatsRecorderTest::SetUp(){ | |
| 97 recorder_.SetRecording(true); | |
| 98 } | |
| 99 | |
| 100 | |
|
Nicolas Zea
2014/03/27 18:55:42
remove extra newlines
juyik
2014/03/27 20:05:11
Done.
| |
| 101 | |
| 102 TEST_F(GCMStatsRecorderTest, RecordSendingTest) { | |
|
Nicolas Zea
2014/03/27 18:55:42
Could you split this test up into three different
juyik
2014/03/27 20:05:11
Done.
| |
| 103 EXPECT_TRUE(recorder_.is_recording()); | |
| 104 recorder_.RecordSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); | |
| 105 VerifyRecordedSendingCount(1); | |
| 106 VerifySentToWire(); | |
| 107 | |
| 108 recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId, | |
| 109 kMessageSendStatus, kByteSize, kTTL); | |
| 110 VerifyRecordedSendingCount(2); | |
| 111 VerifyNotifySendStatus(); | |
| 112 | |
| 113 recorder_.Clear(); | |
| 114 VerifyRecordedSendingCount(0); | |
| 115 | |
| 116 recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId, kByteSize, | |
| 117 kTTL); | |
| 118 VerifyRecordedSendingCount(1); | |
| 119 VerifyIncomingSendError(); | |
| 120 | |
| 121 recorder_.SetRecording(false); | |
| 122 EXPECT_FALSE(recorder_.is_recording()); | |
| 123 recorder_.RecordSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); | |
| 124 VerifyRecordedSendingCount(1); | |
| 125 } | |
| 126 | |
| 127 } // namespace gcm | |
| OLD | NEW |