1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
fuchsia_web / webengine / browser / mock_virtual_keyboard.h [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FUCHSIA_WEB_WEBENGINE_BROWSER_MOCK_VIRTUAL_KEYBOARD_H_
#define FUCHSIA_WEB_WEBENGINE_BROWSER_MOCK_VIRTUAL_KEYBOARD_H_
#include <fidl/fuchsia.input.virtualkeyboard/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include <optional>
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/test_component_context_for_process.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"
class MockVirtualKeyboardController
: public fidl::Server<fuchsia_input_virtualkeyboard::Controller> {
public:
MockVirtualKeyboardController();
~MockVirtualKeyboardController() override;
MockVirtualKeyboardController(MockVirtualKeyboardController&) = delete;
MockVirtualKeyboardController operator=(MockVirtualKeyboardController&) =
delete;
void Bind(fuchsia_ui_views::ViewRef view_ref,
fuchsia_input_virtualkeyboard::TextType text_type,
fidl::ServerEnd<fuchsia_input_virtualkeyboard::Controller>
controller_server_end);
// Spins a RunLoop until the client calls WatchVisibility().
void AwaitWatchAndRespondWith(bool is_visible);
const fuchsia_ui_views::ViewRef& view_ref() const { return view_ref_; }
fuchsia_input_virtualkeyboard::TextType text_type() const {
return text_type_;
}
// fuchsia_input_virtualkeyboard::Controller implementation.
MOCK_METHOD1(RequestShow, void(RequestShowCompleter::Sync&));
MOCK_METHOD1(RequestHide, void(RequestHideCompleter::Sync&));
MOCK_METHOD2(SetTextType,
void(SetTextTypeRequest&, SetTextTypeCompleter::Sync&));
private:
// fuchsia_input_virtualkeyboard::Controller implementation.
void WatchVisibility(WatchVisibilityCompleter::Sync& completer) final;
base::OnceClosure on_watch_visibility_;
std::optional<fidl::Server<fuchsia_input_virtualkeyboard::Controller>::
WatchVisibilityCompleter::Async>
watch_visibility_completer_;
fuchsia_ui_views::ViewRef view_ref_;
fuchsia_input_virtualkeyboard::TextType text_type_;
std::optional<fidl::ServerBinding<fuchsia_input_virtualkeyboard::Controller>>
binding_;
};
// Services connection requests for MockVirtualKeyboardControllers.
class MockVirtualKeyboardControllerCreator
: public fidl::Server<fuchsia_input_virtualkeyboard::ControllerCreator> {
public:
explicit MockVirtualKeyboardControllerCreator(
base::TestComponentContextForProcess* component_context);
~MockVirtualKeyboardControllerCreator() override;
MockVirtualKeyboardControllerCreator(MockVirtualKeyboardControllerCreator&) =
delete;
MockVirtualKeyboardControllerCreator operator=(
MockVirtualKeyboardControllerCreator&) = delete;
// Returns an unbound MockVirtualKeyboardController, which will later be
// connected when |this| handles a call to the FIDL method Create().
// The MockVirtualKeyboardController must not be destroyed before |this|.
std::unique_ptr<MockVirtualKeyboardController> CreateController();
private:
// fuchsia_input_virtualkeyboard implementation.
void Create(CreateRequest& request, CreateCompleter::Sync& completer) final;
raw_ptr<MockVirtualKeyboardController> pending_controller_ = nullptr;
base::ScopedNaturalServiceBinding<
fuchsia_input_virtualkeyboard::ControllerCreator>
binding_;
};
#endif // FUCHSIA_WEB_WEBENGINE_BROWSER_MOCK_VIRTUAL_KEYBOARD_H_