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

Unified Diff: google_apis/gcm/monitoring/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: . Created 6 years, 8 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
« no previous file with comments | « google_apis/gcm/monitoring/gcm_stats_recorder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc b/google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..488b31b1a37428a786b8ee5ccf61f2e45be91c13
--- /dev/null
+++ b/google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc
@@ -0,0 +1,136 @@
+// 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/monitoring/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 {
+
+static const char kAppId[] = "app id 1";
+static const char kReceiverId[] = "receiver 1";
+static const char kMessageId[] = "message id 1";
+static const int kQueuedSec = 5;
+static const gcm::MCSClient::MessageSendStatus kMessageSendStatus =
+ gcm::MCSClient::QUEUED;
+static const int kByteSize = 99;
+static const int kTTL = 7;
+
+static const char kDataSentToWireEvent[] = "Data msg sent to wire";
+static const char kSentToWireDetails[] = "Msg queued for 5 seconds";
+static const char kNotifySendStatusEvent[] = "SEND status: QUEUED";
+static const char kNotifySendStatusDetails[] = "Msg size: 99 bytes, TTL: 7";
+static const char kIncomingSendErrorEvent[] = "Received 'send error' msg";
+static const char kIncomingSendErrorDetails[] = "";
+
+} // 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 VerifyDataSentToWire(const std::string& remark){
+ VerifyData(recorder_.sending_activities(),
+ kDataSentToWireEvent,
+ kSentToWireDetails,
+ remark);
+ }
+
+ void VerifyNotifySendStatus(const std::string& remark){
+ VerifyData(recorder_.sending_activities(),
+ kNotifySendStatusEvent,
+ kNotifySendStatusDetails,
+ remark);
+ }
+
+ void VerifyIncomingSendError(const std::string& remark){
+ VerifyData(recorder_.sending_activities(),
+ kIncomingSendErrorEvent,
+ kIncomingSendErrorDetails,
+ remark);
+ }
+
+ protected:
+ template <typename T>
+ void VerifyData(const std::deque<T>& queue, const std::string& event,
+ const std::string& details, const std::string& remark) {
+ EXPECT_EQ(kAppId, queue.front().app_id) << remark;
+ EXPECT_EQ(kReceiverId, queue.front().receiver_id) << remark;
+ EXPECT_EQ(kMessageId, queue.front().message_id) << remark;
+ EXPECT_EQ(event, queue.front().event) << remark;
+ EXPECT_EQ(details, queue.front().details) << remark;
+ }
+
+ GCMStatsRecorder recorder_;
+};
+
+GCMStatsRecorderTest::GCMStatsRecorderTest(){
+}
+
+GCMStatsRecorderTest::~GCMStatsRecorderTest() {}
+
+void GCMStatsRecorderTest::SetUp(){
+ recorder_.SetRecording(true);
+}
+
+TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) {
+ EXPECT_TRUE(recorder_.is_recording());
+ recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
+ VerifyRecordedSendingCount(1);
+ VerifyDataSentToWire("1st call");
+
+ recorder_.SetRecording(false);
+ EXPECT_FALSE(recorder_.is_recording());
+ recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
+ VerifyRecordedSendingCount(1);
+ VerifyDataSentToWire("2nd call");
+}
+
+TEST_F(GCMStatsRecorderTest, ClearLogTest) {
+ recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
+ VerifyRecordedSendingCount(1);
+ VerifyDataSentToWire("1st call");
+
+ recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
+ kMessageSendStatus, kByteSize, kTTL);
+ VerifyRecordedSendingCount(2);
+ VerifyNotifySendStatus("2nd call");
+
+ recorder_.Clear();
+ VerifyRecordedSendingCount(0);
+}
+
+TEST_F(GCMStatsRecorderTest, RecordSendingTest) {
+ recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
+ VerifyRecordedSendingCount(1);
+ VerifyDataSentToWire("1st call");
+
+ recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
+ kMessageSendStatus, kByteSize, kTTL);
+ VerifyRecordedSendingCount(2);
+ VerifyNotifySendStatus("2nd call");
+
+ recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId);
+ VerifyRecordedSendingCount(3);
+ VerifyIncomingSendError("3rd call");
+
+ recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
+ VerifyRecordedSendingCount(4);
+ VerifyDataSentToWire("4th call");
+}
+
+} // namespace gcm
« no previous file with comments | « google_apis/gcm/monitoring/gcm_stats_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698