zoom_test_utils.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_ZOOM_TEST_ZOOM_TEST_UTILS_H_
  5. #define COMPONENTS_ZOOM_TEST_ZOOM_TEST_UTILS_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/zoom/zoom_controller.h"
  9. #include "components/zoom/zoom_observer.h"
  10. namespace content {
  11. class MessageLoopRunner;
  12. }
  13. namespace zoom {
  14. bool operator==(const ZoomController::ZoomChangedEventData& lhs,
  15. const ZoomController::ZoomChangedEventData& rhs);
  16. class ZoomChangedWatcher : public zoom::ZoomObserver {
  17. public:
  18. using ZoomEventPred = base::RepeatingCallback<bool(
  19. const ZoomController::ZoomChangedEventData&)>;
  20. // Used to wait until we see a zoom changed event that satisfies the
  21. // given |predicate|.
  22. ZoomChangedWatcher(ZoomController* zoom_controller, ZoomEventPred predicate);
  23. ZoomChangedWatcher(content::WebContents* web_contents,
  24. ZoomEventPred predicate);
  25. // Used to wait until we see a zoom changed event equal to the given
  26. // |expected_event_data|.
  27. ZoomChangedWatcher(
  28. ZoomController* zoom_controller,
  29. const ZoomController::ZoomChangedEventData& expected_event_data);
  30. ZoomChangedWatcher(
  31. content::WebContents* web_contents,
  32. const ZoomController::ZoomChangedEventData& expected_event_data);
  33. ZoomChangedWatcher(const ZoomChangedWatcher&) = delete;
  34. ZoomChangedWatcher& operator=(const ZoomChangedWatcher&) = delete;
  35. ~ZoomChangedWatcher() override;
  36. void Wait();
  37. // zoom::ZoomObserver:
  38. void OnZoomChanged(
  39. const ZoomController::ZoomChangedEventData& event_data) override;
  40. private:
  41. raw_ptr<ZoomController> zoom_controller_;
  42. ZoomEventPred predicate_;
  43. scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
  44. bool change_received_ = false;
  45. };
  46. } // namespace zoom
  47. #endif // COMPONENTS_ZOOM_TEST_ZOOM_TEST_UTILS_H_