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

Unified Diff: google_apis/gcm/gcm_stats_recorder_unittest.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing arv's comments. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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";
+
Nicolas Zea 2014/03/27 18:55:42 remove extra newline
juyik 2014/03/27 20:05:11 Done.
+
+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);
+}
+
+
Nicolas Zea 2014/03/27 18:55:42 remove extra newlines
juyik 2014/03/27 20:05:11 Done.
+
+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.
+ 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
« google_apis/gcm/gcm_stats_recorder.cc ('K') | « google_apis/gcm/gcm_stats_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698