fake_semantics_manager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2019 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 FUCHSIA_WEB_WEBENGINE_BROWSER_FAKE_SEMANTICS_MANAGER_H_
  5. #define FUCHSIA_WEB_WEBENGINE_BROWSER_FAKE_SEMANTICS_MANAGER_H_
  6. #include <fuchsia/accessibility/semantics/cpp/fidl.h>
  7. #include <fuchsia/accessibility/semantics/cpp/fidl_test_base.h>
  8. #include <fuchsia/ui/scenic/cpp/fidl.h>
  9. #include <lib/fidl/cpp/binding.h>
  10. #include "base/callback.h"
  11. #include "fuchsia_web/webengine/browser/fake_semantic_tree.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. class FakeSemanticsManager : public fuchsia::accessibility::semantics::testing::
  14. SemanticsManager_TestBase {
  15. public:
  16. FakeSemanticsManager();
  17. ~FakeSemanticsManager() override;
  18. FakeSemanticsManager(const FakeSemanticsManager&) = delete;
  19. FakeSemanticsManager& operator=(const FakeSemanticsManager&) = delete;
  20. bool is_view_registered() const { return view_ref_.reference.is_valid(); }
  21. bool is_listener_valid() const { return static_cast<bool>(listener_); }
  22. FakeSemanticTree* semantic_tree() { return &semantic_tree_; }
  23. int32_t num_actions_handled() { return num_actions_handled_; }
  24. int32_t num_actions_unhandled() { return num_actions_unhandled_; }
  25. // Directly call the listener to simulate Fuchsia setting the semantics mode.
  26. void SetSemanticsModeEnabled(bool is_enabled);
  27. // Pumps the message loop until the RegisterViewForSemantics() is called.
  28. void WaitUntilViewRegistered();
  29. // The value returned by hit testing is written to a class member. In the case
  30. // Run() times out, the function continues so we don't want to write to a
  31. // local variable.
  32. uint32_t HitTestAtPointSync(fuchsia::math::PointF target_point);
  33. // A helper function for RequestAccessibilityAction.
  34. void CheckNumActions();
  35. // TODO(crbug.com/1291330): Remove async RequestAccessibilityAction(), and
  36. // replace with RequestAccessibilityActionSync().
  37. // Request the client to perform |action| on the node with |node_id|.
  38. void RequestAccessibilityAction(
  39. uint32_t node_id,
  40. fuchsia::accessibility::semantics::Action action);
  41. // Request the client to perform |action| on the node with |node_id|.
  42. bool RequestAccessibilityActionSync(
  43. uint32_t node_id,
  44. fuchsia::accessibility::semantics::Action action);
  45. // Runs until |num_actions| accessibility actions have been handled.
  46. void RunUntilNumActionsHandledEquals(int32_t num_actions);
  47. // fuchsia::accessibility::semantics::SemanticsManager implementation.
  48. void RegisterViewForSemantics(
  49. fuchsia::ui::views::ViewRef view_ref,
  50. fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticListener>
  51. listener,
  52. fidl::InterfaceRequest<fuchsia::accessibility::semantics::SemanticTree>
  53. semantic_tree_request) final;
  54. void NotImplemented_(const std::string& name) final;
  55. private:
  56. fuchsia::ui::views::ViewRef view_ref_;
  57. fuchsia::accessibility::semantics::SemanticListenerPtr listener_;
  58. // This fake only supports one SemanticTree, unlike the real SemanticsManager
  59. // which can support many.
  60. FakeSemanticTree semantic_tree_;
  61. absl::optional<uint32_t> hit_test_result_;
  62. int32_t num_actions_handled_ = 0;
  63. int32_t num_actions_unhandled_ = 0;
  64. int32_t expected_num_actions_ = 0;
  65. base::RepeatingClosure on_expected_num_actions_;
  66. base::OnceClosure on_view_registered_;
  67. };
  68. #endif // FUCHSIA_WEB_WEBENGINE_BROWSER_FAKE_SEMANTICS_MANAGER_H_