| 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> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 bool has_crash_logs_; | 62 bool has_crash_logs_; |
| 63 bool has_uploaded_crash_reports_in_background_; | 63 bool has_uploaded_crash_reports_in_background_; |
| 64 bool received_memory_warning_before_last_shutdown_; | 64 bool received_memory_warning_before_last_shutdown_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderForTesting); | 66 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderForTesting); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class MobileSessionShutdownMetricsProviderTest | 69 class MobileSessionShutdownMetricsProviderTest |
| 70 : public testing::TestWithParam<int> { | 70 : public testing::TestWithParam<int> { |
| 71 public: | 71 public: |
| 72 MobileSessionShutdownMetricsProviderTest() | 72 MobileSessionShutdownMetricsProviderTest() { |
| 73 : task_runner_(new base::TestSimpleTaskRunner) { | |
| 74 base::SetRecordActionTaskRunner(task_runner_); | |
| 75 metrics::MetricsService::RegisterPrefs(local_state_.registry()); | 73 metrics::MetricsService::RegisterPrefs(local_state_.registry()); |
| 76 } | 74 } |
| 77 | 75 |
| 78 protected: | 76 protected: |
| 79 TestingPrefServiceSimple local_state_; | 77 TestingPrefServiceSimple local_state_; |
| 80 metrics::TestMetricsServiceClient metrics_client_; | 78 metrics::TestMetricsServiceClient metrics_client_; |
| 81 std::unique_ptr<metrics::MetricsStateManager> metrics_state_; | 79 std::unique_ptr<metrics::MetricsStateManager> metrics_state_; |
| 82 std::unique_ptr<metrics::MetricsService> metrics_service_; | 80 std::unique_ptr<metrics::MetricsService> metrics_service_; |
| 83 std::unique_ptr<MobileSessionShutdownMetricsProviderForTesting> | 81 std::unique_ptr<MobileSessionShutdownMetricsProviderForTesting> |
| 84 metrics_provider_; | 82 metrics_provider_; |
| 85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 86 | 83 |
| 87 private: | 84 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest); | 85 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest); |
| 89 }; | 86 }; |
| 90 | 87 |
| 91 // Verifies that a sample is recorded in the correct bucket of the shutdown type | 88 // Verifies that a sample is recorded in the correct bucket of the shutdown type |
| 92 // histogram when ProvideStabilityMetrics is invoked. | 89 // histogram when ProvideStabilityMetrics is invoked. |
| 93 // | 90 // |
| 94 // This parameterized test receives a parameter in the range [0, 32), which is | 91 // This parameterized test receives a parameter in the range [0, 32), which is |
| 95 // used to generate values for five booleans based on the binary representation | 92 // 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... |
| 176 // Now call the method under test and verify exactly one sample is written to | 173 // Now call the method under test and verify exactly one sample is written to |
| 177 // the expected bucket. | 174 // the expected bucket. |
| 178 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); | 175 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); |
| 179 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", | 176 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", |
| 180 expected_buckets[GetParam()], 1); | 177 expected_buckets[GetParam()], 1); |
| 181 } | 178 } |
| 182 | 179 |
| 183 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, | 180 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, |
| 184 MobileSessionShutdownMetricsProviderTest, | 181 MobileSessionShutdownMetricsProviderTest, |
| 185 testing::Range(0, 32)); | 182 testing::Range(0, 32)); |
| OLD | NEW |