1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_ 6 #define COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_ 7 8 #include "base/metrics/histogram_snapshot_manager.h" 9 #include "components/metrics/metrics_provider.h" 10 11 namespace metrics { 12 13 // A simple implementation of MetricsProvider that checks that its providing 14 // functions are called, for use in tests. 15 class TestMetricsProvider : public MetricsProvider { 16 public: 17 TestMetricsProvider() = default; 18 19 TestMetricsProvider(const TestMetricsProvider&) = delete; 20 TestMetricsProvider& operator=(const TestMetricsProvider&) = delete; 21 22 // MetricsProvider: 23 void Init() override; 24 void OnRecordingDisabled() override; 25 bool HasPreviousSessionData() override; 26 void ProvidePreviousSessionData( 27 ChromeUserMetricsExtension* uma_proto) override; 28 void ProvideCurrentSessionData( 29 ChromeUserMetricsExtension* uma_proto) override; 30 void ProvideSystemProfileMetrics( 31 SystemProfileProto* system_profile_proto) override; 32 void RecordInitialHistogramSnapshots( 33 base::HistogramSnapshotManager* snapshot_manager) override; 34 void RecordHistogramSnapshots( 35 base::HistogramSnapshotManager* snapshot_manager) override; 36 init_called()37 bool init_called() { return init_called_; } on_recording_disabled_called()38 bool on_recording_disabled_called() { return on_recording_disabled_called_; } has_initial_stability_metrics_called()39 bool has_initial_stability_metrics_called() { 40 return has_initial_stability_metrics_called_; 41 } set_has_initial_stability_metrics(bool has_initial_stability_metrics)42 void set_has_initial_stability_metrics(bool has_initial_stability_metrics) { 43 has_initial_stability_metrics_ = has_initial_stability_metrics; 44 } provide_initial_stability_metrics_called()45 bool provide_initial_stability_metrics_called() const { 46 return provide_initial_stability_metrics_called_; 47 } provide_stability_metrics_called()48 bool provide_stability_metrics_called() const { 49 return provide_stability_metrics_called_; 50 } provide_system_profile_metrics_called()51 bool provide_system_profile_metrics_called() const { 52 return provide_system_profile_metrics_called_; 53 } record_initial_histogram_snapshots_called()54 bool record_initial_histogram_snapshots_called() const { 55 return record_initial_histogram_snapshots_called_; 56 } record_histogram_snapshots_called()57 bool record_histogram_snapshots_called() const { 58 return record_histogram_snapshots_called_; 59 } set_record_histogram_snapshots_called(bool val)60 void set_record_histogram_snapshots_called(bool val) { 61 record_histogram_snapshots_called_ = val; 62 } 63 64 private: 65 bool init_called_ = false; 66 bool on_recording_disabled_called_ = false; 67 bool has_initial_stability_metrics_ = false; 68 bool has_initial_stability_metrics_called_ = false; 69 bool provide_initial_stability_metrics_called_ = false; 70 bool provide_stability_metrics_called_ = false; 71 bool provide_system_profile_metrics_called_ = false; 72 bool record_initial_histogram_snapshots_called_ = false; 73 bool record_histogram_snapshots_called_ = false; 74 }; 75 76 } // namespace metrics 77 78 #endif // COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_ 79