Flutter Engine
The Flutter Engine
mock_injector_registry.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 FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_MOCK_INJECTOR_REGISTRY_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_MOCK_INJECTOR_REGISTRY_H_
7
8#include <fuchsia/ui/pointerinjector/cpp/fidl.h>
9#include <lib/fidl/cpp/binding_set.h>
10
11#include <unordered_map>
12
14
15// A test stub to act as the protocol server. A test can control what is sent
16// back by this server implementation, via the ScheduleCallback call.
17class MockInjectorRegistry : public fuchsia::ui::pointerinjector::Registry,
18 public fuchsia::ui::pointerinjector::Device {
19 public:
21 fidl::InterfaceRequest<fuchsia::ui::pointerinjector::Registry> registry)
22 : registry_(this, std::move(registry)) {}
23
24 // |fuchsia.ui.pointerinjector.Registry.Register|.
26 fuchsia::ui::pointerinjector::Config config,
27 fidl::InterfaceRequest<fuchsia::ui::pointerinjector::Device> injector,
28 RegisterCallback callback) override {
29 num_register_calls_++;
30 const uint32_t id = next_id_++;
31
32 auto [it, success] = bindings_.try_emplace(id, this, std::move(injector));
33
34 it->second.set_error_handler(
35 [this, id](zx_status_t status) { bindings_.erase(id); });
36
37 config_ = std::move(config);
38
39 callback();
40 }
41
42 // |fuchsia.ui.pointerinjector.Device.Inject|.
43 void Inject(std::vector<fuchsia::ui::pointerinjector::Event> events,
44 InjectCallback callback) override {
45 num_events_received_ += events.size();
46
47 for (auto& event : events) {
48 events_.push_back(std::move(event));
49 }
50
51 callback();
52 }
53
54 void ClearBindings() { bindings_.clear(); }
55
56 // Returns the |fuchsia::ui::pointerinjector::Config| received in the last
57 // |Register(...)| call.
58 const fuchsia::ui::pointerinjector::Config& config() const { return config_; }
59
60 // Returns all the |fuchsia::ui::pointerinjector::Event|s received from the
61 // |Inject(...)| calls.
62 const std::vector<fuchsia::ui::pointerinjector::Event>& events() const {
63 return events_;
64 }
65
66 uint32_t num_register_calls() { return num_register_calls_; }
67
68 size_t num_registered() { return bindings_.size(); }
69
70 uint32_t num_events_received() const { return num_events_received_; }
71
72 private:
73 uint32_t next_id_ = 0;
74
75 uint32_t num_events_received_ = 0;
76
77 uint32_t num_register_calls_ = 0;
78
79 fuchsia::ui::pointerinjector::Config config_;
80
81 std::vector<fuchsia::ui::pointerinjector::Event> events_;
82
83 std::unordered_map<uint32_t,
84 fidl::Binding<fuchsia::ui::pointerinjector::Device>>
85 bindings_;
86
87 fidl::Binding<fuchsia::ui::pointerinjector::Registry> registry_;
88
89 FML_DISALLOW_COPY_AND_ASSIGN(MockInjectorRegistry);
90};
91} // namespace flutter_runner::testing
92
93#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_MOCK_INJECTOR_REGISTRY_H_
void Inject(std::vector< fuchsia::ui::pointerinjector::Event > events, InjectCallback callback) override
void Register(fuchsia::ui::pointerinjector::Config config, fidl::InterfaceRequest< fuchsia::ui::pointerinjector::Device > injector, RegisterCallback callback) override
MockInjectorRegistry(fidl::InterfaceRequest< fuchsia::ui::pointerinjector::Registry > registry)
const std::vector< fuchsia::ui::pointerinjector::Event > & events() const
const fuchsia::ui::pointerinjector::Config & config() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlKeyEvent * event
Definition: ref_ptr.h:256