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" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
13 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
14 #include "components/metrics/metrics_pref_names.h" | 14 #include "components/metrics/metrics_pref_names.h" |
15 #include "components/metrics/metrics_service.h" | 15 #include "components/metrics/metrics_service.h" |
16 #include "components/metrics/metrics_state_manager.h" | 16 #include "components/metrics/metrics_state_manager.h" |
| 17 #include "components/metrics/test_enabled_state_provider.h" |
17 #include "components/metrics/test_metrics_service_client.h" | 18 #include "components/metrics/test_metrics_service_client.h" |
18 #include "components/prefs/testing_pref_service.h" | 19 #include "components/prefs/testing_pref_service.h" |
19 #include "testing/gtest/include/gtest/gtest-param-test.h" | 20 #include "testing/gtest/include/gtest/gtest-param-test.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace { | |
23 | |
24 bool IsMetricsReportingEnabled() { | |
25 return false; | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 // An MobileSessionShutdownMetricsProvider that returns fake values for the last | 23 // An MobileSessionShutdownMetricsProvider that returns fake values for the last |
31 // session environment query methods. | 24 // session environment query methods. |
32 class MobileSessionShutdownMetricsProviderForTesting | 25 class MobileSessionShutdownMetricsProviderForTesting |
33 : public MobileSessionShutdownMetricsProvider { | 26 : public MobileSessionShutdownMetricsProvider { |
34 public: | 27 public: |
35 explicit MobileSessionShutdownMetricsProviderForTesting( | 28 explicit MobileSessionShutdownMetricsProviderForTesting( |
36 metrics::MetricsService* metrics_service) | 29 metrics::MetricsService* metrics_service) |
37 : MobileSessionShutdownMetricsProvider(metrics_service) {} | 30 : MobileSessionShutdownMetricsProvider(metrics_service) {} |
38 | 31 |
39 void set_is_first_launch_after_upgrade(bool value) { | 32 void set_is_first_launch_after_upgrade(bool value) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 FIRST_LAUNCH_AFTER_UPGRADE, | 140 FIRST_LAUNCH_AFTER_UPGRADE, |
148 FIRST_LAUNCH_AFTER_UPGRADE, | 141 FIRST_LAUNCH_AFTER_UPGRADE, |
149 FIRST_LAUNCH_AFTER_UPGRADE, | 142 FIRST_LAUNCH_AFTER_UPGRADE, |
150 FIRST_LAUNCH_AFTER_UPGRADE, | 143 FIRST_LAUNCH_AFTER_UPGRADE, |
151 }; | 144 }; |
152 | 145 |
153 // Setup the MetricsService. | 146 // Setup the MetricsService. |
154 local_state_.SetBoolean(metrics::prefs::kStabilityExitedCleanly, | 147 local_state_.SetBoolean(metrics::prefs::kStabilityExitedCleanly, |
155 was_last_shutdown_clean); | 148 was_last_shutdown_clean); |
156 metrics_state_ = metrics::MetricsStateManager::Create( | 149 metrics_state_ = metrics::MetricsStateManager::Create( |
157 &local_state_, base::Bind(&IsMetricsReportingEnabled), | 150 &local_state_, new metrics::TestEnabledStateProvider(false, false), |
158 metrics::MetricsStateManager::StoreClientInfoCallback(), | 151 metrics::MetricsStateManager::StoreClientInfoCallback(), |
159 metrics::MetricsStateManager::LoadClientInfoCallback()); | 152 metrics::MetricsStateManager::LoadClientInfoCallback()); |
160 metrics_service_.reset(new metrics::MetricsService( | 153 metrics_service_.reset(new metrics::MetricsService( |
161 metrics_state_.get(), &metrics_client_, &local_state_)); | 154 metrics_state_.get(), &metrics_client_, &local_state_)); |
162 | 155 |
163 // Create the metrics provider to test. | 156 // Create the metrics provider to test. |
164 metrics_provider_.reset(new MobileSessionShutdownMetricsProviderForTesting( | 157 metrics_provider_.reset(new MobileSessionShutdownMetricsProviderForTesting( |
165 metrics_service_.get())); | 158 metrics_service_.get())); |
166 | 159 |
167 // Setup the metrics provider for the current test. | 160 // Setup the metrics provider for the current test. |
(...skipping 12 matching lines...) Expand all Loading... |
180 // 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 |
181 // the expected bucket. | 174 // the expected bucket. |
182 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); | 175 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); |
183 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", | 176 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", |
184 expected_buckets[GetParam()], 1); | 177 expected_buckets[GetParam()], 1); |
185 } | 178 } |
186 | 179 |
187 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, | 180 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, |
188 MobileSessionShutdownMetricsProviderTest, | 181 MobileSessionShutdownMetricsProviderTest, |
189 testing::Range(0, 32)); | 182 testing::Range(0, 32)); |
OLD | NEW |