Flutter Engine
flutter_runner_fakes.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 
5 #ifndef TOPAZ_RUNTIME_FLUTTER_RUNNER_PLATFORM_VIEW_FAKES_H_
6 #define TOPAZ_RUNTIME_FLUTTER_RUNNER_PLATFORM_VIEW_FAKES_H_
7 
8 #include <fuchsia/accessibility/semantics/cpp/fidl.h>
9 
10 namespace flutter_runner_test {
11 using fuchsia::accessibility::semantics::SemanticsManager;
12 
14  : public SemanticsManager,
15  public fuchsia::accessibility::semantics::SemanticTree {
16  public:
17  MockSemanticsManager() : tree_binding_(this) {}
18 
19  // |fuchsia::accessibility::semantics::SemanticsManager|:
21  fuchsia::ui::views::ViewRef view_ref,
22  fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticListener>
23  handle,
24  fidl::InterfaceRequest<fuchsia::accessibility::semantics::SemanticTree>
25  semantic_tree) override {
26  tree_binding_.Bind(std::move(semantic_tree));
27  has_view_ref_ = true;
28  }
29 
30  fidl::InterfaceRequestHandler<SemanticsManager> GetHandler(
31  async_dispatcher_t* dispatcher) {
32  return bindings_.GetHandler(this, dispatcher);
33  }
34 
35  bool RegisterViewCalled() { return has_view_ref_; }
36 
37  void ResetTree() {
38  update_count_ = 0;
39  delete_count_ = 0;
40  commit_count_ = 0;
41  last_updated_nodes_.clear();
42  last_deleted_node_ids_.clear();
43  delete_overflowed_ = false;
44  update_overflowed_ = false;
45  }
46 
48  std::vector<fuchsia::accessibility::semantics::Node> nodes) override {
49  update_count_++;
50  if (!update_overflowed_) {
51  size_t size = 0;
52  for (const auto& node : nodes) {
53  size += sizeof(node);
54  size += sizeof(node.attributes().label().size());
55  }
56  update_overflowed_ = size > ZX_CHANNEL_MAX_MSG_BYTES;
57  }
58  last_updated_nodes_ = std::move(nodes);
59  }
60 
61  void DeleteSemanticNodes(std::vector<uint32_t> node_ids) override {
62  delete_count_++;
63  if (!delete_overflowed_) {
64  size_t size =
65  sizeof(node_ids) +
67  delete_overflowed_ = size > ZX_CHANNEL_MAX_MSG_BYTES;
68  }
69  last_deleted_node_ids_ = std::move(node_ids);
70  }
71 
72  const std::vector<uint32_t>& LastDeletedNodeIds() const {
73  return last_deleted_node_ids_;
74  }
75 
76  int DeleteCount() const { return delete_count_; }
77  bool DeleteOverflowed() const { return delete_overflowed_; }
78 
79  int UpdateCount() const { return update_count_; }
80  bool UpdateOverflowed() const { return update_overflowed_; }
81 
82  int CommitCount() const { return commit_count_; }
83 
84  const std::vector<fuchsia::accessibility::semantics::Node>& LastUpdatedNodes()
85  const {
86  return last_updated_nodes_;
87  }
88 
89  void CommitUpdates(CommitUpdatesCallback callback) override {
90  commit_count_++;
91  }
92 
93  private:
94  bool has_view_ref_ = false;
95  fidl::BindingSet<SemanticsManager> bindings_;
96  fidl::Binding<SemanticTree> tree_binding_;
97 
98  std::vector<fuchsia::accessibility::semantics::Node> last_updated_nodes_;
99  bool update_overflowed_;
100  int update_count_;
101  int delete_count_;
102  bool delete_overflowed_;
103  std::vector<uint32_t> last_deleted_node_ids_;
104  int commit_count_;
105 };
106 
107 } // namespace flutter_runner_test
108 
109 #endif // TOPAZ_RUNTIME_FLUTTER_RUNNER_PLATFORM_VIEW_FAKES_H_
const std::vector< uint32_t > & LastDeletedNodeIds() const
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
void CommitUpdates(CommitUpdatesCallback callback) override
void DeleteSemanticNodes(std::vector< uint32_t > node_ids) override
fidl::InterfaceRequestHandler< SemanticsManager > GetHandler(async_dispatcher_t *dispatcher)
const std::vector< fuchsia::accessibility::semantics::Node > & LastUpdatedNodes() const
void UpdateSemanticNodes(std::vector< fuchsia::accessibility::semantics::Node > nodes) override
void RegisterViewForSemantics(fuchsia::ui::views::ViewRef view_ref, fidl::InterfaceHandle< fuchsia::accessibility::semantics::SemanticListener > handle, fidl::InterfaceRequest< fuchsia::accessibility::semantics::SemanticTree > semantic_tree) override