fake_semantic_tree.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_SEMANTIC_TREE_H_
  5. #define FUCHSIA_WEB_WEBENGINE_BROWSER_FAKE_SEMANTIC_TREE_H_
  6. #include <fuchsia/accessibility/semantics/cpp/fidl.h>
  7. #include <fuchsia/accessibility/semantics/cpp/fidl_test_base.h>
  8. #include <lib/fidl/cpp/binding.h>
  9. #include <unordered_map>
  10. #include "base/callback.h"
  11. #include "base/strings/string_piece_forward.h"
  12. class FakeSemanticTree
  13. : public fuchsia::accessibility::semantics::testing::SemanticTree_TestBase {
  14. public:
  15. FakeSemanticTree();
  16. ~FakeSemanticTree() override;
  17. FakeSemanticTree(const FakeSemanticTree&) = delete;
  18. FakeSemanticTree& operator=(const FakeSemanticTree&) = delete;
  19. // Binds |semantic_tree_request| to |this|.
  20. void Bind(
  21. fidl::InterfaceRequest<fuchsia::accessibility::semantics::SemanticTree>
  22. semantic_tree_request);
  23. // Checks that the tree is complete and that there are no dangling nodes by
  24. // traversing the tree starting at the root. Keeps track of how many nodes are
  25. // visited to make sure there aren't dangling nodes in |nodes_|.
  26. bool IsTreeValid(fuchsia::accessibility::semantics::Node* node,
  27. size_t* tree_size);
  28. // Disconnects the SemanticTree binding.
  29. void Disconnect();
  30. void RunUntilNodeCountAtLeast(size_t count);
  31. void RunUntilNodeWithLabelIsInTree(base::StringPiece label);
  32. void RunUntilCommitCountIs(size_t count);
  33. void RunUntilConditionIsTrue(base::RepeatingCallback<bool()> condition);
  34. void SetNodeUpdatedCallback(uint32_t node_id,
  35. base::OnceClosure node_updated_callback);
  36. fuchsia::accessibility::semantics::Node* GetNodeWithId(uint32_t id);
  37. // For both functions below, it is possible there are multiple nodes with the
  38. // same identifier.
  39. fuchsia::accessibility::semantics::Node* GetNodeFromLabel(
  40. base::StringPiece label);
  41. fuchsia::accessibility::semantics::Node* GetNodeFromRole(
  42. fuchsia::accessibility::semantics::Role role);
  43. size_t tree_size() const { return nodes_.size(); }
  44. void Clear();
  45. size_t num_delete_calls() const { return num_delete_calls_; }
  46. size_t num_update_calls() const { return num_update_calls_; }
  47. size_t num_commit_calls() const { return num_commit_calls_; }
  48. // fuchsia::accessibility::semantics::SemanticTree implementation.
  49. void UpdateSemanticNodes(
  50. std::vector<fuchsia::accessibility::semantics::Node> nodes) final;
  51. void DeleteSemanticNodes(std::vector<uint32_t> node_ids) final;
  52. void CommitUpdates(CommitUpdatesCallback callback) final;
  53. void NotImplemented_(const std::string& name) final;
  54. private:
  55. fidl::Binding<fuchsia::accessibility::semantics::SemanticTree>
  56. semantic_tree_binding_;
  57. std::unordered_map<uint32_t, fuchsia::accessibility::semantics::Node> nodes_;
  58. base::RepeatingClosure on_commit_updates_;
  59. uint32_t node_wait_id_;
  60. base::OnceClosure on_node_updated_callback_;
  61. size_t num_delete_calls_ = 0;
  62. size_t num_update_calls_ = 0;
  63. size_t num_commit_calls_ = 0;
  64. };
  65. #endif // FUCHSIA_WEB_WEBENGINE_BROWSER_FAKE_SEMANTIC_TREE_H_