test_metrics_provider.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_
  5. #define COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_
  6. #include "components/metrics/metrics_provider.h"
  7. namespace metrics {
  8. // A simple implementation of MetricsProvider that checks that its providing
  9. // functions are called, for use in tests.
  10. class TestMetricsProvider : public MetricsProvider {
  11. public:
  12. TestMetricsProvider() = default;
  13. TestMetricsProvider(const TestMetricsProvider&) = delete;
  14. TestMetricsProvider& operator=(const TestMetricsProvider&) = delete;
  15. // MetricsProvider:
  16. void Init() override;
  17. void OnRecordingDisabled() override;
  18. bool HasPreviousSessionData() override;
  19. void ProvidePreviousSessionData(
  20. ChromeUserMetricsExtension* uma_proto) override;
  21. void ProvideCurrentSessionData(
  22. ChromeUserMetricsExtension* uma_proto) override;
  23. void ProvideSystemProfileMetrics(
  24. SystemProfileProto* system_profile_proto) override;
  25. bool init_called() { return init_called_; }
  26. bool on_recording_disabled_called() { return on_recording_disabled_called_; }
  27. bool has_initial_stability_metrics_called() {
  28. return has_initial_stability_metrics_called_;
  29. }
  30. void set_has_initial_stability_metrics(bool has_initial_stability_metrics) {
  31. has_initial_stability_metrics_ = has_initial_stability_metrics;
  32. }
  33. bool provide_initial_stability_metrics_called() const {
  34. return provide_initial_stability_metrics_called_;
  35. }
  36. bool provide_stability_metrics_called() const {
  37. return provide_stability_metrics_called_;
  38. }
  39. bool provide_system_profile_metrics_called() const {
  40. return provide_system_profile_metrics_called_;
  41. }
  42. private:
  43. bool init_called_ = false;
  44. bool on_recording_disabled_called_ = false;
  45. bool has_initial_stability_metrics_ = false;
  46. bool has_initial_stability_metrics_called_ = false;
  47. bool provide_initial_stability_metrics_called_ = false;
  48. bool provide_stability_metrics_called_ = false;
  49. bool provide_system_profile_metrics_called_ = false;
  50. };
  51. } // namespace metrics
  52. #endif // COMPONENTS_METRICS_TEST_TEST_METRICS_PROVIDER_H_