| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/metrics/mobile_session_shutdown_metrics_provider.h" | 5 #include "ios/chrome/browser/metrics/mobile_session_shutdown_metrics_provider.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 11 #include "components/metrics/metrics_pref_names.h" | 12 #include "components/metrics/metrics_pref_names.h" |
| 12 #include "components/metrics/metrics_service.h" | 13 #include "components/metrics/metrics_service.h" |
| 13 #include "components/metrics/metrics_state_manager.h" | 14 #include "components/metrics/metrics_state_manager.h" |
| 14 #include "components/metrics/test_metrics_service_client.h" | 15 #include "components/metrics/test_metrics_service_client.h" |
| 15 #include "components/prefs/testing_pref_service.h" | 16 #include "components/prefs/testing_pref_service.h" |
| 16 #include "testing/gtest/include/gtest/gtest-param-test.h" | 17 #include "testing/gtest/include/gtest/gtest-param-test.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 class MobileSessionShutdownMetricsProviderTest | 71 class MobileSessionShutdownMetricsProviderTest |
| 71 : public testing::TestWithParam<int> { | 72 : public testing::TestWithParam<int> { |
| 72 public: | 73 public: |
| 73 MobileSessionShutdownMetricsProviderTest() { | 74 MobileSessionShutdownMetricsProviderTest() { |
| 74 metrics::MetricsService::RegisterPrefs(local_state_.registry()); | 75 metrics::MetricsService::RegisterPrefs(local_state_.registry()); |
| 75 } | 76 } |
| 76 | 77 |
| 77 protected: | 78 protected: |
| 78 TestingPrefServiceSimple local_state_; | 79 TestingPrefServiceSimple local_state_; |
| 79 metrics::TestMetricsServiceClient metrics_client_; | 80 metrics::TestMetricsServiceClient metrics_client_; |
| 80 scoped_ptr<metrics::MetricsStateManager> metrics_state_; | 81 std::unique_ptr<metrics::MetricsStateManager> metrics_state_; |
| 81 scoped_ptr<metrics::MetricsService> metrics_service_; | 82 std::unique_ptr<metrics::MetricsService> metrics_service_; |
| 82 scoped_ptr<MobileSessionShutdownMetricsProviderForTesting> metrics_provider_; | 83 std::unique_ptr<MobileSessionShutdownMetricsProviderForTesting> |
| 84 metrics_provider_; |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest); | 87 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest); |
| 86 }; | 88 }; |
| 87 | 89 |
| 88 // Verifies that a sample is recorded in the correct bucket of the shutdown type | 90 // Verifies that a sample is recorded in the correct bucket of the shutdown type |
| 89 // histogram when ProvideStabilityMetrics is invoked. | 91 // histogram when ProvideStabilityMetrics is invoked. |
| 90 // | 92 // |
| 91 // This parameterized test receives a parameter in the range [0, 32), which is | 93 // This parameterized test receives a parameter in the range [0, 32), which is |
| 92 // used to generate values for five booleans based on the binary representation | 94 // used to generate values for five booleans based on the binary representation |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Now call the method under test and verify exactly one sample is written to | 175 // Now call the method under test and verify exactly one sample is written to |
| 174 // the expected bucket. | 176 // the expected bucket. |
| 175 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); | 177 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); |
| 176 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", | 178 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", |
| 177 expected_buckets[GetParam()], 1); | 179 expected_buckets[GetParam()], 1); |
| 178 } | 180 } |
| 179 | 181 |
| 180 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, | 182 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, |
| 181 MobileSessionShutdownMetricsProviderTest, | 183 MobileSessionShutdownMetricsProviderTest, |
| 182 testing::Range(0, 32)); | 184 testing::Range(0, 32)); |
| OLD | NEW |