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

Unified Diff: components/gcm_driver/gcm_stats_recorder_android_unittest.cc

Issue 1515153003: Enable chrome://gcm-internals on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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: components/gcm_driver/gcm_stats_recorder_android_unittest.cc
diff --git a/components/gcm_driver/gcm_stats_recorder_android_unittest.cc b/components/gcm_driver/gcm_stats_recorder_android_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44c2872837e05f9791a6c86899abc97ea70eb10d
--- /dev/null
+++ b/components/gcm_driver/gcm_stats_recorder_android_unittest.cc
@@ -0,0 +1,123 @@
+// Copyright 2015 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 "components/gcm_driver/gcm_stats_recorder_android.h"
+
+#include "base/test/histogram_tester.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace gcm {
+
+namespace {
+
+const char kTestAppId[] = "test_app_id";
+
+class GCMStatsRecorderAndroidTest : public ::testing::Test,
+ public GCMStatsRecorderAndroid::Delegate {
+ public:
+ GCMStatsRecorderAndroidTest()
+ : activity_recorded_calls_(0) {}
+ ~GCMStatsRecorderAndroidTest() {}
+
+ // GCMStatsRecorderAndroid::Delegate implementation.
+ void OnActivityRecorded() override {
+ ++activity_recorded_calls_;
+ }
+
+ size_t activity_recorded_calls() const { return activity_recorded_calls_; }
+
+ private:
+ size_t activity_recorded_calls_;
+};
+
+TEST_F(GCMStatsRecorderAndroidTest, RecordsAndCallsDelegate) {
+ GCMStatsRecorderAndroid recorder(this /* delegate */);
+ recorder.SetRecording(true);
+
+ ASSERT_TRUE(recorder.is_recording());
+
+ EXPECT_EQ(0u, activity_recorded_calls());
+
+ recorder.RecordRegistrationSent(kTestAppId);
+ EXPECT_EQ(1u, activity_recorded_calls());
+
+ recorder.RecordRegistrationResponse(kTestAppId, true /* success */);
+ EXPECT_EQ(2u, activity_recorded_calls());
+
+ recorder.RecordUnregistrationSent(kTestAppId);
+ EXPECT_EQ(3u, activity_recorded_calls());
+
+ recorder.RecordUnregistrationResponse(kTestAppId, true /* success */);
+ EXPECT_EQ(4u, activity_recorded_calls());
+
+ recorder.RecordDataMessageReceived(kTestAppId, 42 /* message_byte_size */);
+ EXPECT_EQ(5u, activity_recorded_calls());
+
+ RecordedActivities activities;
+ recorder.CollectActivities(&activities);
+
+ EXPECT_EQ(4u, activities.registration_activities.size());
+ EXPECT_EQ(1u, activities.receiving_activities.size());
+
+ recorder.CollectActivities(&activities);
+
+ EXPECT_EQ(8u, activities.registration_activities.size());
+ EXPECT_EQ(2u, activities.receiving_activities.size());
+
+ recorder.Clear();
+
+ RecordedActivities empty_activities;
+ recorder.CollectActivities(&empty_activities);
+
+ EXPECT_EQ(0u, empty_activities.registration_activities.size());
+ EXPECT_EQ(0u, empty_activities.receiving_activities.size());
+}
+
+TEST_F(GCMStatsRecorderAndroidTest, NullDelegate) {
+ GCMStatsRecorderAndroid recorder(nullptr /* delegate */);
+ recorder.SetRecording(true);
+
+ ASSERT_TRUE(recorder.is_recording());
+
+ recorder.RecordRegistrationSent(kTestAppId);
+
+ RecordedActivities activities;
+ recorder.CollectActivities(&activities);
+
+ EXPECT_EQ(1u, activities.registration_activities.size());
+}
+
+TEST_F(GCMStatsRecorderAndroidTest, NotRecording) {
+ GCMStatsRecorderAndroid recorder(this /* delegate */);
+ ASSERT_FALSE(recorder.is_recording());
+
+ recorder.RecordRegistrationSent(kTestAppId);
+
+ RecordedActivities activities;
+ recorder.CollectActivities(&activities);
+
+ EXPECT_EQ(0u, activities.registration_activities.size());
+}
+
+TEST_F(GCMStatsRecorderAndroidTest, HistogramCounts) {
+ GCMStatsRecorderAndroid recorder(this /* delegate */);
+ recorder.SetRecording(true);
+
+ ASSERT_TRUE(recorder.is_recording());
+
+ base::HistogramTester histogram_tester;
+
+ recorder.RecordRegistrationSent(kTestAppId);
+ histogram_tester.ExpectTotalCount("GCM.RegistrationRequest", 1);
+
+ recorder.RecordUnregistrationSent(kTestAppId);
+ histogram_tester.ExpectTotalCount("GCM.UnregistrationRequest", 1);
+
+ recorder.RecordDataMessageReceived(kTestAppId, 42 /* message_byte_size */);
+ histogram_tester.ExpectTotalCount("GCM.DataMessageReceived", 1);
+}
+
+} // namespace
jianli 2015/12/18 00:10:00 Why wrapping all test code inside anonymous namesp
Peter Beverloo 2015/12/18 17:19:17 It became a force of habit per the following threa
+
+} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698