throughput_report_checker.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 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 UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
  5. #define UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
  6. #include "base/bind.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "cc/metrics/frame_sequence_metrics.h"
  9. namespace ui {
  10. class AnimationThroughputReporterTestBase;
  11. class ThroughputReportChecker {
  12. public:
  13. using ReportRepeatingCallback = base::RepeatingCallback<void(
  14. const cc::FrameSequenceMetrics::CustomReportData&)>;
  15. using ReportOnceCallback = base::OnceCallback<void(
  16. const cc::FrameSequenceMetrics::CustomReportData&)>;
  17. explicit ThroughputReportChecker(
  18. AnimationThroughputReporterTestBase* test_base,
  19. bool fail_if_reported = false)
  20. : test_base_(test_base), fail_if_reported_(fail_if_reported) {}
  21. ThroughputReportChecker(const ThroughputReportChecker&) = delete;
  22. ThroughputReportChecker& operator=(const ThroughputReportChecker&) = delete;
  23. ~ThroughputReportChecker() = default;
  24. bool reported() const { return reported_; }
  25. void reset() { reported_ = false; }
  26. ReportRepeatingCallback repeating_callback() {
  27. return base::BindRepeating(&ThroughputReportChecker::OnReport,
  28. base::Unretained(this));
  29. }
  30. ReportOnceCallback once_callback() {
  31. return base::BindOnce(&ThroughputReportChecker::OnReport,
  32. base::Unretained(this));
  33. }
  34. // It waits until reported up to 5 seconds timeout. Returns true if it's
  35. // reported.
  36. bool WaitUntilReported();
  37. private:
  38. void OnReport(const cc::FrameSequenceMetrics::CustomReportData&);
  39. raw_ptr<AnimationThroughputReporterTestBase> test_base_;
  40. bool reported_ = false;
  41. bool fail_if_reported_ = false;
  42. };
  43. } // namespace ui
  44. #endif // UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_