| 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/ios_stability_metrics_provider.h" | 5 #include "ios/chrome/browser/metrics/ios_stability_metrics_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // least significant to most significant): | 93 // least significant to most significant): |
| 94 // - received memory warning; | 94 // - received memory warning; |
| 95 // - crash log present; | 95 // - crash log present; |
| 96 // - uploaded crash reports in background; | 96 // - uploaded crash reports in background; |
| 97 // - last shutdown was clean; | 97 // - last shutdown was clean; |
| 98 // - first launch after upgrade. | 98 // - first launch after upgrade. |
| 99 TEST_P(IOSStabilityMetricsProviderTest, ProvideStabilityMetrics) { | 99 TEST_P(IOSStabilityMetricsProviderTest, ProvideStabilityMetrics) { |
| 100 const bool received_memory_warning = GetParam() % 2; | 100 const bool received_memory_warning = GetParam() % 2; |
| 101 const bool has_crash_logs = (GetParam() >> 1) % 2; | 101 const bool has_crash_logs = (GetParam() >> 1) % 2; |
| 102 const bool has_uploaded_crash_reports_in_background = (GetParam() >> 2) % 2; | 102 const bool has_uploaded_crash_reports_in_background = (GetParam() >> 2) % 2; |
| 103 const bool was_last_shutdown_clean = (GetParam() >> 3) % 2; | 103 const bool is_first_launch_after_upgrade = (GetParam() >> 3) % 2; |
| 104 const bool is_first_launch_after_upgrade = (GetParam() >> 4) % 2; | 104 const bool was_last_shutdown_clean = (GetParam() >> 4) % 2; |
| 105 | 105 |
| 106 // Expected bucket for each possible value of GetParam(). | 106 // Expected bucket for each possible value of GetParam(). |
| 107 const MobileSessionShutdownType expected_buckets[] = { | 107 const MobileSessionShutdownType expected_buckets[] = { |
| 108 SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_NO_MEMORY_WARNING, | 108 SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_NO_MEMORY_WARNING, |
| 109 SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_WITH_MEMORY_WARNING, | 109 SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_WITH_MEMORY_WARNING, |
| 110 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, | 110 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, |
| 111 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, | 111 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, |
| 112 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, | 112 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, |
| 113 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, | 113 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, |
| 114 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, | 114 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING, |
| 115 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, | 115 SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING, |
| 116 // If wasLastShutdownClean is true, the memory warning and crash log don't | 116 // If firstLaunchAfterUpgrade is true, it is not possible to determine the |
| 117 // matter. | 117 // real reason of the crash, so the memory warning and crash log flags |
| 118 // don't matter. |
| 119 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 120 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 121 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 122 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 123 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 124 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 125 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 126 SHUTDOWN_IN_FOREGROUND_UNKNOWN_LOG_STATE, |
| 127 // If wasLastShutdownClean is true, the other flags don't matter. |
| 118 SHUTDOWN_IN_BACKGROUND, | 128 SHUTDOWN_IN_BACKGROUND, |
| 119 SHUTDOWN_IN_BACKGROUND, | 129 SHUTDOWN_IN_BACKGROUND, |
| 120 SHUTDOWN_IN_BACKGROUND, | 130 SHUTDOWN_IN_BACKGROUND, |
| 131 SHUTDOWN_IN_BACKGROUND, |
| 132 SHUTDOWN_IN_BACKGROUND, |
| 133 SHUTDOWN_IN_BACKGROUND, |
| 134 SHUTDOWN_IN_BACKGROUND, |
| 135 SHUTDOWN_IN_BACKGROUND, |
| 136 SHUTDOWN_IN_BACKGROUND, |
| 137 SHUTDOWN_IN_BACKGROUND, |
| 138 SHUTDOWN_IN_BACKGROUND, |
| 121 SHUTDOWN_IN_BACKGROUND, | 139 SHUTDOWN_IN_BACKGROUND, |
| 122 SHUTDOWN_IN_BACKGROUND, | 140 SHUTDOWN_IN_BACKGROUND, |
| 123 SHUTDOWN_IN_BACKGROUND, | 141 SHUTDOWN_IN_BACKGROUND, |
| 124 SHUTDOWN_IN_BACKGROUND, | 142 SHUTDOWN_IN_BACKGROUND, |
| 125 SHUTDOWN_IN_BACKGROUND, | 143 SHUTDOWN_IN_BACKGROUND, |
| 126 // If firstLaunchAfterUpgrade is true, the other flags don't matter. | |
| 127 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 128 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 129 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 130 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 131 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 132 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 133 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 134 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 135 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 136 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 137 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 138 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 139 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 140 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 141 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 142 FIRST_LAUNCH_AFTER_UPGRADE, | |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 // Setup the MetricsService. | 146 // Setup the MetricsService. |
| 146 local_state_.SetBoolean(metrics::prefs::kStabilityExitedCleanly, | 147 local_state_.SetBoolean(metrics::prefs::kStabilityExitedCleanly, |
| 147 was_last_shutdown_clean); | 148 was_last_shutdown_clean); |
| 148 metrics_state_ = metrics::MetricsStateManager::Create( | 149 metrics_state_ = metrics::MetricsStateManager::Create( |
| 149 &local_state_, base::Bind(&IsMetricsReportingEnabled), | 150 &local_state_, base::Bind(&IsMetricsReportingEnabled), |
| 150 metrics::MetricsStateManager::StoreClientInfoCallback(), | 151 metrics::MetricsStateManager::StoreClientInfoCallback(), |
| 151 metrics::MetricsStateManager::LoadClientInfoCallback()); | 152 metrics::MetricsStateManager::LoadClientInfoCallback()); |
| 152 metrics_service_.reset(new metrics::MetricsService( | 153 metrics_service_.reset(new metrics::MetricsService( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 172 // 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 |
| 173 // the expected bucket. | 174 // the expected bucket. |
| 174 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); | 175 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); |
| 175 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", | 176 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", |
| 176 expected_buckets[GetParam()], 1); | 177 expected_buckets[GetParam()], 1); |
| 177 } | 178 } |
| 178 | 179 |
| 179 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, | 180 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, |
| 180 IOSStabilityMetricsProviderTest, | 181 IOSStabilityMetricsProviderTest, |
| 181 testing::Range(0, 32)); | 182 testing::Range(0, 32)); |
| OLD | NEW |