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)
101 virtual std::shared_ptr<AccessibilityBridgeWindows>
102 CreateAccessibilityBridge()
override {
103 return std::make_shared<AccessibilityBridgeWindowsSpy>(GetEngine(),
this);
113std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
115 properties.
assets_path = L
"C:\\foo\\flutter_assets";
119 FlutterProjectBundle project(properties);
120 auto engine = std::make_unique<FlutterWindowsEngine>(project);
122 EngineModifier modifier(
engine.get());
123 modifier.embedder_api().UpdateSemanticsEnabled =
129 std::make_shared<MockKeyResponseController>());
145void PopulateAXTree(std::shared_ptr<AccessibilityBridge> bridge) {
149 std::vector<int32_t> node0_children{1, 2};
150 node0.child_count = node0_children.size();
151 node0.children_in_traversal_order = node0_children.data();
152 node0.children_in_hit_test_order = node0_children.data();
153 node0.flags2 = &empty_flags;
157 node1.
label =
"prefecture";
158 node1.value =
"Kyoto";
159 node1.flags2 = &empty_flags;
163 std::vector<int32_t> node2_children{3, 4};
165 node2.children_in_traversal_order = node2_children.data();
166 node2.children_in_hit_test_order = node2_children.data();
167 node2.flags2 = &empty_flags;
171 node3.
label =
"city";
173 node3.flags2 = &empty_flags;
177 node4.
flags2 = &empty_flags;
179 bridge->AddFlutterSemanticsNodeUpdate(node0);
180 bridge->AddFlutterSemanticsNodeUpdate(node1);
181 bridge->AddFlutterSemanticsNodeUpdate(node2);
182 bridge->AddFlutterSemanticsNodeUpdate(node3);
183 bridge->AddFlutterSemanticsNodeUpdate(node4);
184 bridge->CommitUpdates();
187ui::AXNode* AXNodeFromID(std::shared_ptr<AccessibilityBridge> bridge,
189 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(
id).lock();
193std::shared_ptr<AccessibilityBridgeWindowsSpy> GetAccessibilityBridgeSpy(
194 FlutterWindowsView& view) {
195 return std::static_pointer_cast<AccessibilityBridgeWindowsSpy>(
196 view.accessibility_bridge().lock());
199void ExpectWinEventFromAXEvent(int32_t node_id,
202 auto engine = GetTestEngine();
203 FlutterWindowsViewSpy
view{
204 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
205 EngineModifier modifier{
engine.get()};
206 modifier.SetImplicitView(&view);
207 view.OnUpdateSemanticsEnabled(
true);
209 auto bridge = GetAccessibilityBridgeSpy(view);
210 PopulateAXTree(bridge);
212 bridge->ResetRecords();
213 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, node_id),
215 ASSERT_EQ(bridge->dispatched_events().size(), 1);
216 EXPECT_EQ(bridge->dispatched_events()[0].event_type, expected_event);
219void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,
223 auto engine = GetTestEngine();
224 FlutterWindowsViewSpy
view{
225 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
226 EngineModifier modifier{
engine.get()};
227 modifier.SetImplicitView(&view);
228 view.OnUpdateSemanticsEnabled(
true);
230 auto bridge = GetAccessibilityBridgeSpy(view);
231 PopulateAXTree(bridge);
233 bridge->ResetRecords();
234 auto focus_delegate =
235 bridge->GetFlutterPlatformNodeDelegateFromID(focus_id).lock();
236 bridge->SetFocus(std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
238 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, node_id),
240 ASSERT_EQ(bridge->dispatched_events().size(), 1);
241 EXPECT_EQ(bridge->dispatched_events()[0].event_type, expected_event);
242 EXPECT_EQ(bridge->dispatched_events()[0].node_delegate->GetAXNode()->id(),
249 auto engine = GetTestEngine();
250 FlutterWindowsViewSpy
view{
251 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
253 modifier.SetImplicitView(&
view);
254 view.OnUpdateSemanticsEnabled(
true);
256 auto bridge =
view.accessibility_bridge().lock();
257 PopulateAXTree(bridge);
259 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
260 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
261 EXPECT_EQ(node0_delegate->GetNativeViewAccessible(),
262 node1_delegate->GetParent());
266 auto engine = GetTestEngine();
267 FlutterWindowsViewSpy
view{
268 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
270 modifier.SetImplicitView(&
view);
271 view.OnUpdateSemanticsEnabled(
true);
273 auto bridge =
view.accessibility_bridge().lock();
274 PopulateAXTree(bridge);
276 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
277 ASSERT_TRUE(node0_delegate->GetParent() ==
nullptr);
281 auto engine = GetTestEngine();
282 FlutterWindowsViewSpy
view{
283 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
285 modifier.SetImplicitView(&
view);
286 view.OnUpdateSemanticsEnabled(
true);
288 auto bridge =
view.accessibility_bridge().lock();
289 PopulateAXTree(bridge);
296 actual_action = info->
action;
316 auto engine = GetTestEngine();
317 FlutterWindowsViewSpy
view{
318 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
320 modifier.SetImplicitView(&
view);
321 view.OnUpdateSemanticsEnabled(
true);
323 auto bridge = GetAccessibilityBridgeSpy(
view);
324 PopulateAXTree(bridge);
326 bridge->ResetRecords();
327 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, 1),
331 ASSERT_EQ(bridge->dispatched_events().size(), 1);
332 EXPECT_EQ(bridge->dispatched_events()[0].event_type,
335 ASSERT_EQ(bridge->focused_nodes().size(), 1);
336 EXPECT_EQ(bridge->focused_nodes()[0], 1);
346 ExpectWinEventFromAXEvent(
362 ExpectWinEventFromAXEvent(
368 ExpectWinEventFromAXEvent(
379 ExpectWinEventFromAXEvent(
395 ExpectWinEventFromAXEvent(
401 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
FlutterDesktopImpellerSwitch impeller_switch
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.