| Index: google_apis/gcm/gcm_stats_recorder_unittest.cc
|
| diff --git a/google_apis/gcm/gcm_stats_recorder_unittest.cc b/google_apis/gcm/gcm_stats_recorder_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b0400211b66f98c9e31bfaf56e006ce7773f4821
|
| --- /dev/null
|
| +++ b/google_apis/gcm/gcm_stats_recorder_unittest.cc
|
| @@ -0,0 +1,127 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "google_apis/gcm/gcm_stats_recorder.h"
|
| +
|
| +#include <deque>
|
| +#include <string>
|
| +
|
| +#include "google_apis/gcm/engine/mcs_client.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace gcm {
|
| +
|
| +namespace {
|
| +
|
| +const std::string kAppId = "app id 1";
|
| +const std::string kReceiverId = "receiver 1";
|
| +const std::string kMessageId = "message id 1";
|
| +const int kQueuedSec = 5;
|
| +const gcm::MCSClient::MessageSendStatus kMessageSendStatus =
|
| + gcm::MCSClient::QUEUED;
|
| +const int kByteSize = 99;
|
| +const int kTTL = 7;
|
| +
|
| +const std::string kSentToWireEvent = "Sent to wire";
|
| +const std::string kSentToWireDetails = "Msg queued for 5 seconds";
|
| +const std::string kNotifySendStatusEvent = "SEND status: QUEUED";
|
| +const std::string kNotifySendStatusDetails = "Msg size: 99 bytes, TTL: 7";
|
| +const std::string kSendCalledEvent = "SEND is called";
|
| +const std::string kSendCalledDetails = "Msg size: 99 bytes, TTL: 7";
|
| +const std::string kIncomingSendErrorEvent = "Received 'send error' msg";
|
| +const std::string kIncomingSendErrorDetails = "Msg size: 99 bytes, TTL: 7";
|
| +
|
| +
|
| +class TestGCMStatsRecorder : public GCMStatsRecorder {
|
| + public:
|
| + TestGCMStatsRecorder() {};
|
| + virtual ~TestGCMStatsRecorder() {};
|
| +
|
| + std::deque<gcm::GCMStatsRecorder::SendingActivity>* sending_activities() {
|
| + return &sending_activities_;
|
| + }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +class GCMStatsRecorderTest : public testing::Test {
|
| + public:
|
| + GCMStatsRecorderTest();
|
| + virtual ~GCMStatsRecorderTest();
|
| + virtual void SetUp() OVERRIDE;
|
| +
|
| + void VerifyRecordedSendingCount(int expected_count) {
|
| + EXPECT_EQ(expected_count,
|
| + static_cast<int>(recorder_.sending_activities()->size()));
|
| + }
|
| +
|
| + void VerifySentToWire(){
|
| + VerifyData(*recorder_.sending_activities(),
|
| + kSentToWireEvent,
|
| + kSentToWireDetails);
|
| + }
|
| +
|
| + void VerifyNotifySendStatus(){
|
| + VerifyData(*recorder_.sending_activities(),
|
| + kNotifySendStatusEvent,
|
| + kNotifySendStatusDetails);
|
| + }
|
| +
|
| + void VerifyIncomingSendError(){
|
| + VerifyData(*recorder_.sending_activities(),
|
| + kIncomingSendErrorEvent,
|
| + kIncomingSendErrorDetails);
|
| + }
|
| +
|
| + protected:
|
| + template <typename T>
|
| + void VerifyData(const std::deque<T>& queue, const std::string& event,
|
| + const std::string& details) {
|
| + EXPECT_EQ(kAppId, queue.front().app_id);
|
| + EXPECT_EQ(kReceiverId, queue.front().receiver_id);
|
| + EXPECT_EQ(kMessageId, queue.front().message_id);
|
| + EXPECT_EQ(event, queue.front().event);
|
| + EXPECT_EQ(details, queue.front().details);
|
| + }
|
| +
|
| + TestGCMStatsRecorder recorder_;
|
| +};
|
| +
|
| +GCMStatsRecorderTest::GCMStatsRecorderTest(){
|
| +}
|
| +
|
| +GCMStatsRecorderTest::~GCMStatsRecorderTest() {}
|
| +
|
| +void GCMStatsRecorderTest::SetUp(){
|
| + recorder_.SetRecording(true);
|
| +}
|
| +
|
| +
|
| +
|
| +TEST_F(GCMStatsRecorderTest, RecordSendingTest) {
|
| + EXPECT_TRUE(recorder_.is_recording());
|
| + recorder_.RecordSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
|
| + VerifyRecordedSendingCount(1);
|
| + VerifySentToWire();
|
| +
|
| + recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
|
| + kMessageSendStatus, kByteSize, kTTL);
|
| + VerifyRecordedSendingCount(2);
|
| + VerifyNotifySendStatus();
|
| +
|
| + recorder_.Clear();
|
| + VerifyRecordedSendingCount(0);
|
| +
|
| + recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId, kByteSize,
|
| + kTTL);
|
| + VerifyRecordedSendingCount(1);
|
| + VerifyIncomingSendError();
|
| +
|
| + recorder_.SetRecording(false);
|
| + EXPECT_FALSE(recorder_.is_recording());
|
| + recorder_.RecordSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
|
| + VerifyRecordedSendingCount(1);
|
| +}
|
| +
|
| +} // namespace gcm
|
|
|