task_switch_time_tracker_test_api.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 ASH_METRICS_TASK_SWITCH_TIME_TRACKER_TEST_API_H_
  5. #define ASH_METRICS_TASK_SWITCH_TIME_TRACKER_TEST_API_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/test/simple_test_tick_clock.h"
  9. #include "base/time/time.h"
  10. namespace ash {
  11. class TaskSwitchTimeTracker;
  12. // Provides access TaskSwitchTimeTracker's internals.
  13. class TaskSwitchTimeTrackerTestAPI {
  14. public:
  15. // Creates a TaskSwitchTimeTracker with the given |histogram_name| and injects
  16. // a base::SimpleTestTickClock that can be controlled.
  17. explicit TaskSwitchTimeTrackerTestAPI(const std::string& histogram_name);
  18. TaskSwitchTimeTrackerTestAPI(const TaskSwitchTimeTrackerTestAPI&) = delete;
  19. TaskSwitchTimeTrackerTestAPI& operator=(const TaskSwitchTimeTrackerTestAPI&) =
  20. delete;
  21. ~TaskSwitchTimeTrackerTestAPI();
  22. TaskSwitchTimeTracker* time_tracker() { return time_tracker_.get(); }
  23. // Advances |time_tracker_|'s TickClock by |time_delta|.
  24. void Advance(base::TimeDelta time_delta);
  25. // Wrapper function to access TaskSwitchTimeTracker::HasLastActionTime();
  26. bool HasLastActionTime() const;
  27. private:
  28. base::SimpleTestTickClock tick_clock_;
  29. // The TaskSwitchTimeTracker to provide internal access to.
  30. std::unique_ptr<TaskSwitchTimeTracker> time_tracker_;
  31. };
  32. } // namespace ash
  33. #endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKER_TEST_API_H_