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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(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
OLDNEW
« 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