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)testFlutterSemanticsObjectHasLocale {
577 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
578 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
580 flutter::SemanticsNode node;
581 node.locale =
"es-MX";
585 XCTAssertTrue([
object.accessibilityLanguage isEqualToString:
@"es-MX"]);
588 - (void)testFlutterSemanticsObjectUseDefaultLocale {
591 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
592 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
594 flutter::SemanticsNode node;
599 XCTAssertTrue([
object.accessibilityLanguage isEqualToString:
@"es-MX"]);
602 - (void)testFlutterSemanticsObjectPrioritizedSectionLocale {
605 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
606 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
608 flutter::SemanticsNode node;
611 node.locale =
"zh-TW";
616 XCTAssertTrue([
object.accessibilityLanguage isEqualToString:
@"zh-TW"]);
619 - (void)testFlutterSemanticsObjectLocaleNil {
622 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
623 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
625 flutter::SemanticsNode node;
629 XCTAssertTrue(
object.accessibilityLanguage == nil);
632 - (void)testFlutterScrollableSemanticsObjectWithLabelValueHintIsNotHiddenWhenVoiceOverIsRunning {
635 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
636 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
638 flutter::SemanticsNode node;
639 node.flags.hasImplicitScrolling =
true;
640 node.actions = flutter::kHorizontalScrollSemanticsActions;
641 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
642 node.label =
"label";
643 node.value =
"value";
645 node.scrollExtentMax = 100.0;
646 node.scrollPosition = 0.0;
653 XCTAssertTrue(scrollView.isAccessibilityElement);
655 [scrollView.accessibilityLabel isEqualToString:NSLocalizedString(
@"label",
@"test")]);
657 [scrollView.accessibilityValue isEqualToString:NSLocalizedString(
@"value",
@"test")]);
658 XCTAssertTrue([scrollView.accessibilityHint isEqualToString:NSLocalizedString(
@"hint",
@"test")]);
661 - (void)testFlutterSemanticsObjectMergeTooltipToLabel {
664 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
665 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
667 flutter::SemanticsNode node;
668 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
669 node.label =
"label";
670 node.tooltip =
"tooltip";
673 XCTAssertTrue(
object.isAccessibilityElement);
674 XCTAssertTrue([
object.accessibilityLabel isEqualToString:
@"label\ntooltip"]);
677 - (void)testSemanticsObjectContainerAccessibilityFrameCoversEntireScreen {
680 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
681 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
683 flutter::SemanticsNode parent;
685 parent.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
687 flutter::SemanticsNode child;
689 child.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
690 child.rect = SkRect::MakeXYWH(0, 0, 100, 100);
691 parent.childrenInTraversalOrder.push_back(1);
701 parentObject.
children = @[ childObject ];
708 XCTAssertTrue(childObject.accessibilityRespondsToUserInteraction);
709 XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, UIScreen.mainScreen.bounds));
712 - (void)testFlutterSemanticsObjectAttributedStringsDoNotCrashWhenEmpty {
715 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
716 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
718 flutter::SemanticsNode node;
719 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
722 XCTAssertTrue(
object.accessibilityAttributedLabel == nil);
725 - (void)testFlutterScrollableSemanticsObjectReturnsParentContainerIfNoChildren {
728 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
729 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
731 flutter::SemanticsNode parent;
733 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
734 parent.label =
"label";
735 parent.value =
"value";
736 parent.hint =
"hint";
738 flutter::SemanticsNode node;
740 node.flags.hasImplicitScrolling =
true;
741 node.actions = flutter::kHorizontalScrollSemanticsActions;
742 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
743 node.label =
"label";
744 node.value =
"value";
746 node.scrollExtentMax = 100.0;
747 node.scrollPosition = 0.0;
748 parent.childrenInTraversalOrder.push_back(1);
759 parentObject.
children = @[ scrollable ];
762 XCTAssertTrue(scrollView.isAccessibilityElement);
768 - (void)testFlutterScrollableSemanticsObjectNoScrollBarOrContentInsets {
769 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
771 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
773 flutter::SemanticsNode node;
774 node.flags.hasImplicitScrolling =
true;
775 node.actions = flutter::kHorizontalScrollSemanticsActions;
776 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
777 node.scrollExtentMax = 100.0;
778 node.scrollPosition = 0.0;
786 XCTAssertFalse(scrollView.showsHorizontalScrollIndicator);
787 XCTAssertFalse(scrollView.showsVerticalScrollIndicator);
788 XCTAssertEqual(scrollView.contentInsetAdjustmentBehavior,
789 UIScrollViewContentInsetAdjustmentNever);
790 XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, UIEdgeInsetsZero));
793 - (void)testSemanticsObjectBuildsAttributedString {
794 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
796 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
797 flutter::SemanticsNode node;
798 node.label =
"label";
799 std::shared_ptr<flutter::SpellOutStringAttribute> attribute =
800 std::make_shared<flutter::SpellOutStringAttribute>();
801 attribute->start = 1;
803 attribute->type = flutter::StringAttributeType::kSpellOut;
804 node.labelAttributes.push_back(attribute);
805 node.value =
"value";
806 attribute = std::make_shared<flutter::SpellOutStringAttribute>();
807 attribute->start = 2;
809 attribute->type = flutter::StringAttributeType::kSpellOut;
810 node.valueAttributes.push_back(attribute);
812 std::shared_ptr<flutter::LocaleStringAttribute> local_attribute =
813 std::make_shared<flutter::LocaleStringAttribute>();
814 local_attribute->start = 3;
815 local_attribute->end = 4;
816 local_attribute->type = flutter::StringAttributeType::kLocale;
817 local_attribute->locale =
"en-MX";
818 node.hintAttributes.push_back(local_attribute);
821 NSMutableAttributedString* expectedAttributedLabel =
822 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"label", @"test")];
823 NSDictionary* attributeDict = @{
824 UIAccessibilitySpeechAttributeSpellOut : @YES,
826 [expectedAttributedLabel setAttributes:attributeDict range:NSMakeRange(1, 1)];
828 [
object.accessibilityAttributedLabel isEqualToAttributedString:expectedAttributedLabel]);
830 NSMutableAttributedString* expectedAttributedValue =
831 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"value", @"test")];
833 UIAccessibilitySpeechAttributeSpellOut : @YES,
835 [expectedAttributedValue setAttributes:attributeDict range:NSMakeRange(2, 1)];
837 [
object.accessibilityAttributedValue isEqualToAttributedString:expectedAttributedValue]);
839 NSMutableAttributedString* expectedAttributedHint =
840 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"hint", @"test")];
842 UIAccessibilitySpeechAttributeLanguage :
@"en-MX",
844 [expectedAttributedHint setAttributes:attributeDict range:NSMakeRange(3, 1)];
846 [
object.accessibilityAttributedHint isEqualToAttributedString:expectedAttributedHint]);
849 - (void)testShouldTriggerAnnouncement {
850 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
852 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
856 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
859 flutter::SemanticsNode node;
860 node.flags.isLiveRegion =
true;
862 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
866 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
869 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&node]);
872 flutter::SemanticsNode updatedNode;
873 updatedNode.flags.isLiveRegion =
true;
874 updatedNode.label =
"bar";
875 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&updatedNode]);
878 updatedNode.flags = flutter::SemanticsFlags{};
879 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&updatedNode]);
882 updatedNode.label =
"foo";
884 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
887 - (void)testShouldDispatchShowOnScreenActionForHeader {
888 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
890 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
894 flutter::SemanticsNode node;
895 node.flags.isHeader =
true;
901 [object accessibilityElementDidBecomeFocused];
903 XCTAssertTrue(bridge->observations.size() == 1);
904 XCTAssertTrue(bridge->observations[0].id == 1);
905 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
908 - (void)testShouldDispatchShowOnScreenActionForHidden {
909 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
911 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
915 flutter::SemanticsNode node;
916 node.flags.isHidden =
true;
922 [object accessibilityElementDidBecomeFocused];
924 XCTAssertTrue(bridge->observations.size() == 1);
925 XCTAssertTrue(bridge->observations[0].id == 1);
926 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
929 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitch {
930 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
932 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
937 flutter::SemanticsNode node;
938 node.flags.isToggled = flutter::SemanticsTristate::kTrue;
939 node.flags.isEnabled = flutter::SemanticsTristate::kTrue;
943 UISwitch* nativeSwitch = [[UISwitch alloc] init];
944 nativeSwitch.on = YES;
946 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
947 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
950 flutter::SemanticsNode update;
951 update.flags.isToggled = flutter::SemanticsTristate::kFalse;
952 update.flags.isEnabled = flutter::SemanticsTristate::kTrue;
954 update.label =
"foo";
957 nativeSwitch.on = NO;
959 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
960 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
963 - (void)testFlutterSemanticsObjectOfRadioButton {
964 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
966 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
970 flutter::SemanticsNode node;
971 node.flags.isInMutuallyExclusiveGroup =
true;
972 node.flags.isChecked = flutter::SemanticsCheckState::kFalse;
973 node.flags.isEnabled = flutter::SemanticsTristate::kTrue;
976 XCTAssertTrue((
object.accessibilityTraits & UIAccessibilityTraitButton) > 0);
977 XCTAssertNil(
object.accessibilityValue);
980 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitchDisabled {
981 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
983 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
988 flutter::SemanticsNode node;
989 node.flags.isToggled = flutter::SemanticsTristate::kTrue;
993 UISwitch* nativeSwitch = [[UISwitch alloc] init];
994 nativeSwitch.on = YES;
995 nativeSwitch.enabled = NO;
997 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
998 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
1001 - (void)testSemanticsObjectDeallocated {
1002 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1004 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1012 XCTAssertNil(weakObject);
1015 - (void)testFlutterSemanticsObjectReturnsNilContainerWhenBridgeIsNotAlive {
1020 flutter::SemanticsNode parent;
1022 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1023 parent.label =
"label";
1024 parent.value =
"value";
1025 parent.hint =
"hint";
1027 flutter::SemanticsNode node;
1029 node.flags.hasImplicitScrolling =
true;
1030 node.actions = flutter::kHorizontalScrollSemanticsActions;
1031 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1032 node.label =
"label";
1033 node.value =
"value";
1035 node.scrollExtentMax = 100.0;
1036 node.scrollPosition = 0.0;
1037 parent.childrenInTraversalOrder.push_back(1);
1039 flutter::SemanticsNode node2;
1041 node2.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1042 node2.label =
"label";
1043 node2.value =
"value";
1044 node2.hint =
"hint";
1045 node2.scrollExtentMax = 100.0;
1046 node2.scrollPosition = 0.0;
1047 parent.childrenInTraversalOrder.push_back(2);
1053 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
1054 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1066 parentObject.
children = @[ scrollable, object2 ];
1081 XCTAssertNil(scrollable.accessibilityContainer);
1082 XCTAssertNil(object2.accessibilityContainer);
1085 - (void)testAccessibilityHitTestSearchCanReturnPlatformView {
1086 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1088 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1097 platformView:platformView];
1101 object1.
children = @[ platformViewSemanticsContainer, object3 ];
1104 flutter::SemanticsNode node0;
1106 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1110 flutter::SemanticsNode node1;
1112 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1116 flutter::SemanticsNode node2;
1118 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
1122 flutter::SemanticsNode node3;
1124 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1128 CGPoint point = CGPointMake(10, 10);
1131 XCTAssertEqual(hitTestResult, platformView);
1134 - (void)testFlutterPlatformViewSemanticsContainer {
1135 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
1137 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1142 weakPlatformView = platformView;
1148 platformView:platformView];
1149 weakContainer = container;
1151 XCTAssertNotNil(weakPlatformView);
1152 XCTAssertNotNil(weakContainer);
1156 XCTAssertNotNil(weakPlatformView);
1157 XCTAssertNotNil(weakContainer);
1161 XCTAssertNil(weakPlatformView);
1162 XCTAssertNil(weakContainer);
1165 - (void)testTextInputSemanticsObject {
1166 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1168 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1170 flutter::SemanticsNode node;
1172 node.flags.isTextField =
true;
1173 node.flags.isReadOnly =
true;
1177 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
1180 - (void)testTextInputSemanticsObject_canPerformAction {
1181 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1183 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1185 flutter::SemanticsNode node;
1187 node.flags.isTextField =
true;
1188 node.flags.isReadOnly =
true;
1193 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1194 id partialSemanticsObject = OCMPartialMock(
object);
1195 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1197 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1199 XCTAssertTrue([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1201 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1203 XCTAssertFalse([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1206 - (void)testTextInputSemanticsObject_editActions {
1207 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1209 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1211 flutter::SemanticsNode node;
1214 node.flags.isTextField =
true;
1215 node.flags.isReadOnly =
true;
1220 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1221 id partialSemanticsObject = OCMPartialMock(
object);
1222 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1224 XCTestExpectation* copyExpectation =
1225 [
self expectationWithDescription:@"Surrogate's copy method is called."];
1226 XCTestExpectation* cutExpectation =
1227 [
self expectationWithDescription:@"Surrogate's cut method is called."];
1228 XCTestExpectation* pasteExpectation =
1229 [
self expectationWithDescription:@"Surrogate's paste method is called."];
1230 XCTestExpectation* selectAllExpectation =
1231 [
self expectationWithDescription:@"Surrogate's selectAll method is called."];
1232 XCTestExpectation* deleteExpectation =
1233 [
self expectationWithDescription:@"Surrogate's delete method is called."];
1235 OCMStub([textInputSurrogate copy:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1236 [copyExpectation fulfill];
1238 OCMStub([textInputSurrogate cut:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1239 [cutExpectation fulfill];
1241 OCMStub([textInputSurrogate paste:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1242 [pasteExpectation fulfill];
1244 OCMStub([textInputSurrogate selectAll:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1245 [selectAllExpectation fulfill];
1247 OCMStub([textInputSurrogate
delete:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1248 [deleteExpectation fulfill];
1251 [partialSemanticsObject copy:nil];
1252 [partialSemanticsObject cut:nil];
1253 [partialSemanticsObject paste:nil];
1254 [partialSemanticsObject selectAll:nil];
1255 [partialSemanticsObject delete:nil];
1257 [
self waitForExpectationsWithTimeout:1 handler:nil];
1260 - (void)testSliderSemanticsObject {
1261 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1263 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1265 flutter::SemanticsNode node;
1266 node.flags.isSlider =
true;
1270 XCTAssertEqual([
object accessibilityActivate], YES);
1273 - (void)testUIFocusItemConformance {
1274 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1276 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1282 XCTAssertTrue([parent.parentFocusEnvironment isKindOfClass:[UIView
class]]);
1283 XCTAssertEqual(child.parentFocusEnvironment, child.
parent);
1286 flutter::SemanticsNode childNode;
1287 childNode.flags.isHidden =
true;
1288 childNode.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
1290 XCTAssertFalse(child.canBecomeFocused);
1291 childNode.flags = flutter::SemanticsFlags{};
1293 XCTAssertTrue(child.canBecomeFocused);
1294 childNode.actions = 0;
1296 XCTAssertFalse(child.canBecomeFocused);
1298 CGFloat scale = ((bridge->view().window.screen ?: UIScreen.mainScreen)).scale;
1300 childNode.rect = SkRect::MakeXYWH(0, 0, 100 * scale, 100 * scale);
1302 flutter::SemanticsNode parentNode;
1303 parentNode.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1306 XCTAssertTrue(CGRectEqualToRect(child.frame, CGRectMake(0, 0, 100, 100)));
1309 - (void)testUIFocusItemContainerConformance {
1310 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1312 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1319 NSArray<id<UIFocusItem>>* itemsInRect = [parent focusItemsInRect:CGRectMake(0, 0, 100, 100)];
1320 XCTAssertEqual(itemsInRect.count, (
unsigned long)2);
1321 XCTAssertTrue([itemsInRect containsObject:child1]);
1322 XCTAssertTrue([itemsInRect containsObject:child2]);
1325 - (void)testUIFocusItemScrollableContainerConformance {
1326 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1328 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1333 CGPoint p = CGPointMake(123.0, 456.0);
1334 [scrollable.scrollView scrollViewWillEndDragging:scrollable.scrollView
1335 withVelocity:CGPointZero
1336 targetContentOffset:&p];
1338 [scrollable.scrollView scrollViewDidEndDecelerating:scrollable.scrollView];
1339 XCTAssertEqual(bridge->observations.size(), (
size_t)1);
1340 XCTAssertEqual(bridge->observations[0].id, 5);
1341 XCTAssertEqual(bridge->observations[0].action, flutter::SemanticsAction::kScrollToOffset);
1343 std::vector<uint8_t> args = bridge->observations[0].args;
1344 XCTAssertEqual(args.size(), 3 *
sizeof(CGFloat));
1346 NSData* encoded = [NSData dataWithBytes:args.data() length:args.size()];
1348 CGPoint point = CGPointZero;
1349 memcpy(&point, decoded.
data.bytes, decoded.
data.length);
1350 XCTAssertTrue(CGPointEqualToPoint(point, p));
1353 - (void)testUIFocusItemScrollableContainerNoFeedbackLoops {
1354 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1356 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1361 const CGPoint p = CGPointMake(0.0, 456.0);
1363 bridge->observations.clear();
1365 const SkScalar scrollPosition = p.y + 0.0000000000000001;
1366 flutter::SemanticsNode node;
1367 node.flags.hasImplicitScrolling =
true;
1368 node.actions = flutter::kVerticalScrollSemanticsActions;
1369 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1370 node.scrollExtentMax = 10000;
1371 node.scrollPosition = scrollPosition;
1372 node.transform = {1.0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 1.0, 0, 0, scrollPosition, 0, 1.0};
1376 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()