@@ -86,6 +86,17 @@ void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {}
8686 void OnPlatformViewUnregisterTexture (int64_t texture_id) override {}
8787 void OnPlatformViewMarkTextureFrameAvailable (int64_t texture_id) override {}
8888};
89+
90+ class MockIosDelegate : public AccessibilityBridge ::IosDelegate {
91+ public:
92+ void PostAccessibilityNotification (UIAccessibilityNotifications notification,
93+ id argument) override {
94+ if (on_PostAccessibilityNotification_) {
95+ on_PostAccessibilityNotification_ (notification, argument);
96+ }
97+ }
98+ std::function<void (UIAccessibilityNotifications, id )> on_PostAccessibilityNotification_;
99+ };
89100} // namespace
90101} // namespace flutter
91102
@@ -238,4 +249,59 @@ - (void)testSemanticsDeallocated {
238249 XCTAssertNil (gMockPlatformView );
239250}
240251
252+ - (void )testAnnouncesRouteChanges {
253+ flutter::MockDelegate mock_delegate;
254+ auto thread_task_runner = CreateNewThread (" AccessibilityBridgeTest" );
255+ flutter::TaskRunners runners (/* label=*/ self.name .UTF8String ,
256+ /* platform=*/ thread_task_runner,
257+ /* raster=*/ thread_task_runner,
258+ /* ui=*/ thread_task_runner,
259+ /* io=*/ thread_task_runner);
260+ auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
261+ /* delegate=*/ mock_delegate,
262+ /* rendering_api=*/ flutter::IOSRenderingAPI::kSoftware ,
263+ /* task_runners=*/ runners);
264+ id mockFlutterView = OCMClassMock ([FlutterView class ]);
265+ std::string label = " some label" ;
266+
267+ NSMutableArray <NSDictionary <NSString *, id >*>* accessibility_notifications =
268+ [[[NSMutableArray alloc ] init ] autorelease ];
269+ auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
270+ ios_delegate->on_PostAccessibilityNotification_ =
271+ [accessibility_notifications](UIAccessibilityNotifications notification, id argument) {
272+ [accessibility_notifications addObject: @{
273+ @" notification" : @(notification),
274+ @" argument" : argument ? argument : [NSNull null ],
275+ }];
276+ };
277+ __block auto bridge =
278+ std::make_unique<flutter::AccessibilityBridge>(/* view=*/ mockFlutterView,
279+ /* platform_view=*/ platform_view.get (),
280+ /* platform_views_controller=*/ nil ,
281+ /* ios_delegate=*/ std::move (ios_delegate));
282+
283+ flutter::CustomAccessibilityActionUpdates actions;
284+ flutter::SemanticsNodeUpdates nodes;
285+
286+ flutter::SemanticsNode route_node;
287+ route_node.id = 1 ;
288+ route_node.label = label;
289+ route_node.flags = static_cast <int32_t >(flutter::SemanticsFlags::kScopesRoute ) |
290+ static_cast <int32_t >(flutter::SemanticsFlags::kNamesRoute );
291+ route_node.label = " route" ;
292+ nodes[route_node.id ] = route_node;
293+ flutter::SemanticsNode root_node;
294+ root_node.id = kRootNodeId ;
295+ root_node.label = label;
296+ root_node.childrenInTraversalOrder = {1 };
297+ root_node.childrenInHitTestOrder = {1 };
298+ nodes[root_node.id ] = root_node;
299+ bridge->UpdateSemantics (/* nodes=*/ nodes, /* actions=*/ actions);
300+
301+ XCTAssertEqual ([accessibility_notifications count ], 1ul );
302+ XCTAssertEqualObjects (accessibility_notifications[0 ][@" argument" ], @" route" );
303+ XCTAssertEqual ([accessibility_notifications[0 ][@" notification" ] unsignedIntValue ],
304+ UIAccessibilityScreenChangedNotification);
305+ }
306+
241307@end
0 commit comments