22#include "gmock/gmock.h"
23#include "gtest/gtest.h"
29using ::testing::NiceMock;
38class AccessibilityBridgeWindowsSpy :
public AccessibilityBridgeWindows {
42 explicit AccessibilityBridgeWindowsSpy(FlutterWindowsEngine*
engine,
43 FlutterWindowsView*
view)
44 : AccessibilityBridgeWindows(
view) {}
46 void DispatchWinAccessibilityEvent(
47 std::shared_ptr<FlutterPlatformNodeDelegateWindows>
node_delegate,
52 void SetFocus(std::shared_ptr<FlutterPlatformNodeDelegateWindows>
58 dispatched_events_.clear();
59 focused_nodes_.clear();
62 const std::vector<MsaaEvent>& dispatched_events()
const {
63 return dispatched_events_;
66 const std::vector<int32_t> focused_nodes()
const {
67 std::vector<int32_t> ids;
68 std::transform(focused_nodes_.begin(), focused_nodes_.end(),
69 std::back_inserter(ids),
70 [](std::shared_ptr<FlutterPlatformNodeDelegate> node) {
71 return node->GetAXNode()->id();
77 std::weak_ptr<FlutterPlatformNodeDelegate> GetFocusedNode()
override {
78 return focused_nodes_.back();
82 std::vector<MsaaEvent> dispatched_events_;
83 std::vector<std::shared_ptr<FlutterPlatformNodeDelegate>> focused_nodes_;
90class FlutterWindowsViewSpy :
public FlutterWindowsView {
92 FlutterWindowsViewSpy(FlutterWindowsEngine*
engine,
93 std::unique_ptr<WindowBindingHandler>
handler)
97 virtual std::shared_ptr<AccessibilityBridgeWindows>
98 CreateAccessibilityBridge()
override {
99 return std::make_shared<AccessibilityBridgeWindowsSpy>(GetEngine(),
this);
109std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
111 properties.
assets_path = L
"C:\\foo\\flutter_assets";
114 FlutterProjectBundle project(properties);
115 auto engine = std::make_unique<FlutterWindowsEngine>(project);
117 EngineModifier modifier(
engine.get());
118 modifier.embedder_api().UpdateSemanticsEnabled =
124 std::make_shared<MockKeyResponseController>());
140void PopulateAXTree(std::shared_ptr<AccessibilityBridge> bridge) {
144 std::vector<int32_t> node0_children{1, 2};
145 node0.child_count = node0_children.size();
146 node0.children_in_traversal_order = node0_children.data();
147 node0.children_in_hit_test_order = node0_children.data();
148 node0.flags2 = &empty_flags;
152 node1.
label =
"prefecture";
153 node1.value =
"Kyoto";
154 node1.flags2 = &empty_flags;
158 std::vector<int32_t> node2_children{3, 4};
160 node2.children_in_traversal_order = node2_children.data();
161 node2.children_in_hit_test_order = node2_children.data();
162 node2.flags2 = &empty_flags;
166 node3.
label =
"city";
168 node3.flags2 = &empty_flags;
172 node4.
flags2 = &empty_flags;
174 bridge->AddFlutterSemanticsNodeUpdate(node0);
175 bridge->AddFlutterSemanticsNodeUpdate(node1);
176 bridge->AddFlutterSemanticsNodeUpdate(node2);
177 bridge->AddFlutterSemanticsNodeUpdate(node3);
178 bridge->AddFlutterSemanticsNodeUpdate(node4);
179 bridge->CommitUpdates();
182ui::AXNode* AXNodeFromID(std::shared_ptr<AccessibilityBridge> bridge,
184 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(
id).lock();
188std::shared_ptr<AccessibilityBridgeWindowsSpy> GetAccessibilityBridgeSpy(
189 FlutterWindowsView&
view) {
190 return std::static_pointer_cast<AccessibilityBridgeWindowsSpy>(
191 view.accessibility_bridge().lock());
194void ExpectWinEventFromAXEvent(int32_t node_id,
197 auto engine = GetTestEngine();
198 FlutterWindowsViewSpy
view{
199 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
200 EngineModifier modifier{
engine.get()};
201 modifier.SetImplicitView(&
view);
202 view.OnUpdateSemanticsEnabled(
true);
204 auto bridge = GetAccessibilityBridgeSpy(
view);
205 PopulateAXTree(bridge);
207 bridge->ResetRecords();
208 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, node_id),
210 ASSERT_EQ(bridge->dispatched_events().size(), 1);
211 EXPECT_EQ(bridge->dispatched_events()[0].event_type, expected_event);
214void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,
218 auto engine = GetTestEngine();
219 FlutterWindowsViewSpy
view{
220 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
221 EngineModifier modifier{
engine.get()};
222 modifier.SetImplicitView(&
view);
223 view.OnUpdateSemanticsEnabled(
true);
225 auto bridge = GetAccessibilityBridgeSpy(
view);
226 PopulateAXTree(bridge);
228 bridge->ResetRecords();
229 auto focus_delegate =
230 bridge->GetFlutterPlatformNodeDelegateFromID(focus_id).lock();
231 bridge->SetFocus(std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
233 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, node_id),
235 ASSERT_EQ(bridge->dispatched_events().size(), 1);
236 EXPECT_EQ(bridge->dispatched_events()[0].event_type, expected_event);
237 EXPECT_EQ(bridge->dispatched_events()[0].node_delegate->GetAXNode()->id(),
244 auto engine = GetTestEngine();
245 FlutterWindowsViewSpy
view{
246 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
248 modifier.SetImplicitView(&
view);
249 view.OnUpdateSemanticsEnabled(
true);
251 auto bridge =
view.accessibility_bridge().lock();
252 PopulateAXTree(bridge);
254 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
255 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
256 EXPECT_EQ(node0_delegate->GetNativeViewAccessible(),
257 node1_delegate->GetParent());
261 auto engine = GetTestEngine();
262 FlutterWindowsViewSpy
view{
263 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
265 modifier.SetImplicitView(&
view);
266 view.OnUpdateSemanticsEnabled(
true);
268 auto bridge =
view.accessibility_bridge().lock();
269 PopulateAXTree(bridge);
271 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
272 ASSERT_TRUE(node0_delegate->GetParent() ==
nullptr);
276 auto engine = GetTestEngine();
277 FlutterWindowsViewSpy
view{
278 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
280 modifier.SetImplicitView(&
view);
281 view.OnUpdateSemanticsEnabled(
true);
283 auto bridge =
view.accessibility_bridge().lock();
284 PopulateAXTree(bridge);
291 actual_action = info->
action;
311 auto engine = GetTestEngine();
312 FlutterWindowsViewSpy
view{
313 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
315 modifier.SetImplicitView(&
view);
316 view.OnUpdateSemanticsEnabled(
true);
318 auto bridge = GetAccessibilityBridgeSpy(
view);
319 PopulateAXTree(bridge);
321 bridge->ResetRecords();
322 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, 1),
326 ASSERT_EQ(bridge->dispatched_events().size(), 1);
327 EXPECT_EQ(bridge->dispatched_events()[0].event_type,
330 ASSERT_EQ(bridge->focused_nodes().size(), 1);
331 EXPECT_EQ(bridge->focused_nodes()[0], 1);
341 ExpectWinEventFromAXEvent(
357 ExpectWinEventFromAXEvent(
363 ExpectWinEventFromAXEvent(
374 ExpectWinEventFromAXEvent(
390 ExpectWinEventFromAXEvent(
396 ExpectWinEventFromAXEventOnFocusNode(
std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate
ax::mojom::Event event_type
void DispatchAccessibilityAction(AccessibilityNodeId target, FlutterSemanticsAction action, fml::MallocMapping data) override
Dispatch accessibility action back to the Flutter framework. These actions are generated in the nativ...
void OnAccessibilityEvent(ui::AXEventGenerator::TargetedEvent targeted_event) override
Handle accessibility events generated due to accessibility tree changes. These events are needed to b...
@ DOCUMENT_SELECTION_CHANGED
@ SCROLL_HORIZONTAL_POSITION_CHANGED
@ IMAGE_ANNOTATION_CHANGED
@ WIN_IACCESSIBLE_STATE_CHANGED
@ SCROLL_VERTICAL_POSITION_CHANGED
@ SELECTED_CHILDREN_CHANGED
#define FLUTTER_API_SYMBOL(symbol)
@ kFlutterSemanticsActionCopy
Copy the current selection to the clipboard.
@ kFlutterSemanticsActionTap
const gchar FlBinaryMessengerMessageHandler handler
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
@ kSelectedChildrenChanged
@ kDocumentSelectionChanged
void MockEmbedderApiForKeyboard(EngineModifier &modifier, std::shared_ptr< MockKeyResponseController > response_controller)
TEST(NativeAssetsManagerTest, NoAvailableAssets)
constexpr int64_t kImplicitViewId
#define MOCK_ENGINE_PROC(proc, mock_impl)
const char * aot_library_path
const char * icu_data_path
size_t child_count
The number of children this node has.
const char * label
A textual description of the node.
FlutterSemanticsFlags * flags2
FlutterSemanticsAction action
The semantics action.