Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: ios/chrome/browser/metrics/mobile_session_shutdown_metrics_provider_unittest.mm

Issue 1859213002: Move the thread hop for UMA user actions from content:: to base::. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initializing in content. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
13 #include "base/test/test_simple_task_runner.h"
12 #include "components/metrics/metrics_pref_names.h" 14 #include "components/metrics/metrics_pref_names.h"
13 #include "components/metrics/metrics_service.h" 15 #include "components/metrics/metrics_service.h"
14 #include "components/metrics/metrics_state_manager.h" 16 #include "components/metrics/metrics_state_manager.h"
15 #include "components/metrics/test_metrics_service_client.h" 17 #include "components/metrics/test_metrics_service_client.h"
16 #include "components/prefs/testing_pref_service.h" 18 #include "components/prefs/testing_pref_service.h"
17 #include "testing/gtest/include/gtest/gtest-param-test.h" 19 #include "testing/gtest/include/gtest/gtest-param-test.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 namespace { 22 namespace {
21 23
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 bool has_crash_logs_; 66 bool has_crash_logs_;
65 bool has_uploaded_crash_reports_in_background_; 67 bool has_uploaded_crash_reports_in_background_;
66 bool received_memory_warning_before_last_shutdown_; 68 bool received_memory_warning_before_last_shutdown_;
67 69
68 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderForTesting); 70 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderForTesting);
69 }; 71 };
70 72
71 class MobileSessionShutdownMetricsProviderTest 73 class MobileSessionShutdownMetricsProviderTest
72 : public testing::TestWithParam<int> { 74 : public testing::TestWithParam<int> {
73 public: 75 public:
74 MobileSessionShutdownMetricsProviderTest() { 76 MobileSessionShutdownMetricsProviderTest()
77 : task_runner_(new base::TestSimpleTaskRunner) {
78 base::SetRecordActionTaskRunner(task_runner_);
75 metrics::MetricsService::RegisterPrefs(local_state_.registry()); 79 metrics::MetricsService::RegisterPrefs(local_state_.registry());
76 } 80 }
77 81
78 protected: 82 protected:
79 TestingPrefServiceSimple local_state_; 83 TestingPrefServiceSimple local_state_;
80 metrics::TestMetricsServiceClient metrics_client_; 84 metrics::TestMetricsServiceClient metrics_client_;
81 std::unique_ptr<metrics::MetricsStateManager> metrics_state_; 85 std::unique_ptr<metrics::MetricsStateManager> metrics_state_;
82 std::unique_ptr<metrics::MetricsService> metrics_service_; 86 std::unique_ptr<metrics::MetricsService> metrics_service_;
83 std::unique_ptr<MobileSessionShutdownMetricsProviderForTesting> 87 std::unique_ptr<MobileSessionShutdownMetricsProviderForTesting>
84 metrics_provider_; 88 metrics_provider_;
89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85 90
86 private: 91 private:
87 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest); 92 DISALLOW_COPY_AND_ASSIGN(MobileSessionShutdownMetricsProviderTest);
88 }; 93 };
89 94
90 // Verifies that a sample is recorded in the correct bucket of the shutdown type 95 // Verifies that a sample is recorded in the correct bucket of the shutdown type
91 // histogram when ProvideStabilityMetrics is invoked. 96 // histogram when ProvideStabilityMetrics is invoked.
92 // 97 //
93 // This parameterized test receives a parameter in the range [0, 32), which is 98 // This parameterized test receives a parameter in the range [0, 32), which is
94 // used to generate values for five booleans based on the binary representation 99 // used to generate values for five booleans based on the binary representation
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Now call the method under test and verify exactly one sample is written to 180 // Now call the method under test and verify exactly one sample is written to
176 // the expected bucket. 181 // the expected bucket.
177 metrics_provider_->ProvideInitialStabilityMetrics(nullptr); 182 metrics_provider_->ProvideInitialStabilityMetrics(nullptr);
178 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType", 183 histogram_tester.ExpectUniqueSample("Stability.MobileSessionShutdownType",
179 expected_buckets[GetParam()], 1); 184 expected_buckets[GetParam()], 1);
180 } 185 }
181 186
182 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */, 187 INSTANTIATE_TEST_CASE_P(/* No InstantiationName */,
183 MobileSessionShutdownMetricsProviderTest, 188 MobileSessionShutdownMetricsProviderTest,
184 testing::Range(0, 32)); 189 testing::Range(0, 32));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698