| 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
|
| +
|
| +} // namespace gcm
|
|
|