5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
10 #import "flutter/fml/message_loop.h"
11 #import "flutter/fml/thread.h"
30 - (id)_accessibilityHitTest:(CGPoint)point withEvent:(UIEvent*)event;
37 - (instancetype)init {
52 @property(nonatomic, strong) UIView* view;
57 - (instancetype)init {
58 if (
self = [super init]) {
70 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
71 viewIdentifier:(int64_t)viewId
72 arguments:(
id _Nullable)args {
80 class MockDelegate :
public PlatformView::Delegate {
82 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override {}
83 void OnPlatformViewDestroyed()
override {}
84 void OnPlatformViewScheduleFrame()
override {}
85 void OnPlatformViewAddView(int64_t view_id,
86 const ViewportMetrics& viewport_metrics,
87 AddViewCallback callback)
override {}
88 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback)
override {}
89 void OnPlatformViewSendViewFocusEvent(
const ViewFocusEvent& event)
override {};
90 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override {}
91 void OnPlatformViewSetViewportMetrics(int64_t view_id,
const ViewportMetrics& metrics)
override {}
92 const flutter::Settings& OnPlatformViewGetSettings()
const override {
return settings_; }
93 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message)
override {}
94 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet)
override {
96 HitTestResponse OnPlatformViewHitTest(int64_t view_id,
const flutter::PointData offset)
override {
97 return {.has_platform_view =
false};
99 void OnPlatformViewDispatchSemanticsAction(int64_t view_id,
101 SemanticsAction action,
102 fml::MallocMapping args)
override {}
103 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override {}
104 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override {}
105 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture)
override {}
106 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override {}
107 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override {}
109 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
110 std::unique_ptr<const fml::Mapping> snapshot_data,
111 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override {
113 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
114 const std::string error_message,
115 bool transient)
override {}
116 void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
117 flutter::AssetResolver::AssetResolverType type)
override {}
118 std::shared_ptr<fml::BasicTaskRunner> OnPlatformViewGetShutdownSafeIOTaskRunner()
const override {
125 class MockIosDelegate :
public AccessibilityBridge::IosDelegate {
127 bool IsFlutterViewControllerPresentingModalViewController(
129 return result_IsFlutterViewControllerPresentingModalViewController_;
132 void PostAccessibilityNotification(UIAccessibilityNotifications notification,
133 id argument)
override {
134 if (on_PostAccessibilityNotification_) {
135 on_PostAccessibilityNotification_(notification, argument);
138 std::function<void(UIAccessibilityNotifications,
id)> on_PostAccessibilityNotification_;
139 bool result_IsFlutterViewControllerPresentingModalViewController_ =
false;
145 fml::RefPtr<fml::TaskRunner>
CreateNewThread(
const std::string& name) {
146 auto thread = std::make_unique<fml::Thread>(name);
147 auto runner = thread->GetTaskRunner();
157 flutter::SemanticsNodeUpdates nodes;
158 flutter::SemanticsNode semantics_node;
160 semantics_node.label = std::move(label);
161 nodes[kRootNodeId] = semantics_node;
162 flutter::CustomAccessibilityActionUpdates actions;
173 flutter::MockDelegate mock_delegate;
175 flutter::TaskRunners runners(
self.name.UTF8String,
180 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
184 std::make_shared<fml::SyncSwitch>());
186 std::make_unique<flutter::AccessibilityBridge>(nil,
189 XCTAssertTrue(bridge.get());
192 - (void)testSetViewControllerRebindsWhenSameViewControllerLoadsView {
193 flutter::MockDelegate mock_delegate;
195 flutter::TaskRunners runners(
self.name.UTF8String,
200 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
204 std::make_shared<fml::SyncSwitch>());
209 id mockFlutterView = OCMClassMock([
FlutterView class]);
210 __block UIView* viewIfLoaded = nil;
211 OCMStub([mockFlutterViewController viewIfLoaded]).andDo(^(NSInvocation* invocation) {
212 [invocation setReturnValue:&viewIfLoaded];
214 OCMStub([mockFlutterViewController
engine]).andReturn(
engine);
215 OCMStub([
engine binaryMessenger]).andReturn(messenger);
218 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
222 UpdateRootSemantics(bridge.get(),
"loaded later");
224 viewIfLoaded = mockFlutterView;
225 OCMExpect([mockFlutterView setAccessibilityElements:[OCMArg checkWithBlock:^BOOL(NSArray* value) {
226 if ([value count] != 1) {
234 return object.
uid ==
kRootNodeId &&
object.bridge == bridge_ptr &&
235 object.node.label ==
"loaded later";
237 bridge->SetViewController(mockFlutterViewController, nil);
238 OCMVerifyAll(mockFlutterView);
240 [engine stopMocking];
243 - (void)testUpdateSemanticsEmpty {
244 flutter::MockDelegate mock_delegate;
246 flutter::TaskRunners runners(
self.name.UTF8String,
251 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
255 std::make_shared<fml::SyncSwitch>());
256 id mockFlutterView = OCMClassMock([
FlutterView class]);
258 OCMStub([mockFlutterViewController viewIfLoaded]).andReturn(mockFlutterView);
259 OCMReject([mockFlutterView setAccessibilityElements:[OCMArg any]]);
261 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
264 flutter::SemanticsNodeUpdates nodes;
265 flutter::CustomAccessibilityActionUpdates actions;
266 bridge->UpdateSemantics(nodes, actions);
267 OCMVerifyAll(mockFlutterView);
268 bridge->SetViewController(nil, nil);
271 - (void)testUpdateSemanticsOneNode {
272 flutter::MockDelegate mock_delegate;
274 flutter::TaskRunners runners(
self.name.UTF8String,
279 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
283 std::make_shared<fml::SyncSwitch>());
284 id mockFlutterView = OCMClassMock([
FlutterView class]);
286 StubLoadedView(mockFlutterViewController, mockFlutterView);
287 std::string label =
"some label";
289 __block
auto bridge =
290 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
294 OCMExpect([mockFlutterView setAccessibilityElements:[OCMArg checkWithBlock:^BOOL(NSArray* value) {
295 if ([value count] != 1) {
301 object.bridge == bridge.get() &&
object.node.label == label;
305 flutter::SemanticsNodeUpdates nodes;
306 flutter::SemanticsNode semantics_node;
308 semantics_node.label = label;
309 nodes[kRootNodeId] = semantics_node;
310 flutter::CustomAccessibilityActionUpdates actions;
311 bridge->UpdateSemantics(nodes, actions);
312 OCMVerifyAll(mockFlutterView);
315 - (void)testSetViewControllerClearsPreviousViewAccessibilityElementsOwnedByBridge {
316 flutter::MockDelegate mock_delegate;
318 flutter::TaskRunners runners(
self.name.UTF8String,
323 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
327 std::make_shared<fml::SyncSwitch>());
328 UIView* previousView = [[UIView alloc] init];
329 UIView* nextView = [[UIView alloc] init];
332 StubLoadedView(previousViewController, previousView);
333 StubLoadedView(nextViewController, nextView);
336 std::make_unique<flutter::AccessibilityBridge>(previousViewController,
339 UpdateRootSemantics(bridge.get(),
"owned");
341 XCTAssertNotNil(previousView.accessibilityElements);
342 XCTAssertNil(nextView.accessibilityElements);
343 bridge->SetViewController(nextViewController,
static_cast<FlutterView*
>(previousView));
344 XCTAssertNil(previousView.accessibilityElements);
345 XCTAssertNotNil(nextView.accessibilityElements);
348 - (void)testSetViewControllerDoesNotClearPreviousViewElementsOwnedByAnotherBridge {
349 flutter::MockDelegate mock_delegate;
351 flutter::TaskRunners runners(
self.name.UTF8String,
356 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
360 std::make_shared<fml::SyncSwitch>());
361 UIView* previousView = [[UIView alloc] init];
362 UIView* nextView = [[UIView alloc] init];
363 UIView* otherView = [[UIView alloc] init];
367 StubLoadedView(previousViewController, previousView);
368 StubLoadedView(nextViewController, nextView);
369 StubLoadedView(otherViewController, otherView);
372 std::make_unique<flutter::AccessibilityBridge>(previousViewController,
376 std::make_unique<flutter::AccessibilityBridge>(otherViewController,
379 UpdateRootSemantics(bridge.get(),
"owned");
380 UpdateRootSemantics(other_bridge.get(),
"other");
381 NSArray* otherBridgeElements = otherView.accessibilityElements;
382 XCTAssertNotNil(otherBridgeElements);
383 previousView.accessibilityElements = otherBridgeElements;
385 bridge->SetViewController(nextViewController,
static_cast<FlutterView*
>(previousView));
386 XCTAssertEqual(previousView.accessibilityElements, otherBridgeElements);
389 - (void)testSetViewControllerDoesNotClearPreviousViewAccessibilityElementsOwnedByUIKit {
390 flutter::MockDelegate mock_delegate;
392 flutter::TaskRunners runners(
self.name.UTF8String,
397 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
401 std::make_shared<fml::SyncSwitch>());
402 UIView* previousView = [[UIView alloc] init];
403 UIView* nextView = [[UIView alloc] init];
406 StubLoadedView(previousViewController, previousView);
407 StubLoadedView(nextViewController, nextView);
410 std::make_unique<flutter::AccessibilityBridge>(previousViewController,
413 UIAccessibilityElement* nativeElement =
414 [[UIAccessibilityElement alloc] initWithAccessibilityContainer:previousView];
415 NSArray* nativeElements = @[ nativeElement ];
416 previousView.accessibilityElements = nativeElements;
418 bridge->SetViewController(nextViewController,
static_cast<FlutterView*
>(previousView));
419 XCTAssertEqual(previousView.accessibilityElements, nativeElements);
422 - (void)testSetViewControllerDoesNotClearMixedAccessibilityElements {
423 flutter::MockDelegate mock_delegate;
425 flutter::TaskRunners runners(
self.name.UTF8String,
430 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
434 std::make_shared<fml::SyncSwitch>());
435 UIView* previousView = [[UIView alloc] init];
436 UIView* nextView = [[UIView alloc] init];
439 StubLoadedView(previousViewController, previousView);
440 StubLoadedView(nextViewController, nextView);
443 std::make_unique<flutter::AccessibilityBridge>(previousViewController,
446 UpdateRootSemantics(bridge.get(),
"owned");
447 id bridgeElement = previousView.accessibilityElements.firstObject;
448 UIAccessibilityElement* nativeElement =
449 [[UIAccessibilityElement alloc] initWithAccessibilityContainer:previousView];
450 NSArray* mixedElements = @[ bridgeElement, nativeElement ];
451 previousView.accessibilityElements = mixedElements;
453 bridge->SetViewController(nextViewController,
static_cast<FlutterView*
>(previousView));
454 XCTAssertEqual(previousView.accessibilityElements, mixedElements);
455 XCTAssertNotNil(nextView.accessibilityElements);
458 - (void)testIsVoiceOverRunning {
459 flutter::MockDelegate mock_delegate;
461 flutter::TaskRunners runners(
self.name.UTF8String,
466 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
470 std::make_shared<fml::SyncSwitch>());
471 id mockFlutterView = OCMClassMock([
FlutterView class]);
473 StubLoadedView(mockFlutterViewController, mockFlutterView);
474 OCMStub([mockFlutterViewController isVoiceOverRunning]).andReturn(YES);
476 __block
auto bridge =
477 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
481 XCTAssertTrue(bridge->isVoiceOverRunning());
484 - (void)testSemanticsDeallocated {
486 flutter::MockDelegate mock_delegate;
488 flutter::TaskRunners runners(
self.name.UTF8String,
498 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
500 flutterPlatformViewsController,
502 std::make_shared<fml::SyncSwitch>());
503 id mockFlutterView = OCMClassMock([
FlutterView class]);
505 StubLoadedView(mockFlutterViewController, mockFlutterView);
506 std::string label =
"some label";
507 flutterPlatformViewsController.
flutterView = mockFlutterView;
510 [flutterPlatformViewsController
512 withId:@"MockFlutterPlatformView"
516 [flutterPlatformViewsController
520 @"viewType" : @"MockFlutterPlatformView"
524 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
525 mockFlutterViewController,
527 flutterPlatformViewsController);
529 flutter::SemanticsNodeUpdates nodes;
530 flutter::SemanticsNode semantics_node;
531 semantics_node.id = 2;
532 semantics_node.platformViewId = 2;
533 semantics_node.label = label;
534 nodes[kRootNodeId] = semantics_node;
535 flutter::CustomAccessibilityActionUpdates actions;
536 bridge->UpdateSemantics(nodes, actions);
538 [flutterPlatformViewsController
reset];
543 - (void)testSemanticsDeallocatedWithoutLoadingView {
548 flutter::MockDelegate mock_delegate;
550 flutter::TaskRunners runners(
self.name.UTF8String,
560 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
562 flutterPlatformViewsController,
564 std::make_shared<fml::SyncSwitch>());
567 [flutterPlatformViewsController
569 withId:@"MockFlutterPlatformView"
573 [flutterPlatformViewsController
577 @"viewType" : @"MockFlutterPlatformView"
581 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
582 flutterViewController,
584 flutterPlatformViewsController);
587 [flutterPlatformViewsController
reset];
591 XCTAssertNil(flutterViewController.viewIfLoaded);
592 [flutterViewController deregisterNotifications];
595 - (void)testReplacedSemanticsDoesNotCleanupChildren {
596 flutter::MockDelegate mock_delegate;
598 flutter::TaskRunners runners(
self.name.UTF8String,
608 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
610 flutterPlatformViewsController,
612 std::make_shared<fml::SyncSwitch>());
618 StubLoadedView(mockFlutterViewController, flutterView);
619 std::string label =
"some label";
620 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
621 mockFlutterViewController,
623 flutterPlatformViewsController);
625 flutter::SemanticsNodeUpdates nodes;
626 flutter::SemanticsNode parent;
628 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
629 parent.label =
"label";
630 parent.value =
"value";
631 parent.hint =
"hint";
633 flutter::SemanticsNode node;
635 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
636 node.label =
"label";
637 node.value =
"value";
639 node.scrollExtentMax = 100.0;
640 node.scrollPosition = 0.0;
641 parent.childrenInTraversalOrder.push_back(1);
642 parent.childrenInHitTestOrder.push_back(1);
644 flutter::SemanticsNode child;
646 child.rect = SkRect::MakeXYWH(0, 0, 100, 200);
647 child.label =
"label";
648 child.value =
"value";
650 node.childrenInTraversalOrder.push_back(2);
651 node.childrenInHitTestOrder.push_back(2);
656 flutter::CustomAccessibilityActionUpdates actions;
657 bridge->UpdateSemantics(nodes, actions);
660 flutter::SemanticsNodeUpdates new_nodes;
661 flutter::SemanticsNode new_node;
663 new_node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
664 new_node.flags.hasImplicitScrolling =
true;
665 new_node.actions = flutter::kHorizontalScrollSemanticsActions;
666 new_node.label =
"label";
667 new_node.value =
"value";
668 new_node.hint =
"hint";
669 new_node.scrollExtentMax = 100.0;
670 new_node.scrollPosition = 0.0;
671 new_node.childrenInTraversalOrder.push_back(2);
672 new_node.childrenInHitTestOrder.push_back(2);
674 new_nodes[1] = new_node;
675 bridge->UpdateSemantics(new_nodes, actions);
679 id rootContainer = flutterView.accessibilityElements[0];
680 XCTAssertTrue([rootContainer accessibilityElementCount] ==
682 id scrollableContainer = [rootContainer accessibilityElementAtIndex:1];
683 XCTAssertTrue([scrollableContainer accessibilityElementCount] ==
685 id child = [scrollableContainer accessibilityElementAtIndex:1];
687 XCTAssertNotNil([child accessibilityContainer]);
690 - (void)testScrollableSemanticsDeallocated {
691 flutter::MockDelegate mock_delegate;
693 flutter::TaskRunners runners(
self.name.UTF8String,
703 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
705 flutterPlatformViewsController,
707 std::make_shared<fml::SyncSwitch>());
713 StubLoadedView(mockFlutterViewController, flutterView);
714 std::string label =
"some label";
716 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
717 mockFlutterViewController,
719 flutterPlatformViewsController);
721 flutter::SemanticsNodeUpdates nodes;
722 flutter::SemanticsNode parent;
724 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
725 parent.label =
"label";
726 parent.value =
"value";
727 parent.hint =
"hint";
729 flutter::SemanticsNode node;
731 node.flags.hasImplicitScrolling =
true;
732 node.actions = flutter::kHorizontalScrollSemanticsActions;
733 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
734 node.label =
"label";
735 node.value =
"value";
737 node.scrollExtentMax = 100.0;
738 node.scrollPosition = 0.0;
739 parent.childrenInTraversalOrder.push_back(1);
740 parent.childrenInHitTestOrder.push_back(1);
743 flutter::CustomAccessibilityActionUpdates actions;
744 bridge->UpdateSemantics(nodes, actions);
745 XCTAssertTrue([flutterView.subviews count] == 1);
747 XCTAssertTrue([flutterView.subviews[0].accessibilityLabel isEqualToString:
@"label"]);
750 flutter::SemanticsNodeUpdates new_nodes;
751 flutter::SemanticsNode new_parent;
753 new_parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
754 new_parent.label =
"label";
755 new_parent.value =
"value";
756 new_parent.hint =
"hint";
757 new_nodes[0] = new_parent;
758 bridge->UpdateSemantics(new_nodes, actions);
760 XCTAssertTrue([flutterView.subviews count] == 0);
763 - (void)testBridgeReplacesSemanticsNode {
764 flutter::MockDelegate mock_delegate;
766 flutter::TaskRunners runners(
self.name.UTF8String,
774 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
776 flutterPlatformViewsController,
778 std::make_shared<fml::SyncSwitch>());
784 StubLoadedView(mockFlutterViewController, flutterView);
785 std::string label =
"some label";
787 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
788 mockFlutterViewController,
790 flutterPlatformViewsController);
792 flutter::SemanticsNodeUpdates nodes;
793 flutter::SemanticsNode parent;
795 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
796 parent.label =
"label";
797 parent.value =
"value";
798 parent.hint =
"hint";
800 flutter::SemanticsNode node;
802 node.flags.hasImplicitScrolling =
true;
803 node.actions = flutter::kHorizontalScrollSemanticsActions;
804 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
805 node.label =
"label";
806 node.value =
"value";
808 node.scrollExtentMax = 100.0;
809 node.scrollPosition = 0.0;
810 parent.childrenInTraversalOrder.push_back(1);
811 parent.childrenInHitTestOrder.push_back(1);
814 flutter::CustomAccessibilityActionUpdates actions;
815 bridge->UpdateSemantics(nodes, actions);
816 XCTAssertTrue([flutterView.subviews count] == 1);
818 XCTAssertTrue([flutterView.subviews[0].accessibilityLabel isEqualToString:
@"label"]);
821 flutter::SemanticsNodeUpdates new_nodes;
822 flutter::SemanticsNode new_node;
824 new_node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
825 new_node.label =
"label";
826 new_node.value =
"value";
827 new_node.hint =
"hint";
828 new_node.scrollExtentMax = 100.0;
829 new_node.scrollPosition = 0.0;
830 new_nodes[1] = new_node;
831 bridge->UpdateSemantics(new_nodes, actions);
833 XCTAssertTrue([flutterView.subviews count] == 0);
836 - (void)testAnnouncesRouteChanges {
837 flutter::MockDelegate mock_delegate;
839 flutter::TaskRunners runners(
self.name.UTF8String,
844 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
848 std::make_shared<fml::SyncSwitch>());
849 id mockFlutterView = OCMClassMock([
FlutterView class]);
851 StubLoadedView(mockFlutterViewController, mockFlutterView);
853 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
854 [[NSMutableArray alloc] init];
855 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
856 ios_delegate->on_PostAccessibilityNotification_ =
857 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
858 [accessibility_notifications addObject:@{
859 @"notification" : @(notification),
860 @"argument" : argument ? argument : [NSNull null],
863 __block
auto bridge =
864 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
867 std::move(ios_delegate));
869 flutter::CustomAccessibilityActionUpdates actions;
870 flutter::SemanticsNodeUpdates nodes;
872 flutter::SemanticsNode node1;
874 node1.label =
"node1";
875 node1.flags.scopesRoute =
true;
876 node1.childrenInTraversalOrder = {2, 3};
877 node1.childrenInHitTestOrder = {2, 3};
878 nodes[node1.id] = node1;
879 flutter::SemanticsNode node2;
881 node2.label =
"node2";
882 nodes[node2.id] = node2;
883 flutter::SemanticsNode node3;
885 node3.flags.namesRoute =
true;
886 node3.label =
"node3";
887 nodes[node3.id] = node3;
888 flutter::SemanticsNode root_node;
890 root_node.flags.scopesRoute =
true;
891 root_node.childrenInTraversalOrder = {1};
892 root_node.childrenInHitTestOrder = {1};
893 nodes[root_node.id] = root_node;
894 bridge->UpdateSemantics(nodes, actions);
896 XCTAssertEqual([accessibility_notifications count], 1ul);
897 XCTAssertEqualObjects(accessibility_notifications[0][
@"argument"],
@"node3");
898 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
899 UIAccessibilityScreenChangedNotification);
902 - (void)testRadioButtonIsNotSwitchButton {
903 flutter::MockDelegate mock_delegate;
905 flutter::TaskRunners runners(
self.name.UTF8String,
910 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
914 std::make_shared<fml::SyncSwitch>());
920 StubLoadedView(mockFlutterViewController, flutterView);
921 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
922 __block
auto bridge =
923 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
926 std::move(ios_delegate));
928 flutter::CustomAccessibilityActionUpdates actions;
929 flutter::SemanticsNodeUpdates nodes;
931 flutter::SemanticsNode root_node;
933 root_node.flags.isInMutuallyExclusiveGroup =
true;
934 root_node.flags.isEnabled = flutter::SemanticsTristate::kTrue;
935 root_node.flags.isChecked = flutter::SemanticsCheckState::kFalse;
936 nodes[root_node.id] = root_node;
937 bridge->UpdateSemantics(nodes, actions);
942 XCTAssertTrue((rootNode.accessibilityTraits & UIAccessibilityTraitButton) > 0);
943 XCTAssertNil(rootNode.accessibilityValue);
946 - (void)testSemanticObjectWithNoAccessibilityFlagNotMarkedAsResponsiveToUserInteraction {
947 flutter::MockDelegate mock_delegate;
949 flutter::TaskRunners runners(
self.name.UTF8String,
954 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
958 std::make_shared<fml::SyncSwitch>());
964 StubLoadedView(mockFlutterViewController, flutterView);
965 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
966 __block
auto bridge =
967 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
970 std::move(ios_delegate));
972 flutter::CustomAccessibilityActionUpdates actions;
973 flutter::SemanticsNodeUpdates nodes;
975 flutter::SemanticsNode root_node;
978 nodes[root_node.id] = root_node;
979 bridge->UpdateSemantics(nodes, actions);
984 XCTAssertFalse(rootNode.accessibilityRespondsToUserInteraction);
987 - (void)testSemanticObjectWithAccessibilityFlagsMarkedAsResponsiveToUserInteraction {
988 flutter::MockDelegate mock_delegate;
990 flutter::TaskRunners runners(
self.name.UTF8String,
995 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
999 std::make_shared<fml::SyncSwitch>());
1004 enableWideGamut:NO];
1005 StubLoadedView(mockFlutterViewController, flutterView);
1006 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1007 __block
auto bridge =
1008 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1011 std::move(ios_delegate));
1013 flutter::CustomAccessibilityActionUpdates actions;
1014 flutter::SemanticsNodeUpdates nodes;
1016 flutter::SemanticsNode root_node;
1018 root_node.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
1020 nodes[root_node.id] = root_node;
1021 bridge->UpdateSemantics(nodes, actions);
1026 XCTAssertTrue(rootNode.accessibilityRespondsToUserInteraction);
1031 - (void)testLabeledParentAndChildNotInteractive {
1032 flutter::MockDelegate mock_delegate;
1034 flutter::TaskRunners runners(
self.name.UTF8String,
1038 thread_task_runner);
1042 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1044 flutterPlatformViewsController,
1046 std::make_shared<fml::SyncSwitch>());
1051 enableWideGamut:NO];
1052 StubLoadedView(mockFlutterViewController, flutterView);
1055 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
1056 mockFlutterViewController,
1058 flutterPlatformViewsController);
1060 flutter::SemanticsNodeUpdates nodes;
1062 flutter::SemanticsNode parent;
1064 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1065 parent.label =
"parent_label";
1067 flutter::SemanticsNode node;
1069 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1070 node.label =
"child_label";
1072 parent.childrenInTraversalOrder.push_back(1);
1073 parent.childrenInHitTestOrder.push_back(1);
1076 flutter::CustomAccessibilityActionUpdates actions;
1077 bridge->UpdateSemantics(nodes, actions);
1083 XCTAssertTrue([parentNode.accessibilityLabel isEqualToString:
@"parent_label"]);
1084 XCTAssertTrue([childNode.accessibilityLabel isEqualToString:
@"child_label"]);
1085 XCTAssertFalse(parentNode.accessibilityRespondsToUserInteraction);
1086 XCTAssertFalse(childNode.accessibilityRespondsToUserInteraction);
1090 - (void)testLayoutChangeWithNonAccessibilityElement {
1091 flutter::MockDelegate mock_delegate;
1093 flutter::TaskRunners runners(
self.name.UTF8String,
1097 thread_task_runner);
1098 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1102 std::make_shared<fml::SyncSwitch>());
1103 id mockFlutterView = OCMClassMock([
FlutterView class]);
1105 StubLoadedView(mockFlutterViewController, mockFlutterView);
1107 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1108 [[NSMutableArray alloc] init];
1109 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1110 ios_delegate->on_PostAccessibilityNotification_ =
1111 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1112 [accessibility_notifications addObject:@{
1113 @"notification" : @(notification),
1114 @"argument" : argument ? argument : [NSNull null],
1117 __block
auto bridge =
1118 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1121 std::move(ios_delegate));
1123 flutter::CustomAccessibilityActionUpdates actions;
1124 flutter::SemanticsNodeUpdates nodes;
1126 flutter::SemanticsNode node1;
1128 node1.label =
"node1";
1129 node1.childrenInTraversalOrder = {2, 3};
1130 node1.childrenInHitTestOrder = {2, 3};
1131 nodes[node1.id] = node1;
1132 flutter::SemanticsNode node2;
1134 node2.label =
"node2";
1135 nodes[node2.id] = node2;
1136 flutter::SemanticsNode node3;
1138 node3.label =
"node3";
1139 nodes[node3.id] = node3;
1140 flutter::SemanticsNode root_node;
1142 root_node.label =
"root";
1143 root_node.childrenInTraversalOrder = {1};
1144 root_node.childrenInHitTestOrder = {1};
1145 nodes[root_node.id] = root_node;
1146 bridge->UpdateSemantics(nodes, actions);
1149 bridge->AccessibilityObjectDidBecomeFocused(1);
1154 flutter::CustomAccessibilityActionUpdates new_actions;
1155 flutter::SemanticsNodeUpdates new_nodes;
1157 flutter::SemanticsNode new_node1;
1159 new_node1.childrenInTraversalOrder = {2};
1160 new_node1.childrenInHitTestOrder = {2};
1161 new_nodes[new_node1.id] = new_node1;
1162 bridge->UpdateSemantics(new_nodes, new_actions);
1164 XCTAssertEqual([accessibility_notifications count], 1ul);
1165 SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
1167 XCTAssertEqual([focusObject uid], 2);
1168 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1169 UIAccessibilityLayoutChangedNotification);
1172 - (void)testLayoutChangeDoesCallNativeAccessibility {
1173 flutter::MockDelegate mock_delegate;
1175 flutter::TaskRunners runners(
self.name.UTF8String,
1179 thread_task_runner);
1180 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1184 std::make_shared<fml::SyncSwitch>());
1185 id mockFlutterView = OCMClassMock([
FlutterView class]);
1187 StubLoadedView(mockFlutterViewController, mockFlutterView);
1189 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1190 [[NSMutableArray alloc] init];
1191 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1192 ios_delegate->on_PostAccessibilityNotification_ =
1193 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1194 [accessibility_notifications addObject:@{
1195 @"notification" : @(notification),
1196 @"argument" : argument ? argument : [NSNull null],
1199 __block
auto bridge =
1200 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1203 std::move(ios_delegate));
1205 flutter::CustomAccessibilityActionUpdates actions;
1206 flutter::SemanticsNodeUpdates nodes;
1208 flutter::SemanticsNode node1;
1210 node1.label =
"node1";
1211 nodes[node1.id] = node1;
1212 flutter::SemanticsNode root_node;
1214 root_node.label =
"root";
1215 root_node.flags.hasImplicitScrolling =
true;
1216 root_node.childrenInTraversalOrder = {1};
1217 root_node.childrenInHitTestOrder = {1};
1218 nodes[root_node.id] = root_node;
1219 bridge->UpdateSemantics(nodes, actions);
1222 bridge->AccessibilityObjectDidBecomeFocused(0);
1225 flutter::CustomAccessibilityActionUpdates new_actions;
1226 flutter::SemanticsNodeUpdates new_nodes;
1228 flutter::SemanticsNode new_root_node;
1230 new_root_node.label =
"root";
1231 new_root_node.flags.hasImplicitScrolling =
true;
1232 new_nodes[new_root_node.id] = new_root_node;
1233 bridge->UpdateSemantics(new_nodes, new_actions);
1235 XCTAssertEqual([accessibility_notifications count], 1ul);
1236 id focusObject = accessibility_notifications[0][@"argument"];
1240 XCTAssertEqualObjects(focusObject, [NSNull
null]);
1241 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1242 UIAccessibilityLayoutChangedNotification);
1245 - (void)testLayoutChangeDoesCallNativeAccessibilityWhenFocusChanged {
1246 flutter::MockDelegate mock_delegate;
1248 flutter::TaskRunners runners(
self.name.UTF8String,
1252 thread_task_runner);
1253 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1257 std::make_shared<fml::SyncSwitch>());
1258 id mockFlutterView = OCMClassMock([
FlutterView class]);
1260 StubLoadedView(mockFlutterViewController, mockFlutterView);
1262 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1263 [[NSMutableArray alloc] init];
1264 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1265 ios_delegate->on_PostAccessibilityNotification_ =
1266 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1267 [accessibility_notifications addObject:@{
1268 @"notification" : @(notification),
1269 @"argument" : argument ? argument : [NSNull null],
1272 __block
auto bridge =
1273 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1276 std::move(ios_delegate));
1278 flutter::CustomAccessibilityActionUpdates actions;
1279 flutter::SemanticsNodeUpdates nodes;
1281 flutter::SemanticsNode node1;
1283 node1.label =
"node1";
1284 nodes[node1.id] = node1;
1285 flutter::SemanticsNode root_node;
1287 root_node.label =
"root";
1288 root_node.flags.hasImplicitScrolling =
true;
1289 root_node.childrenInTraversalOrder = {1};
1290 root_node.childrenInHitTestOrder = {1};
1291 nodes[root_node.id] = root_node;
1292 bridge->UpdateSemantics(nodes, actions);
1295 bridge->AccessibilityObjectDidBecomeFocused(1);
1298 flutter::CustomAccessibilityActionUpdates new_actions;
1299 flutter::SemanticsNodeUpdates new_nodes;
1301 flutter::SemanticsNode new_root_node;
1303 new_root_node.label =
"root";
1304 new_root_node.flags.hasImplicitScrolling =
true;
1305 new_nodes[new_root_node.id] = new_root_node;
1306 bridge->UpdateSemantics(new_nodes, new_actions);
1308 XCTAssertEqual([accessibility_notifications count], 1ul);
1309 SemanticsObject* focusObject2 = accessibility_notifications[0][@"argument"];
1313 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1314 UIAccessibilityLayoutChangedNotification);
1317 - (void)testScrollableSemanticsContainerReturnsCorrectChildren {
1318 flutter::MockDelegate mock_delegate;
1320 flutter::TaskRunners runners(
self.name.UTF8String,
1324 thread_task_runner);
1325 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1329 std::make_shared<fml::SyncSwitch>());
1330 id mockFlutterView = OCMClassMock([
FlutterView class]);
1332 StubLoadedView(mockFlutterViewController, mockFlutterView);
1334 OCMExpect([mockFlutterView
1335 setAccessibilityElements:[OCMArg checkWithBlock:^BOOL(NSArray* value) {
1336 if ([value count] != 1) {
1345 return [scrollableContainer indexOfAccessibilityElement:nativeScrollable] == 1;
1347 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1348 __block
auto bridge =
1349 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1352 std::move(ios_delegate));
1354 flutter::CustomAccessibilityActionUpdates actions;
1355 flutter::SemanticsNodeUpdates nodes;
1357 flutter::SemanticsNode node1;
1359 node1.label =
"node1";
1360 node1.flags.hasImplicitScrolling =
true;
1361 nodes[node1.id] = node1;
1362 flutter::SemanticsNode root_node;
1364 root_node.label =
"root";
1365 root_node.childrenInTraversalOrder = {1};
1366 root_node.childrenInHitTestOrder = {1};
1367 nodes[root_node.id] = root_node;
1368 bridge->UpdateSemantics(nodes, actions);
1369 OCMVerifyAll(mockFlutterView);
1372 - (void)testAnnouncesRouteChangesAndLayoutChangeInOneUpdate {
1373 flutter::MockDelegate mock_delegate;
1375 flutter::TaskRunners runners(
self.name.UTF8String,
1379 thread_task_runner);
1380 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1384 std::make_shared<fml::SyncSwitch>());
1385 id mockFlutterView = OCMClassMock([
FlutterView class]);
1387 StubLoadedView(mockFlutterViewController, mockFlutterView);
1389 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1390 [[NSMutableArray alloc] init];
1391 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1392 ios_delegate->on_PostAccessibilityNotification_ =
1393 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1394 [accessibility_notifications addObject:@{
1395 @"notification" : @(notification),
1396 @"argument" : argument ? argument : [NSNull null],
1399 __block
auto bridge =
1400 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1403 std::move(ios_delegate));
1405 flutter::CustomAccessibilityActionUpdates actions;
1406 flutter::SemanticsNodeUpdates nodes;
1408 flutter::SemanticsNode node1;
1410 node1.label =
"node1";
1411 node1.flags.scopesRoute =
true;
1412 node1.flags.namesRoute =
true;
1413 nodes[node1.id] = node1;
1414 flutter::SemanticsNode node3;
1416 node3.label =
"node3";
1417 nodes[node3.id] = node3;
1418 flutter::SemanticsNode root_node;
1420 root_node.label =
"root";
1421 root_node.childrenInTraversalOrder = {1, 3};
1422 root_node.childrenInHitTestOrder = {1, 3};
1423 nodes[root_node.id] = root_node;
1424 bridge->UpdateSemantics(nodes, actions);
1426 XCTAssertEqual([accessibility_notifications count], 1ul);
1427 XCTAssertEqualObjects(accessibility_notifications[0][
@"argument"],
@"node1");
1428 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1429 UIAccessibilityScreenChangedNotification);
1432 bridge->AccessibilityObjectDidBecomeFocused(0);
1434 flutter::SemanticsNodeUpdates new_nodes;
1436 flutter::SemanticsNode new_node1;
1438 new_node1.label =
"new_node1";
1439 new_node1.flags.scopesRoute =
true;
1440 new_node1.flags.namesRoute =
true;
1441 new_node1.childrenInTraversalOrder = {2};
1442 new_node1.childrenInHitTestOrder = {2};
1443 new_nodes[new_node1.id] = new_node1;
1444 flutter::SemanticsNode new_node2;
1446 new_node2.label =
"new_node2";
1447 new_node2.flags.scopesRoute =
true;
1448 new_node2.flags.namesRoute =
true;
1449 new_nodes[new_node2.id] = new_node2;
1450 flutter::SemanticsNode new_root_node;
1452 new_root_node.label =
"root";
1453 new_root_node.childrenInTraversalOrder = {1};
1454 new_root_node.childrenInHitTestOrder = {1};
1455 new_nodes[new_root_node.id] = new_root_node;
1456 bridge->UpdateSemantics(new_nodes, actions);
1457 XCTAssertEqual([accessibility_notifications count], 3ul);
1458 XCTAssertEqualObjects(accessibility_notifications[1][
@"argument"],
@"new_node2");
1459 XCTAssertEqual([accessibility_notifications[1][
@"notification"] unsignedIntValue],
1460 UIAccessibilityScreenChangedNotification);
1461 SemanticsObject* focusObject = accessibility_notifications[2][@"argument"];
1462 XCTAssertEqual([focusObject uid], 0);
1463 XCTAssertEqual([accessibility_notifications[2][
@"notification"] unsignedIntValue],
1464 UIAccessibilityLayoutChangedNotification);
1467 - (void)testAnnouncesRouteChangesWhenAddAdditionalRoute {
1468 flutter::MockDelegate mock_delegate;
1470 flutter::TaskRunners runners(
self.name.UTF8String,
1474 thread_task_runner);
1475 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1479 std::make_shared<fml::SyncSwitch>());
1480 id mockFlutterView = OCMClassMock([
FlutterView class]);
1482 StubLoadedView(mockFlutterViewController, mockFlutterView);
1484 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1485 [[NSMutableArray alloc] init];
1486 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1487 ios_delegate->on_PostAccessibilityNotification_ =
1488 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1489 [accessibility_notifications addObject:@{
1490 @"notification" : @(notification),
1491 @"argument" : argument ? argument : [NSNull null],
1494 __block
auto bridge =
1495 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1498 std::move(ios_delegate));
1500 flutter::CustomAccessibilityActionUpdates actions;
1501 flutter::SemanticsNodeUpdates nodes;
1503 flutter::SemanticsNode node1;
1505 node1.label =
"node1";
1506 node1.flags.scopesRoute =
true;
1507 node1.flags.namesRoute =
true;
1508 nodes[node1.id] = node1;
1509 flutter::SemanticsNode root_node;
1511 root_node.flags.scopesRoute =
true;
1512 root_node.childrenInTraversalOrder = {1};
1513 root_node.childrenInHitTestOrder = {1};
1514 nodes[root_node.id] = root_node;
1515 bridge->UpdateSemantics(nodes, actions);
1517 XCTAssertEqual([accessibility_notifications count], 1ul);
1518 XCTAssertEqualObjects(accessibility_notifications[0][
@"argument"],
@"node1");
1519 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1520 UIAccessibilityScreenChangedNotification);
1522 flutter::SemanticsNodeUpdates new_nodes;
1524 flutter::SemanticsNode new_node1;
1526 new_node1.label =
"new_node1";
1527 new_node1.flags.scopesRoute =
true;
1528 new_node1.flags.namesRoute =
true;
1529 new_node1.childrenInTraversalOrder = {2};
1530 new_node1.childrenInHitTestOrder = {2};
1531 new_nodes[new_node1.id] = new_node1;
1532 flutter::SemanticsNode new_node2;
1534 new_node2.label =
"new_node2";
1535 new_node2.flags.scopesRoute =
true;
1536 new_node2.flags.namesRoute =
true;
1537 new_nodes[new_node2.id] = new_node2;
1538 flutter::SemanticsNode new_root_node;
1540 new_root_node.flags.scopesRoute =
true;
1541 new_root_node.childrenInTraversalOrder = {1};
1542 new_root_node.childrenInHitTestOrder = {1};
1543 new_nodes[new_root_node.id] = new_root_node;
1544 bridge->UpdateSemantics(new_nodes, actions);
1545 XCTAssertEqual([accessibility_notifications count], 2ul);
1546 XCTAssertEqualObjects(accessibility_notifications[1][
@"argument"],
@"new_node2");
1547 XCTAssertEqual([accessibility_notifications[1][
@"notification"] unsignedIntValue],
1548 UIAccessibilityScreenChangedNotification);
1551 - (void)testAnnouncesRouteChangesRemoveRouteInMiddle {
1552 flutter::MockDelegate mock_delegate;
1554 flutter::TaskRunners runners(
self.name.UTF8String,
1558 thread_task_runner);
1559 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1563 std::make_shared<fml::SyncSwitch>());
1564 id mockFlutterView = OCMClassMock([
FlutterView class]);
1566 StubLoadedView(mockFlutterViewController, mockFlutterView);
1568 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1569 [[NSMutableArray alloc] init];
1570 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1571 ios_delegate->on_PostAccessibilityNotification_ =
1572 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1573 [accessibility_notifications addObject:@{
1574 @"notification" : @(notification),
1575 @"argument" : argument ? argument : [NSNull null],
1578 __block
auto bridge =
1579 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1582 std::move(ios_delegate));
1584 flutter::CustomAccessibilityActionUpdates actions;
1585 flutter::SemanticsNodeUpdates nodes;
1587 flutter::SemanticsNode node1;
1589 node1.label =
"node1";
1590 node1.flags.scopesRoute =
true;
1591 node1.flags.namesRoute =
true;
1592 node1.childrenInTraversalOrder = {2};
1593 node1.childrenInHitTestOrder = {2};
1594 nodes[node1.id] = node1;
1595 flutter::SemanticsNode node2;
1597 node2.label =
"node2";
1598 node2.flags.scopesRoute =
true;
1599 node2.flags.namesRoute =
true;
1600 nodes[node2.id] = node2;
1601 flutter::SemanticsNode root_node;
1603 root_node.flags.scopesRoute =
true;
1604 root_node.childrenInTraversalOrder = {1};
1605 root_node.childrenInHitTestOrder = {1};
1606 nodes[root_node.id] = root_node;
1607 bridge->UpdateSemantics(nodes, actions);
1609 XCTAssertEqual([accessibility_notifications count], 1ul);
1610 XCTAssertEqualObjects(accessibility_notifications[0][
@"argument"],
@"node2");
1611 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1612 UIAccessibilityScreenChangedNotification);
1614 flutter::SemanticsNodeUpdates new_nodes;
1616 flutter::SemanticsNode new_node1;
1618 new_node1.label =
"new_node1";
1619 new_node1.childrenInTraversalOrder = {2};
1620 new_node1.childrenInHitTestOrder = {2};
1621 new_nodes[new_node1.id] = new_node1;
1622 flutter::SemanticsNode new_node2;
1624 new_node2.label =
"new_node2";
1625 new_node2.flags.scopesRoute =
true;
1626 new_node2.flags.namesRoute =
true;
1627 new_nodes[new_node2.id] = new_node2;
1628 flutter::SemanticsNode new_root_node;
1630 new_root_node.flags.scopesRoute =
true;
1631 new_root_node.childrenInTraversalOrder = {1};
1632 new_root_node.childrenInHitTestOrder = {1};
1633 new_nodes[new_root_node.id] = new_root_node;
1634 bridge->UpdateSemantics(new_nodes, actions);
1635 XCTAssertEqual([accessibility_notifications count], 2ul);
1636 XCTAssertEqualObjects(accessibility_notifications[1][
@"argument"],
@"new_node2");
1637 XCTAssertEqual([accessibility_notifications[1][
@"notification"] unsignedIntValue],
1638 UIAccessibilityScreenChangedNotification);
1641 - (void)testHandleEvent {
1642 flutter::MockDelegate mock_delegate;
1644 flutter::TaskRunners runners(
self.name.UTF8String,
1648 thread_task_runner);
1649 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1653 std::make_shared<fml::SyncSwitch>());
1654 id mockFlutterView = OCMClassMock([
FlutterView class]);
1656 StubLoadedView(mockFlutterViewController, mockFlutterView);
1658 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1659 [[NSMutableArray alloc] init];
1660 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1661 ios_delegate->on_PostAccessibilityNotification_ =
1662 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1663 [accessibility_notifications addObject:@{
1664 @"notification" : @(notification),
1665 @"argument" : argument ? argument : [NSNull null],
1668 __block
auto bridge =
1669 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1672 std::move(ios_delegate));
1674 NSDictionary<NSString*, id>* annotatedEvent = @{
@"type" :
@"focus",
@"nodeId" : @123};
1676 bridge->HandleEvent(annotatedEvent);
1678 XCTAssertEqual([accessibility_notifications count], 1ul);
1679 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1680 UIAccessibilityLayoutChangedNotification);
1683 - (void)testAccessibilityObjectDidBecomeFocused {
1684 flutter::MockDelegate mock_delegate;
1685 auto thread = std::make_unique<fml::Thread>(
"AccessibilityBridgeTest");
1686 auto thread_task_runner = thread->GetTaskRunner();
1687 flutter::TaskRunners runners(
self.name.UTF8String,
1691 thread_task_runner);
1696 OCMStub([flutterViewController
engine]).andReturn(
engine);
1697 OCMStub([
engine binaryMessenger]).andReturn(messenger);
1699 OCMStub([messenger setMessageHandlerOnChannel:
@"flutter/accessibility"
1700 binaryMessageHandler:[OCMArg any]])
1701 .andReturn(connection);
1703 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1707 std::make_shared<fml::SyncSwitch>());
1708 fml::AutoResetWaitableEvent latch;
1709 thread_task_runner->PostTask([&] {
1710 platform_view->SetOwnerViewController(flutterViewController);
1712 std::make_unique<flutter::AccessibilityBridge>(nil,
1715 XCTAssertTrue(bridge.get());
1716 OCMVerify([messenger setMessageHandlerOnChannel:
@"flutter/accessibility"
1717 binaryMessageHandler:[OCMArg isNotNil]]);
1719 bridge->AccessibilityObjectDidBecomeFocused(123);
1721 NSDictionary<NSString*, id>* annotatedEvent = @{
@"type" :
@"didGainFocus",
@"nodeId" : @123};
1722 OCMVerify([messenger sendOnChannel:
@"flutter/accessibility"
1723 message:[OCMArg checkWithBlock:^BOOL(NSData* message) {
1725 decode:message] isEqual:annotatedEvent];
1731 [engine stopMocking];
1734 - (void)testAnnouncesRouteChangesWhenNoNamesRoute {
1735 flutter::MockDelegate mock_delegate;
1737 flutter::TaskRunners runners(
self.name.UTF8String,
1741 thread_task_runner);
1742 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1746 std::make_shared<fml::SyncSwitch>());
1747 id mockFlutterView = OCMClassMock([
FlutterView class]);
1749 StubLoadedView(mockFlutterViewController, mockFlutterView);
1751 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1752 [[NSMutableArray alloc] init];
1753 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1754 ios_delegate->on_PostAccessibilityNotification_ =
1755 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1756 [accessibility_notifications addObject:@{
1757 @"notification" : @(notification),
1758 @"argument" : argument ? argument : [NSNull null],
1761 __block
auto bridge =
1762 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1765 std::move(ios_delegate));
1767 flutter::CustomAccessibilityActionUpdates actions;
1768 flutter::SemanticsNodeUpdates nodes;
1770 flutter::SemanticsNode node1;
1772 node1.label =
"node1";
1773 node1.flags.scopesRoute =
true;
1774 node1.flags.namesRoute =
true;
1775 node1.childrenInTraversalOrder = {2, 3};
1776 node1.childrenInHitTestOrder = {2, 3};
1777 nodes[node1.id] = node1;
1778 flutter::SemanticsNode node2;
1780 node2.label =
"node2";
1781 nodes[node2.id] = node2;
1782 flutter::SemanticsNode node3;
1784 node3.label =
"node3";
1785 nodes[node3.id] = node3;
1786 flutter::SemanticsNode root_node;
1788 root_node.childrenInTraversalOrder = {1};
1789 root_node.childrenInHitTestOrder = {1};
1790 nodes[root_node.id] = root_node;
1791 bridge->UpdateSemantics(nodes, actions);
1794 XCTAssertEqual([accessibility_notifications count], 1ul);
1795 id focusObject = accessibility_notifications[0][@"argument"];
1796 XCTAssertTrue([focusObject isKindOfClass:[NSString
class]]);
1797 XCTAssertEqualObjects(focusObject,
@"node1");
1798 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1799 UIAccessibilityScreenChangedNotification);
1802 - (void)testAnnouncesLayoutChangeWithNilIfLastFocusIsRemoved {
1803 flutter::MockDelegate mock_delegate;
1805 flutter::TaskRunners runners(
self.name.UTF8String,
1809 thread_task_runner);
1810 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1814 std::make_shared<fml::SyncSwitch>());
1816 id mockFlutterView = OCMClassMock([
FlutterView class]);
1817 StubLoadedView(mockFlutterViewController, mockFlutterView);
1819 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1820 [[NSMutableArray alloc] init];
1821 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1822 ios_delegate->on_PostAccessibilityNotification_ =
1823 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1824 [accessibility_notifications addObject:@{
1825 @"notification" : @(notification),
1826 @"argument" : argument ? argument : [NSNull null],
1829 __block
auto bridge =
1830 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1833 std::move(ios_delegate));
1835 flutter::CustomAccessibilityActionUpdates actions;
1836 flutter::SemanticsNodeUpdates first_update;
1838 flutter::SemanticsNode route_node;
1840 route_node.label =
"route";
1841 first_update[route_node.id] = route_node;
1842 flutter::SemanticsNode root_node;
1844 root_node.label =
"root";
1845 root_node.childrenInTraversalOrder = {1};
1846 root_node.childrenInHitTestOrder = {1};
1847 first_update[root_node.id] = root_node;
1848 bridge->UpdateSemantics(first_update, actions);
1850 XCTAssertEqual([accessibility_notifications count], 0ul);
1852 bridge->AccessibilityObjectDidBecomeFocused(1);
1854 flutter::SemanticsNodeUpdates second_update;
1856 flutter::SemanticsNode new_root_node;
1858 new_root_node.label =
"root";
1859 second_update[root_node.id] = new_root_node;
1860 bridge->UpdateSemantics(second_update, actions);
1861 SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
1863 XCTAssertEqual([focusObject uid], 0);
1864 XCTAssertEqualObjects([focusObject accessibilityLabel],
@"root");
1865 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1866 UIAccessibilityLayoutChangedNotification);
1869 - (void)testAnnouncesLayoutChangeWithTheSameItemFocused {
1870 flutter::MockDelegate mock_delegate;
1872 flutter::TaskRunners runners(
self.name.UTF8String,
1876 thread_task_runner);
1877 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1881 std::make_shared<fml::SyncSwitch>());
1883 id mockFlutterView = OCMClassMock([
FlutterView class]);
1884 StubLoadedView(mockFlutterViewController, mockFlutterView);
1886 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1887 [[NSMutableArray alloc] init];
1888 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1889 ios_delegate->on_PostAccessibilityNotification_ =
1890 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1891 [accessibility_notifications addObject:@{
1892 @"notification" : @(notification),
1893 @"argument" : argument ? argument : [NSNull null],
1896 __block
auto bridge =
1897 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1900 std::move(ios_delegate));
1902 flutter::CustomAccessibilityActionUpdates actions;
1903 flutter::SemanticsNodeUpdates first_update;
1905 flutter::SemanticsNode node_one;
1907 node_one.label =
"route1";
1908 first_update[node_one.id] = node_one;
1909 flutter::SemanticsNode node_two;
1911 node_two.label =
"route2";
1912 first_update[node_two.id] = node_two;
1913 flutter::SemanticsNode root_node;
1915 root_node.label =
"root";
1916 root_node.childrenInTraversalOrder = {1, 2};
1917 root_node.childrenInHitTestOrder = {1, 2};
1918 first_update[root_node.id] = root_node;
1919 bridge->UpdateSemantics(first_update, actions);
1921 XCTAssertEqual([accessibility_notifications count], 0ul);
1923 bridge->AccessibilityObjectDidBecomeFocused(1);
1925 flutter::SemanticsNodeUpdates second_update;
1927 flutter::SemanticsNode new_root_node;
1929 new_root_node.label =
"root";
1930 new_root_node.childrenInTraversalOrder = {1};
1931 new_root_node.childrenInHitTestOrder = {1};
1932 second_update[root_node.id] = new_root_node;
1933 bridge->UpdateSemantics(second_update, actions);
1934 id focusObject = accessibility_notifications[0][@"argument"];
1937 XCTAssertEqualObjects(focusObject, [NSNull
null]);
1938 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
1939 UIAccessibilityLayoutChangedNotification);
1942 - (void)testAnnouncesLayoutChangeWhenFocusMovedOutside {
1943 flutter::MockDelegate mock_delegate;
1945 flutter::TaskRunners runners(
self.name.UTF8String,
1949 thread_task_runner);
1950 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1954 std::make_shared<fml::SyncSwitch>());
1956 id mockFlutterView = OCMClassMock([
FlutterView class]);
1957 StubLoadedView(mockFlutterViewController, mockFlutterView);
1959 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1960 [[NSMutableArray alloc] init];
1961 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1962 ios_delegate->on_PostAccessibilityNotification_ =
1963 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
1964 [accessibility_notifications addObject:@{
1965 @"notification" : @(notification),
1966 @"argument" : argument ? argument : [NSNull null],
1969 __block
auto bridge =
1970 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
1973 std::move(ios_delegate));
1975 flutter::CustomAccessibilityActionUpdates actions;
1976 flutter::SemanticsNodeUpdates first_update;
1978 flutter::SemanticsNode node_one;
1980 node_one.label =
"route1";
1981 first_update[node_one.id] = node_one;
1982 flutter::SemanticsNode node_two;
1984 node_two.label =
"route2";
1985 first_update[node_two.id] = node_two;
1986 flutter::SemanticsNode root_node;
1988 root_node.label =
"root";
1989 root_node.childrenInTraversalOrder = {1, 2};
1990 root_node.childrenInHitTestOrder = {1, 2};
1991 first_update[root_node.id] = root_node;
1992 bridge->UpdateSemantics(first_update, actions);
1994 XCTAssertEqual([accessibility_notifications count], 0ul);
1996 bridge->AccessibilityObjectDidBecomeFocused(1);
1998 bridge->AccessibilityObjectDidLoseFocus(1);
2000 flutter::SemanticsNodeUpdates second_update;
2002 flutter::SemanticsNode new_root_node;
2004 new_root_node.label =
"root";
2005 new_root_node.childrenInTraversalOrder = {1};
2006 new_root_node.childrenInHitTestOrder = {1};
2007 second_update[root_node.id] = new_root_node;
2008 bridge->UpdateSemantics(second_update, actions);
2009 NSNull* focusObject = accessibility_notifications[0][@"argument"];
2012 XCTAssertEqual(focusObject, [NSNull
null]);
2013 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
2014 UIAccessibilityLayoutChangedNotification);
2017 - (void)testAnnouncesScrollChangeWithLastFocused {
2018 flutter::MockDelegate mock_delegate;
2020 flutter::TaskRunners runners(
self.name.UTF8String,
2024 thread_task_runner);
2025 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2029 std::make_shared<fml::SyncSwitch>());
2031 id mockFlutterView = OCMClassMock([
FlutterView class]);
2032 StubLoadedView(mockFlutterViewController, mockFlutterView);
2034 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
2035 [[NSMutableArray alloc] init];
2036 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2037 ios_delegate->on_PostAccessibilityNotification_ =
2038 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
2039 [accessibility_notifications addObject:@{
2040 @"notification" : @(notification),
2041 @"argument" : argument ? argument : [NSNull null],
2044 __block
auto bridge =
2045 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2048 std::move(ios_delegate));
2050 flutter::CustomAccessibilityActionUpdates actions;
2051 flutter::SemanticsNodeUpdates first_update;
2053 flutter::SemanticsNode node_one;
2055 node_one.label =
"route1";
2056 node_one.scrollPosition = 0.0;
2057 first_update[node_one.id] = node_one;
2058 flutter::SemanticsNode root_node;
2060 root_node.label =
"root";
2061 root_node.childrenInTraversalOrder = {1};
2062 root_node.childrenInHitTestOrder = {1};
2063 first_update[root_node.id] = root_node;
2064 bridge->UpdateSemantics(first_update, actions);
2067 [accessibility_notifications removeAllObjects];
2070 bridge->AccessibilityObjectDidBecomeFocused(1);
2072 flutter::SemanticsNodeUpdates second_update;
2074 flutter::SemanticsNode new_node_one;
2075 new_node_one.id = 1;
2076 new_node_one.label =
"route1";
2077 new_node_one.scrollPosition = 1.0;
2078 second_update[new_node_one.id] = new_node_one;
2079 bridge->UpdateSemantics(second_update, actions);
2080 SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
2083 XCTAssertEqual([focusObject uid], 1);
2084 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
2085 UIAccessibilityPageScrolledNotification);
2088 - (void)testAnnouncesScrollChangeDoesCallNativeAccessibility {
2089 flutter::MockDelegate mock_delegate;
2091 flutter::TaskRunners runners(
self.name.UTF8String,
2095 thread_task_runner);
2096 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2100 std::make_shared<fml::SyncSwitch>());
2102 id mockFlutterView = OCMClassMock([
FlutterView class]);
2103 StubLoadedView(mockFlutterViewController, mockFlutterView);
2105 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
2106 [[NSMutableArray alloc] init];
2107 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2108 ios_delegate->on_PostAccessibilityNotification_ =
2109 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
2110 [accessibility_notifications addObject:@{
2111 @"notification" : @(notification),
2112 @"argument" : argument ? argument : [NSNull null],
2115 __block
auto bridge =
2116 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2119 std::move(ios_delegate));
2121 flutter::CustomAccessibilityActionUpdates actions;
2122 flutter::SemanticsNodeUpdates first_update;
2124 flutter::SemanticsNode node_one;
2126 node_one.label =
"route1";
2127 node_one.flags.hasImplicitScrolling =
true;
2128 node_one.scrollPosition = 0.0;
2129 first_update[node_one.id] = node_one;
2130 flutter::SemanticsNode root_node;
2132 root_node.label =
"root";
2133 root_node.childrenInTraversalOrder = {1};
2134 root_node.childrenInHitTestOrder = {1};
2135 first_update[root_node.id] = root_node;
2136 bridge->UpdateSemantics(first_update, actions);
2139 [accessibility_notifications removeAllObjects];
2142 bridge->AccessibilityObjectDidBecomeFocused(1);
2144 flutter::SemanticsNodeUpdates second_update;
2146 flutter::SemanticsNode new_node_one;
2147 new_node_one.id = 1;
2148 new_node_one.label =
"route1";
2149 new_node_one.flags.hasImplicitScrolling =
true;
2150 new_node_one.scrollPosition = 1.0;
2151 second_update[new_node_one.id] = new_node_one;
2152 bridge->UpdateSemantics(second_update, actions);
2153 SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
2157 XCTAssertEqual([accessibility_notifications[0][
@"notification"] unsignedIntValue],
2158 UIAccessibilityPageScrolledNotification);
2161 - (void)testAnnouncesIgnoresRouteChangesWhenModal {
2162 flutter::MockDelegate mock_delegate;
2164 flutter::TaskRunners runners(
self.name.UTF8String,
2168 thread_task_runner);
2169 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2173 std::make_shared<fml::SyncSwitch>());
2174 id mockFlutterView = OCMClassMock([
FlutterView class]);
2176 StubLoadedView(mockFlutterViewController, mockFlutterView);
2177 std::string label =
"some label";
2179 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
2180 [[NSMutableArray alloc] init];
2181 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2182 ios_delegate->on_PostAccessibilityNotification_ =
2183 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
2184 [accessibility_notifications addObject:@{
2185 @"notification" : @(notification),
2186 @"argument" : argument ? argument : [NSNull null],
2189 ios_delegate->result_IsFlutterViewControllerPresentingModalViewController_ =
true;
2190 __block
auto bridge =
2191 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2194 std::move(ios_delegate));
2196 flutter::CustomAccessibilityActionUpdates actions;
2197 flutter::SemanticsNodeUpdates nodes;
2199 flutter::SemanticsNode route_node;
2201 route_node.flags.scopesRoute =
true;
2202 route_node.flags.namesRoute =
true;
2203 route_node.label =
"route";
2204 nodes[route_node.id] = route_node;
2205 flutter::SemanticsNode root_node;
2207 root_node.label = label;
2208 root_node.childrenInTraversalOrder = {1};
2209 root_node.childrenInHitTestOrder = {1};
2210 nodes[root_node.id] = root_node;
2211 bridge->UpdateSemantics(nodes, actions);
2213 XCTAssertEqual([accessibility_notifications count], 0ul);
2216 - (void)testAnnouncesIgnoresLayoutChangeWhenModal {
2217 flutter::MockDelegate mock_delegate;
2219 flutter::TaskRunners runners(
self.name.UTF8String,
2223 thread_task_runner);
2224 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2228 std::make_shared<fml::SyncSwitch>());
2229 id mockFlutterView = OCMClassMock([
FlutterView class]);
2231 StubLoadedView(mockFlutterViewController, mockFlutterView);
2233 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
2234 [[NSMutableArray alloc] init];
2235 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2236 ios_delegate->on_PostAccessibilityNotification_ =
2237 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
2238 [accessibility_notifications addObject:@{
2239 @"notification" : @(notification),
2240 @"argument" : argument ? argument : [NSNull null],
2243 ios_delegate->result_IsFlutterViewControllerPresentingModalViewController_ =
true;
2244 __block
auto bridge =
2245 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2248 std::move(ios_delegate));
2250 flutter::CustomAccessibilityActionUpdates actions;
2251 flutter::SemanticsNodeUpdates nodes;
2253 flutter::SemanticsNode child_node;
2255 child_node.label =
"child_node";
2256 nodes[child_node.id] = child_node;
2257 flutter::SemanticsNode root_node;
2259 root_node.label =
"root";
2260 root_node.childrenInTraversalOrder = {1};
2261 root_node.childrenInHitTestOrder = {1};
2262 nodes[root_node.id] = root_node;
2263 bridge->UpdateSemantics(nodes, actions);
2266 flutter::SemanticsNodeUpdates new_nodes;
2267 flutter::SemanticsNode new_root_node;
2269 new_root_node.label =
"root";
2270 new_nodes[new_root_node.id] = new_root_node;
2271 bridge->UpdateSemantics(new_nodes, actions);
2273 XCTAssertEqual([accessibility_notifications count], 0ul);
2276 - (void)testAnnouncesIgnoresScrollChangeWhenModal {
2277 flutter::MockDelegate mock_delegate;
2279 flutter::TaskRunners runners(
self.name.UTF8String,
2283 thread_task_runner);
2284 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2288 std::make_shared<fml::SyncSwitch>());
2289 id mockFlutterView = OCMClassMock([
FlutterView class]);
2291 StubLoadedView(mockFlutterViewController, mockFlutterView);
2293 NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
2294 [[NSMutableArray alloc] init];
2295 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2296 ios_delegate->on_PostAccessibilityNotification_ =
2297 [accessibility_notifications](UIAccessibilityNotifications notification,
id argument) {
2298 [accessibility_notifications addObject:@{
2299 @"notification" : @(notification),
2300 @"argument" : argument ? argument : [NSNull null],
2303 ios_delegate->result_IsFlutterViewControllerPresentingModalViewController_ =
true;
2304 __block
auto bridge =
2305 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2308 std::move(ios_delegate));
2310 flutter::CustomAccessibilityActionUpdates actions;
2311 flutter::SemanticsNodeUpdates nodes;
2313 flutter::SemanticsNode root_node;
2315 root_node.label =
"root";
2316 root_node.scrollPosition = 1;
2317 nodes[root_node.id] = root_node;
2318 bridge->UpdateSemantics(nodes, actions);
2321 flutter::SemanticsNodeUpdates new_nodes;
2322 flutter::SemanticsNode new_root_node;
2324 new_root_node.label =
"root";
2325 new_root_node.scrollPosition = 2;
2326 new_nodes[new_root_node.id] = new_root_node;
2327 bridge->UpdateSemantics(new_nodes, actions);
2329 XCTAssertEqual([accessibility_notifications count], 0ul);
2332 - (void)testAccessibilityMessageAfterDeletion {
2333 flutter::MockDelegate mock_delegate;
2334 auto thread = std::make_unique<fml::Thread>(
"AccessibilityBridgeTest");
2335 auto thread_task_runner = thread->GetTaskRunner();
2336 flutter::TaskRunners runners(
self.name.UTF8String,
2340 thread_task_runner);
2345 OCMStub([flutterViewController
engine]).andReturn(
engine);
2346 OCMStub([
engine binaryMessenger]).andReturn(messenger);
2348 OCMStub([messenger setMessageHandlerOnChannel:
@"flutter/accessibility"
2349 binaryMessageHandler:[OCMArg any]])
2350 .andReturn(connection);
2352 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2356 std::make_shared<fml::SyncSwitch>());
2357 fml::AutoResetWaitableEvent latch;
2358 thread_task_runner->PostTask([&] {
2359 platform_view->SetOwnerViewController(flutterViewController);
2361 std::make_unique<flutter::AccessibilityBridge>(nil,
2364 XCTAssertTrue(bridge.get());
2365 OCMVerify([messenger setMessageHandlerOnChannel:
@"flutter/accessibility"
2366 binaryMessageHandler:[OCMArg isNotNil]]);
2371 OCMVerify([messenger cleanUpConnection:connection]);
2372 [engine stopMocking];
2375 - (void)testFlutterSemanticsScrollViewManagedObjectLifecycleCorrectly {
2376 flutter::MockDelegate mock_delegate;
2378 flutter::TaskRunners runners(
self.name.UTF8String,
2382 thread_task_runner);
2383 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2387 std::make_shared<fml::SyncSwitch>());
2388 id mockFlutterView = OCMClassMock([
FlutterView class]);
2390 StubLoadedView(mockFlutterViewController, mockFlutterView);
2392 auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
2393 __block
auto bridge =
2394 std::make_unique<flutter::AccessibilityBridge>(mockFlutterViewController,
2397 std::move(ios_delegate));
2406 XCTAssertTrue(flutterSemanticsScrollView);
2409 XCTAssertFalse([flutterSemanticsScrollView isAccessibilityElement]);
2412 - (void)testPlatformViewDestructorDoesNotCallSemanticsAPIs {
2413 class TestDelegate :
public flutter::MockDelegate {
2415 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override { set_semantics_enabled_calls++; }
2416 int set_semantics_enabled_calls = 0;
2419 TestDelegate test_delegate;
2420 auto thread = std::make_unique<fml::Thread>(
"AccessibilityBridgeTest");
2421 auto thread_task_runner = thread->GetTaskRunner();
2422 flutter::TaskRunners runners(
self.name.UTF8String,
2426 thread_task_runner);
2428 fml::AutoResetWaitableEvent latch;
2429 thread_task_runner->PostTask([&] {
2430 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2434 std::make_shared<fml::SyncSwitch>());
2442 OCMStub([mockFlutterViewController platformViewsController])
2443 .andReturn(flutterPlatformViewsController);
2444 platform_view->SetOwnerViewController(mockFlutterViewController);
2447 XCTAssertNotEqual(test_delegate.set_semantics_enabled_calls, 0);
2450 test_delegate.set_semantics_enabled_calls = 0;
2452 XCTAssertEqual(test_delegate.set_semantics_enabled_calls, 0);
2459 - (void)testResetsAccessibilityElementsOnHotRestart {
2460 flutter::MockDelegate mock_delegate;
2461 auto thread = std::make_unique<fml::Thread>(
"AccessibilityBridgeTest");
2462 auto thread_task_runner = thread->GetTaskRunner();
2463 flutter::TaskRunners runners(
self.name.UTF8String,
2467 thread_task_runner);
2468 UIView* flutterView = [[UIView alloc] init];
2470 OCMStub([mockFlutterViewController viewIfLoaded]).andReturn(flutterView);
2472 fml::AutoResetWaitableEvent latch;
2473 thread_task_runner->PostTask([&] {
2474 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2478 std::make_shared<fml::SyncSwitch>());
2480 platform_view->SetOwnerViewController(mockFlutterViewController);
2484 UpdateRootSemantics(
platform_view->GetAccessibilityBridge(),
"hot restart");
2485 XCTAssertNotNil(flutterView.accessibilityElements);
2488 XCTAssertNil(flutterView.accessibilityElements);
2495 - (void)testWeakViewController {
2496 flutter::MockDelegate mock_delegate;
2498 flutter::TaskRunners runners(
self.name.UTF8String,
2502 thread_task_runner);
2503 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2507 std::make_shared<fml::SyncSwitch>());
2509 std::unique_ptr<flutter::AccessibilityBridge> bridge;
2511 id mockFlutterView = OCMClassMock([
FlutterView class]);
2513 StubLoadedView(mockFlutterViewController, mockFlutterView);
2515 bridge = std::make_unique<flutter::AccessibilityBridge>(
2516 mockFlutterViewController,
2519 XCTAssertTrue(bridge.get());
2520 XCTAssertNotNil(bridge->view());
2522 XCTAssertNil(bridge->view());
2525 - (void)testSemanticsObjectAndContainerAccessAfterBridgeDestruction {
2526 flutter::MockDelegate mock_delegate;
2528 flutter::TaskRunners runners(
self.name.UTF8String,
2532 thread_task_runner);
2533 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2537 std::make_shared<fml::SyncSwitch>());
2542 enableWideGamut:NO];
2543 OCMStub([mockFlutterViewController view]).andReturn(flutterView);
2546 OCMStub([mockFlutterViewController viewIfLoaded]).andReturn(flutterView);
2548 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
2549 mockFlutterViewController,
2553 flutter::SemanticsNodeUpdates nodes;
2554 flutter::SemanticsNode root_node;
2556 root_node.label =
"root";
2557 root_node.childrenInTraversalOrder = {1};
2558 root_node.childrenInHitTestOrder = {1};
2560 flutter::SemanticsNode child_node;
2562 child_node.label =
"child";
2563 nodes[root_node.id] = root_node;
2564 nodes[child_node.id] = child_node;
2566 flutter::CustomAccessibilityActionUpdates actions;
2567 bridge->UpdateSemantics(nodes, actions);
2569 NSArray* accessibilityElements = flutterView.accessibilityElements;
2570 XCTAssertEqual([accessibilityElements count], 1u);
2572 XCTAssertNotNil(rootContainer);
2574 XCTAssertNotNil(rootObject);
2580 XCTAssertNil([rootContainer accessibilityContainer]);
2584 XCTAssertFalse([rootObject accessibilityActivate]);
2585 XCTAssertTrue(CGPointEqualToPoint([rootObject accessibilityActivationPoint], CGPointZero));
2586 XCTAssertTrue(CGRectEqualToRect([rootObject accessibilityFrame], CGRectZero));
2587 XCTAssertNil([rootObject _accessibilityHitTest:CGPointZero withEvent:nil]);
2590 - (void)testAccessibilityChannelCallbackAfterBridgeDestruction {
2591 flutter::MockDelegate mock_delegate;
2594 fml::MessageLoop::EnsureInitializedForCurrentThread();
2595 auto thread_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
2596 flutter::TaskRunners runners(
self.name.UTF8String,
2600 thread_task_runner);
2601 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2605 std::make_shared<fml::SyncSwitch>());
2611 OCMStub([mockFlutterViewController
engine]).andReturn(mockEngine);
2612 OCMStub([mockEngine binaryMessenger]).andReturn(mockBinaryMessenger);
2616 OCMStub([mockFlutterViewController viewIfLoaded]).andReturn(nil);
2621 OCMStub([mockFlutterViewController isViewLoaded]).andReturn(NO);
2624 OCMStub([mockBinaryMessenger setMessageHandlerOnChannel:
@"flutter/accessibility"
2625 binaryMessageHandler:[OCMArg checkWithBlock:^BOOL(
id obj) {
2627 capturedHandler = [obj copy];
2632 platform_view->SetOwnerViewController(mockFlutterViewController);
2634 auto bridge = std::make_unique<flutter::AccessibilityBridge>(
2635 mockFlutterViewController,
2639 XCTAssertNotNil(capturedHandler);
2643 NSDictionary*
event = @{
@"type" :
@"announce",
@"data" : @{
@"message" :
@"test"}};
2645 if (capturedHandler) {
2646 capturedHandler(messageData, ^(NSData* reply){
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
int64_t FlutterBinaryMessengerConnection
void(^ FlutterResult)(id _Nullable result)
FlutterViewController * viewController
constexpr NS_ASSUME_NONNULL_BEGIN int32_t kRootNodeId
static __weak MockPlatformView * gMockPlatformView
void UpdateSemantics(flutter::SemanticsNodeUpdates nodes, const flutter::CustomAccessibilityActionUpdates &actions)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
SemanticsObject * semanticsObject
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
instancetype sharedInstance()