5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
24 UIFocusItemScrollableContainer>
37 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
39 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
41 XCTAssertNotNil(
object);
44 - (void)testSetChildren {
45 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
47 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
51 XCTAssertEqual(parent, child.
parent);
53 XCTAssertNil(child.
parent);
56 - (void)testAccessibilityHitTestFocusAtLeaf {
57 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
59 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
66 object1.
children = @[ object2, object3 ];
69 flutter::SemanticsNode node0;
71 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
75 flutter::SemanticsNode node1;
77 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
81 flutter::SemanticsNode node2;
83 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
87 flutter::SemanticsNode node3;
89 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
93 CGPoint point = CGPointMake(10, 10);
97 XCTAssertEqual(hitTestResult, object2);
100 - (void)testAccessibilityHitTestNoFocusableItem {
101 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
103 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
110 object1.
children = @[ object2, object3 ];
113 flutter::SemanticsNode node0;
115 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
118 flutter::SemanticsNode node1;
120 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
123 flutter::SemanticsNode node2;
125 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
128 flutter::SemanticsNode node3;
130 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
133 CGPoint point = CGPointMake(10, 10);
136 XCTAssertNil(hitTestResult);
139 - (void)testAccessibilityScrollToVisible {
140 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
142 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
145 flutter::SemanticsNode node3;
147 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
152 XCTAssertTrue(bridge->observations.size() == 1);
153 XCTAssertTrue(bridge->observations[0].id == 3);
154 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
157 - (void)testAccessibilityScrollToVisibleWithChild {
158 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
160 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
163 flutter::SemanticsNode node3;
165 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
170 XCTAssertTrue(bridge->observations.size() == 1);
171 XCTAssertTrue(bridge->observations[0].id == 3);
172 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
175 - (void)testAccessibilityHitTestOutOfRect {
176 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
178 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
185 object1.
children = @[ object2, object3 ];
188 flutter::SemanticsNode node0;
190 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
194 flutter::SemanticsNode node1;
196 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
200 flutter::SemanticsNode node2;
202 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
206 flutter::SemanticsNode node3;
208 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
212 CGPoint point = CGPointMake(300, 300);
215 XCTAssertNil(hitTestResult);
218 - (void)testReplaceChildAtIndex {
219 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
221 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
227 XCTAssertNil(child1.
parent);
228 XCTAssertEqual(parent, child2.
parent);
229 XCTAssertEqualObjects(parent.
children, @[ child2 ]);
232 - (void)testPlainSemanticsObjectWithLabelHasStaticTextTrait {
233 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
235 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
236 flutter::SemanticsNode node;
240 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitStaticText);
243 - (void)testNodeWithImplicitScrollIsAnAccessibilityElementWhenItisHidden {
244 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
246 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
247 flutter::SemanticsNode node;
249 node.flags.hasImplicitScrolling =
true;
250 node.flags.isHidden =
true;
253 XCTAssertEqual(
object.isAccessibilityElement, YES);
256 - (void)testNodeWithImplicitScrollIsNotAnAccessibilityElementWhenItisNotHidden {
257 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
259 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
260 flutter::SemanticsNode node;
261 node.flags.hasImplicitScrolling =
true;
264 XCTAssertEqual(
object.isAccessibilityElement, NO);
267 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait {
268 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
270 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
271 flutter::SemanticsNode node;
277 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
280 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait1 {
281 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
283 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
284 flutter::SemanticsNode node;
286 node.flags.isTextField =
true;
289 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
292 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait2 {
293 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
295 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
296 flutter::SemanticsNode node;
299 node.flags.isButton =
true;
302 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitButton);
305 - (void)testVerticalFlutterScrollableSemanticsObject {
306 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
308 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
310 float transformScale = 0.5f;
311 float screenScale = [[bridge->view() window] screen].scale;
312 float effectivelyScale = transformScale / screenScale;
317 float scrollExtentMax = 500.0;
318 float scrollPosition = 150.0;
320 flutter::SemanticsNode node;
321 node.flags.hasImplicitScrolling =
true;
322 node.actions = flutter::kVerticalScrollSemanticsActions;
323 node.rect = SkRect::MakeXYWH(x, y, w, h);
324 node.scrollExtentMax = scrollExtentMax;
325 node.scrollPosition = scrollPosition;
327 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
334 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
335 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
336 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
338 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
341 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
343 XCTAssertEqualWithAccuracy(scrollView.contentSize.height,
346 XCTAssertEqual(scrollView.contentOffset.x, 0);
347 XCTAssertEqualWithAccuracy(scrollView.contentOffset.y, scrollPosition * effectivelyScale,
351 - (void)testVerticalFlutterScrollableSemanticsObjectNoWindowDoesNotCrash {
352 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
354 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
356 float transformScale = 0.5f;
361 float scrollExtentMax = 500.0;
362 float scrollPosition = 150.0;
364 flutter::SemanticsNode node;
365 node.flags.hasImplicitScrolling =
true;
366 node.actions = flutter::kVerticalScrollSemanticsActions;
367 node.rect = SkRect::MakeXYWH(x, y, w, h);
368 node.scrollExtentMax = scrollExtentMax;
369 node.scrollPosition = scrollPosition;
371 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
376 XCTAssertNoThrow([scrollable accessibilityBridgeDidFinishUpdate]);
379 - (void)testHorizontalFlutterScrollableSemanticsObject {
380 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
382 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
384 float transformScale = 0.5f;
385 float screenScale = [[bridge->view() window] screen].scale;
386 float effectivelyScale = transformScale / screenScale;
391 float scrollExtentMax = 500.0;
392 float scrollPosition = 150.0;
394 flutter::SemanticsNode node;
395 node.flags.hasImplicitScrolling =
true;
396 node.actions = flutter::kHorizontalScrollSemanticsActions;
397 node.rect = SkRect::MakeXYWH(x, y, w, h);
398 node.scrollExtentMax = scrollExtentMax;
399 node.scrollPosition = scrollPosition;
401 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
408 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
409 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
410 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
412 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
415 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, (w + scrollExtentMax) * effectivelyScale,
417 XCTAssertEqualWithAccuracy(scrollView.contentSize.height, h * effectivelyScale,
420 XCTAssertEqualWithAccuracy(scrollView.contentOffset.x, scrollPosition * effectivelyScale,
422 XCTAssertEqual(scrollView.contentOffset.y, 0);
425 - (void)testCanHandleInfiniteScrollExtent {
426 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
428 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
430 float transformScale = 0.5f;
431 float screenScale = [[bridge->view() window] screen].scale;
432 float effectivelyScale = transformScale / screenScale;
437 float scrollExtentMax = INFINITY;
438 float scrollPosition = 150.0;
440 flutter::SemanticsNode node;
441 node.flags.hasImplicitScrolling =
true;
442 node.actions = flutter::kVerticalScrollSemanticsActions;
443 node.rect = SkRect::MakeXYWH(x, y, w, h);
444 node.scrollExtentMax = scrollExtentMax;
445 node.scrollPosition = scrollPosition;
447 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
453 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
454 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
455 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
457 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
460 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
462 XCTAssertEqualWithAccuracy(scrollView.contentSize.height,
466 XCTAssertEqual(scrollView.contentOffset.x, 0);
467 XCTAssertEqualWithAccuracy(scrollView.contentOffset.y, scrollPosition * effectivelyScale,
471 - (void)testCanHandleNaNScrollExtentAndScrollPoisition {
472 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
474 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
476 float transformScale = 0.5f;
477 float screenScale = [[bridge->view() window] screen].scale;
478 float effectivelyScale = transformScale / screenScale;
483 float scrollExtentMax = std::nan(
"");
484 float scrollPosition = std::nan(
"");
486 flutter::SemanticsNode node;
487 node.flags.hasImplicitScrolling =
true;
488 node.actions = flutter::kVerticalScrollSemanticsActions;
489 node.rect = SkRect::MakeXYWH(x, y, w, h);
490 node.scrollExtentMax = scrollExtentMax;
491 node.scrollPosition = scrollPosition;
493 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
500 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
501 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
502 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
504 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
508 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
510 XCTAssertEqualWithAccuracy(scrollView.contentSize.height, h * effectivelyScale,
513 XCTAssertEqual(scrollView.contentOffset.x, 0);
514 XCTAssertEqual(scrollView.contentOffset.y, 0);
517 - (void)testFlutterScrollableSemanticsObjectIsNotHittestable {
518 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
520 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
522 flutter::SemanticsNode node;
523 node.flags.hasImplicitScrolling =
true;
524 node.actions = flutter::kHorizontalScrollSemanticsActions;
525 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
526 node.scrollExtentMax = 100.0;
527 node.scrollPosition = 0.0;
534 XCTAssertEqual([scrollView hitTest:CGPointMake(10, 10) withEvent:nil], nil);
537 - (void)testFlutterScrollableSemanticsObjectIsHiddenWhenVoiceOverIsRunning {
540 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
541 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
543 flutter::SemanticsNode node;
544 node.flags.hasImplicitScrolling =
true;
545 node.actions = flutter::kHorizontalScrollSemanticsActions;
546 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
547 node.scrollExtentMax = 100.0;
548 node.scrollPosition = 0.0;
555 XCTAssertTrue(scrollView.isAccessibilityElement);
557 XCTAssertFalse(scrollView.isAccessibilityElement);
560 - (void)testFlutterSemanticsObjectHasIdentifier {
563 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
564 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
566 flutter::SemanticsNode node;
567 node.identifier =
"identifier";
571 XCTAssertTrue([
object.accessibilityIdentifier isEqualToString:
@"identifier"]);
574 - (void)testFlutterScrollableSemanticsObjectWithLabelValueHintIsNotHiddenWhenVoiceOverIsRunning {
577 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
578 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
580 flutter::SemanticsNode node;
581 node.flags.hasImplicitScrolling =
true;
582 node.actions = flutter::kHorizontalScrollSemanticsActions;
583 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
584 node.label =
"label";
585 node.value =
"value";
587 node.scrollExtentMax = 100.0;
588 node.scrollPosition = 0.0;
595 XCTAssertTrue(scrollView.isAccessibilityElement);
597 [scrollView.accessibilityLabel isEqualToString:NSLocalizedString(
@"label",
@"test")]);
599 [scrollView.accessibilityValue isEqualToString:NSLocalizedString(
@"value",
@"test")]);
600 XCTAssertTrue([scrollView.accessibilityHint isEqualToString:NSLocalizedString(
@"hint",
@"test")]);
603 - (void)testFlutterSemanticsObjectMergeTooltipToLabel {
606 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
607 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
609 flutter::SemanticsNode node;
610 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
611 node.label =
"label";
612 node.tooltip =
"tooltip";
615 XCTAssertTrue(
object.isAccessibilityElement);
616 XCTAssertTrue([
object.accessibilityLabel isEqualToString:
@"label\ntooltip"]);
619 - (void)testSemanticsObjectContainerAccessibilityFrameCoversEntireScreen {
622 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
623 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
625 flutter::SemanticsNode parent;
627 parent.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
629 flutter::SemanticsNode child;
631 child.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
632 child.rect = SkRect::MakeXYWH(0, 0, 100, 100);
633 parent.childrenInTraversalOrder.push_back(1);
643 parentObject.
children = @[ childObject ];
650 XCTAssertTrue(childObject.accessibilityRespondsToUserInteraction);
651 XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, UIScreen.mainScreen.bounds));
654 - (void)testFlutterSemanticsObjectAttributedStringsDoNotCrashWhenEmpty {
657 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
658 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
660 flutter::SemanticsNode node;
661 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
664 XCTAssertTrue(
object.accessibilityAttributedLabel == nil);
667 - (void)testFlutterScrollableSemanticsObjectReturnsParentContainerIfNoChildren {
670 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
671 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
673 flutter::SemanticsNode parent;
675 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
676 parent.label =
"label";
677 parent.value =
"value";
678 parent.hint =
"hint";
680 flutter::SemanticsNode node;
682 node.flags.hasImplicitScrolling =
true;
683 node.actions = flutter::kHorizontalScrollSemanticsActions;
684 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
685 node.label =
"label";
686 node.value =
"value";
688 node.scrollExtentMax = 100.0;
689 node.scrollPosition = 0.0;
690 parent.childrenInTraversalOrder.push_back(1);
701 parentObject.
children = @[ scrollable ];
704 XCTAssertTrue(scrollView.isAccessibilityElement);
710 - (void)testFlutterScrollableSemanticsObjectNoScrollBarOrContentInsets {
711 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
713 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
715 flutter::SemanticsNode node;
716 node.flags.hasImplicitScrolling =
true;
717 node.actions = flutter::kHorizontalScrollSemanticsActions;
718 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
719 node.scrollExtentMax = 100.0;
720 node.scrollPosition = 0.0;
728 XCTAssertFalse(scrollView.showsHorizontalScrollIndicator);
729 XCTAssertFalse(scrollView.showsVerticalScrollIndicator);
730 XCTAssertEqual(scrollView.contentInsetAdjustmentBehavior,
731 UIScrollViewContentInsetAdjustmentNever);
732 XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, UIEdgeInsetsZero));
735 - (void)testSemanticsObjectBuildsAttributedString {
736 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
738 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
739 flutter::SemanticsNode node;
740 node.label =
"label";
741 std::shared_ptr<flutter::SpellOutStringAttribute> attribute =
742 std::make_shared<flutter::SpellOutStringAttribute>();
743 attribute->start = 1;
745 attribute->type = flutter::StringAttributeType::kSpellOut;
746 node.labelAttributes.push_back(attribute);
747 node.value =
"value";
748 attribute = std::make_shared<flutter::SpellOutStringAttribute>();
749 attribute->start = 2;
751 attribute->type = flutter::StringAttributeType::kSpellOut;
752 node.valueAttributes.push_back(attribute);
754 std::shared_ptr<flutter::LocaleStringAttribute> local_attribute =
755 std::make_shared<flutter::LocaleStringAttribute>();
756 local_attribute->start = 3;
757 local_attribute->end = 4;
758 local_attribute->type = flutter::StringAttributeType::kLocale;
759 local_attribute->locale =
"en-MX";
760 node.hintAttributes.push_back(local_attribute);
763 NSMutableAttributedString* expectedAttributedLabel =
764 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"label", @"test")];
765 NSDictionary* attributeDict = @{
766 UIAccessibilitySpeechAttributeSpellOut : @YES,
768 [expectedAttributedLabel setAttributes:attributeDict range:NSMakeRange(1, 1)];
770 [
object.accessibilityAttributedLabel isEqualToAttributedString:expectedAttributedLabel]);
772 NSMutableAttributedString* expectedAttributedValue =
773 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"value", @"test")];
775 UIAccessibilitySpeechAttributeSpellOut : @YES,
777 [expectedAttributedValue setAttributes:attributeDict range:NSMakeRange(2, 1)];
779 [
object.accessibilityAttributedValue isEqualToAttributedString:expectedAttributedValue]);
781 NSMutableAttributedString* expectedAttributedHint =
782 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"hint", @"test")];
784 UIAccessibilitySpeechAttributeLanguage :
@"en-MX",
786 [expectedAttributedHint setAttributes:attributeDict range:NSMakeRange(3, 1)];
788 [
object.accessibilityAttributedHint isEqualToAttributedString:expectedAttributedHint]);
791 - (void)testShouldTriggerAnnouncement {
792 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
794 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
798 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
801 flutter::SemanticsNode node;
802 node.flags.isLiveRegion =
true;
804 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
808 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
811 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&node]);
814 flutter::SemanticsNode updatedNode;
815 updatedNode.flags.isLiveRegion =
true;
816 updatedNode.label =
"bar";
817 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&updatedNode]);
820 updatedNode.flags = flutter::SemanticsFlags{};
821 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&updatedNode]);
824 updatedNode.label =
"foo";
826 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
829 - (void)testShouldDispatchShowOnScreenActionForHeader {
830 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
832 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
836 flutter::SemanticsNode node;
837 node.flags.isHeader =
true;
843 [object accessibilityElementDidBecomeFocused];
845 XCTAssertTrue(bridge->observations.size() == 1);
846 XCTAssertTrue(bridge->observations[0].id == 1);
847 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
850 - (void)testShouldDispatchShowOnScreenActionForHidden {
851 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
853 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
857 flutter::SemanticsNode node;
858 node.flags.isHidden =
true;
864 [object accessibilityElementDidBecomeFocused];
866 XCTAssertTrue(bridge->observations.size() == 1);
867 XCTAssertTrue(bridge->observations[0].id == 1);
868 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
871 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitch {
872 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
874 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
879 flutter::SemanticsNode node;
880 node.flags.hasToggledState =
true;
881 node.flags.isToggled =
true;
882 node.flags.isEnabled =
true;
886 UISwitch* nativeSwitch = [[UISwitch alloc] init];
887 nativeSwitch.on = YES;
889 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
890 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
893 flutter::SemanticsNode update;
894 update.flags.hasToggledState =
true;
895 update.flags.isToggled =
false;
896 update.flags.isEnabled =
true;
898 update.label =
"foo";
901 nativeSwitch.on = NO;
903 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
904 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
907 - (void)testFlutterSemanticsObjectOfRadioButton {
908 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
910 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
914 flutter::SemanticsNode node;
915 node.flags.isInMutuallyExclusiveGroup =
true;
916 node.flags.hasCheckedState =
true;
917 node.flags.hasEnabledState =
true;
918 node.flags.isEnabled =
true;
921 XCTAssertTrue((
object.accessibilityTraits & UIAccessibilityTraitButton) > 0);
922 XCTAssertNil(
object.accessibilityValue);
925 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitchDisabled {
926 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
928 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
933 flutter::SemanticsNode node;
934 node.flags.hasToggledState =
true;
935 node.flags.isToggled =
true;
939 UISwitch* nativeSwitch = [[UISwitch alloc] init];
940 nativeSwitch.on = YES;
941 nativeSwitch.enabled = NO;
943 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
944 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
947 - (void)testSemanticsObjectDeallocated {
948 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
950 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
958 XCTAssertNil(weakObject);
961 - (void)testFlutterSemanticsObjectReturnsNilContainerWhenBridgeIsNotAlive {
966 flutter::SemanticsNode parent;
968 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
969 parent.label =
"label";
970 parent.value =
"value";
971 parent.hint =
"hint";
973 flutter::SemanticsNode node;
975 node.flags.hasImplicitScrolling =
true;
976 node.actions = flutter::kHorizontalScrollSemanticsActions;
977 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
978 node.label =
"label";
979 node.value =
"value";
981 node.scrollExtentMax = 100.0;
982 node.scrollPosition = 0.0;
983 parent.childrenInTraversalOrder.push_back(1);
985 flutter::SemanticsNode node2;
987 node2.rect = SkRect::MakeXYWH(0, 0, 100, 200);
988 node2.label =
"label";
989 node2.value =
"value";
991 node2.scrollExtentMax = 100.0;
992 node2.scrollPosition = 0.0;
993 parent.childrenInTraversalOrder.push_back(2);
999 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
1000 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1012 parentObject.
children = @[ scrollable, object2 ];
1027 XCTAssertNil(scrollable.accessibilityContainer);
1028 XCTAssertNil(object2.accessibilityContainer);
1031 - (void)testAccessibilityHitTestSearchCanReturnPlatformView {
1032 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1034 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1043 platformView:platformView];
1047 object1.
children = @[ platformViewSemanticsContainer, object3 ];
1050 flutter::SemanticsNode node0;
1052 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1056 flutter::SemanticsNode node1;
1058 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1062 flutter::SemanticsNode node2;
1064 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
1068 flutter::SemanticsNode node3;
1070 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1074 CGPoint point = CGPointMake(10, 10);
1077 XCTAssertEqual(hitTestResult, platformView);
1080 - (void)testFlutterPlatformViewSemanticsContainer {
1081 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
1083 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1088 weakPlatformView = platformView;
1094 platformView:platformView];
1095 weakContainer = container;
1097 XCTAssertNotNil(weakPlatformView);
1098 XCTAssertNotNil(weakContainer);
1102 XCTAssertNotNil(weakPlatformView);
1103 XCTAssertNotNil(weakContainer);
1107 XCTAssertNil(weakPlatformView);
1108 XCTAssertNil(weakContainer);
1111 - (void)testTextInputSemanticsObject {
1112 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1114 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1116 flutter::SemanticsNode node;
1118 node.flags.isTextField =
true;
1119 node.flags.isReadOnly =
true;
1123 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
1126 - (void)testTextInputSemanticsObject_canPerformAction {
1127 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1129 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1131 flutter::SemanticsNode node;
1133 node.flags.isTextField =
true;
1134 node.flags.isReadOnly =
true;
1139 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1140 id partialSemanticsObject = OCMPartialMock(
object);
1141 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1143 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1145 XCTAssertTrue([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1147 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1149 XCTAssertFalse([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1152 - (void)testTextInputSemanticsObject_editActions {
1153 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1155 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1157 flutter::SemanticsNode node;
1160 node.flags.isTextField =
true;
1161 node.flags.isReadOnly =
true;
1166 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1167 id partialSemanticsObject = OCMPartialMock(
object);
1168 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1170 XCTestExpectation* copyExpectation =
1171 [
self expectationWithDescription:@"Surrogate's copy method is called."];
1172 XCTestExpectation* cutExpectation =
1173 [
self expectationWithDescription:@"Surrogate's cut method is called."];
1174 XCTestExpectation* pasteExpectation =
1175 [
self expectationWithDescription:@"Surrogate's paste method is called."];
1176 XCTestExpectation* selectAllExpectation =
1177 [
self expectationWithDescription:@"Surrogate's selectAll method is called."];
1178 XCTestExpectation* deleteExpectation =
1179 [
self expectationWithDescription:@"Surrogate's delete method is called."];
1181 OCMStub([textInputSurrogate copy:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1182 [copyExpectation fulfill];
1184 OCMStub([textInputSurrogate cut:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1185 [cutExpectation fulfill];
1187 OCMStub([textInputSurrogate paste:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1188 [pasteExpectation fulfill];
1190 OCMStub([textInputSurrogate selectAll:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1191 [selectAllExpectation fulfill];
1193 OCMStub([textInputSurrogate
delete:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1194 [deleteExpectation fulfill];
1197 [partialSemanticsObject copy:nil];
1198 [partialSemanticsObject cut:nil];
1199 [partialSemanticsObject paste:nil];
1200 [partialSemanticsObject selectAll:nil];
1201 [partialSemanticsObject delete:nil];
1203 [
self waitForExpectationsWithTimeout:1 handler:nil];
1206 - (void)testSliderSemanticsObject {
1207 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1209 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1211 flutter::SemanticsNode node;
1212 node.flags.isSlider =
true;
1216 XCTAssertEqual([
object accessibilityActivate], YES);
1219 - (void)testUIFocusItemConformance {
1220 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1222 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1228 XCTAssertTrue([parent.parentFocusEnvironment isKindOfClass:[UIView
class]]);
1229 XCTAssertEqual(child.parentFocusEnvironment, child.
parent);
1232 flutter::SemanticsNode childNode;
1233 childNode.flags.isHidden =
true;
1234 childNode.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
1236 XCTAssertFalse(child.canBecomeFocused);
1237 childNode.flags = flutter::SemanticsFlags{};
1239 XCTAssertTrue(child.canBecomeFocused);
1240 childNode.actions = 0;
1242 XCTAssertFalse(child.canBecomeFocused);
1244 CGFloat scale = ((bridge->view().window.screen ?: UIScreen.mainScreen)).scale;
1246 childNode.rect = SkRect::MakeXYWH(0, 0, 100 * scale, 100 * scale);
1248 flutter::SemanticsNode parentNode;
1249 parentNode.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1252 XCTAssertTrue(CGRectEqualToRect(child.frame, CGRectMake(0, 0, 100, 100)));
1255 - (void)testUIFocusItemContainerConformance {
1256 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1258 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1265 NSArray<id<UIFocusItem>>* itemsInRect = [parent focusItemsInRect:CGRectMake(0, 0, 100, 100)];
1266 XCTAssertEqual(itemsInRect.count, (
unsigned long)2);
1267 XCTAssertTrue([itemsInRect containsObject:child1]);
1268 XCTAssertTrue([itemsInRect containsObject:child2]);
1271 - (void)testUIFocusItemScrollableContainerConformance {
1272 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1274 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1279 CGPoint p = CGPointMake(123.0, 456.0);
1280 [scrollable.scrollView scrollViewWillEndDragging:scrollable.scrollView
1281 withVelocity:CGPointZero
1282 targetContentOffset:&p];
1284 [scrollable.scrollView scrollViewDidEndDecelerating:scrollable.scrollView];
1285 XCTAssertEqual(bridge->observations.size(), (
size_t)1);
1286 XCTAssertEqual(bridge->observations[0].id, 5);
1287 XCTAssertEqual(bridge->observations[0].action, flutter::SemanticsAction::kScrollToOffset);
1289 std::vector<uint8_t> args = bridge->observations[0].args;
1290 XCTAssertEqual(args.size(), 3 *
sizeof(CGFloat));
1292 NSData* encoded = [NSData dataWithBytes:args.data() length:args.size()];
1294 CGPoint point = CGPointZero;
1295 memcpy(&point, decoded.
data.bytes, decoded.
data.length);
1296 XCTAssertTrue(CGPointEqualToPoint(point, p));
1299 - (void)testUIFocusItemScrollableContainerNoFeedbackLoops {
1300 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1302 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1307 const CGPoint p = CGPointMake(0.0, 456.0);
1309 bridge->observations.clear();
1311 const SkScalar scrollPosition = p.y + 0.0000000000000001;
1312 flutter::SemanticsNode node;
1313 node.flags.hasImplicitScrolling =
true;
1314 node.actions = flutter::kVerticalScrollSemanticsActions;
1315 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1316 node.scrollExtentMax = 10000;
1317 node.scrollPosition = scrollPosition;
1318 node.transform = {1.0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 1.0, 0, 0, scrollPosition, 0, 1.0};
1322 XCTAssertEqual(bridge->observations.size(), (
size_t)0);
constexpr float kScrollExtentMaxForInf
FLUTTER_ASSERT_ARC const float kFloatCompareEpsilon
UIView< UITextInput > * textInputSurrogate()
id accessibilityContainer()
bool isVoiceOverRunningValue
SemanticsObject * semanticsObject
id _accessibilityHitTest:withEvent:(CGPoint point,[withEvent] UIEvent *event)
NSArray< SemanticsObject * > * childrenInHitTestOrder
BOOL accessibilityScrollToVisibleWithChild:(id child)
void accessibilityBridgeDidFinishUpdate()
BOOL accessibilityScrollToVisible()
NSArray< SemanticsObject * > * children
void replaceChildAtIndex:withChild:(NSInteger index,[withChild] SemanticsObject *child)
void setSemanticsNode:(const flutter::SemanticsNode *NS_REQUIRES_SUPER)
instancetype sharedInstance()