highlighter_controller_test_api.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2017 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_HIGHLIGHTER_HIGHLIGHTER_CONTROLLER_TEST_API_H_
  5. #define ASH_HIGHLIGHTER_HIGHLIGHTER_CONTROLLER_TEST_API_H_
  6. #include "ash/highlighter/highlighter_controller.h"
  7. #include "base/scoped_observation.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace fast_ink {
  10. class FastInkPoints;
  11. }
  12. namespace ash {
  13. // An api for testing the HighlighterController class.
  14. // Implements ash::mojom::HighlighterControllerClient and binds itself as the
  15. // client to provide the tests with access to gesture recognition results.
  16. class HighlighterControllerTestApi : public HighlighterController::Observer {
  17. public:
  18. explicit HighlighterControllerTestApi(HighlighterController* instance);
  19. HighlighterControllerTestApi(const HighlighterControllerTestApi&) = delete;
  20. HighlighterControllerTestApi& operator=(const HighlighterControllerTestApi&) =
  21. delete;
  22. ~HighlighterControllerTestApi() override;
  23. // Attaches itself as the client to the controller. This method is called
  24. // automatically from the constructor, and should be explicitly called only
  25. // if DetachClient has been called previously.
  26. void AttachClient();
  27. // Detaches itself from the controller.
  28. void DetachClient();
  29. void SetEnabled(bool enabled);
  30. void DestroyPointerView();
  31. void SimulateInterruptedStrokeTimeout();
  32. bool IsShowingHighlighter() const;
  33. bool IsFadingAway() const;
  34. bool IsWaitingToResumeStroke() const;
  35. bool IsShowingSelectionResult() const;
  36. const fast_ink::FastInkPoints& points() const;
  37. const fast_ink::FastInkPoints& predicted_points() const;
  38. void ResetEnabledState() { handle_enabled_state_changed_called_ = false; }
  39. bool HandleEnabledStateChangedCalled();
  40. bool enabled() const { return enabled_; }
  41. void ResetSelection() { handle_selection_called_ = false; }
  42. bool HandleSelectionCalled();
  43. const gfx::Rect& selection() const { return selection_; }
  44. private:
  45. using ScopedObservation =
  46. base::ScopedObservation<HighlighterController,
  47. HighlighterController::Observer>;
  48. // HighlighterSelectionObserver:
  49. void OnHighlighterSelectionRecognized(const gfx::Rect& rect) override;
  50. void OnHighlighterEnabledChanged(HighlighterEnabledState state) override;
  51. std::unique_ptr<ScopedObservation> scoped_observation_;
  52. HighlighterController* instance_;
  53. bool handle_selection_called_ = false;
  54. bool handle_enabled_state_changed_called_ = false;
  55. gfx::Rect selection_;
  56. bool enabled_ = false;
  57. };
  58. } // namespace ash
  59. #endif // ASH_HIGHLIGHTER_HIGHLIGHTER_CONTROLLER_TEST_API_H_