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

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..4d46dc4a48e4aba1163500f7c6f62110d34be4fe
--- /dev/null
+++ b/components/gcm_driver/gcm_stats_recorder_android_unittest.cc
@@ -0,0 +1,104 @@
+// 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 "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() override {}
+
+ // 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.set_is_recording(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.set_is_recording(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());
+}
+
+} // namespace
+
+} // namespace gcm
« no previous file with comments | « components/gcm_driver/gcm_stats_recorder_android.cc ('k') | components/gcm_driver/gcm_stats_recorder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698