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;
248 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling) |
249 static_cast<int32_t
>(flutter::SemanticsFlags::kIsHidden);
252 XCTAssertEqual(
object.isAccessibilityElement, YES);
255 - (void)testNodeWithImplicitScrollIsNotAnAccessibilityElementWhenItisNotHidden {
256 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
258 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
259 flutter::SemanticsNode node;
260 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
263 XCTAssertEqual(
object.isAccessibilityElement, NO);
266 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait {
267 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
269 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
270 flutter::SemanticsNode node;
276 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
279 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait1 {
280 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
282 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
283 flutter::SemanticsNode node;
285 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsTextField);
288 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
291 - (void)testIntresetingSemanticsObjectWithLabelHasStaticTextTrait2 {
292 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
294 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
295 flutter::SemanticsNode node;
297 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsButton);
300 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitButton);
303 - (void)testVerticalFlutterScrollableSemanticsObject {
304 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
306 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
308 float transformScale = 0.5f;
309 float screenScale = [[bridge->view() window] screen].scale;
310 float effectivelyScale = transformScale / screenScale;
315 float scrollExtentMax = 500.0;
316 float scrollPosition = 150.0;
318 flutter::SemanticsNode node;
319 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
320 node.actions = flutter::kVerticalScrollSemanticsActions;
321 node.rect = SkRect::MakeXYWH(x, y, w, h);
322 node.scrollExtentMax = scrollExtentMax;
323 node.scrollPosition = scrollPosition;
325 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
332 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
333 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
334 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
336 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
339 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
341 XCTAssertEqualWithAccuracy(scrollView.contentSize.height,
344 XCTAssertEqual(scrollView.contentOffset.x, 0);
345 XCTAssertEqualWithAccuracy(scrollView.contentOffset.y, scrollPosition * effectivelyScale,
349 - (void)testVerticalFlutterScrollableSemanticsObjectNoWindowDoesNotCrash {
350 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
352 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
354 float transformScale = 0.5f;
359 float scrollExtentMax = 500.0;
360 float scrollPosition = 150.0;
362 flutter::SemanticsNode node;
363 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
364 node.actions = flutter::kVerticalScrollSemanticsActions;
365 node.rect = SkRect::MakeXYWH(x, y, w, h);
366 node.scrollExtentMax = scrollExtentMax;
367 node.scrollPosition = scrollPosition;
369 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
374 XCTAssertNoThrow([scrollable accessibilityBridgeDidFinishUpdate]);
377 - (void)testHorizontalFlutterScrollableSemanticsObject {
378 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
380 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
382 float transformScale = 0.5f;
383 float screenScale = [[bridge->view() window] screen].scale;
384 float effectivelyScale = transformScale / screenScale;
389 float scrollExtentMax = 500.0;
390 float scrollPosition = 150.0;
392 flutter::SemanticsNode node;
393 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
394 node.actions = flutter::kHorizontalScrollSemanticsActions;
395 node.rect = SkRect::MakeXYWH(x, y, w, h);
396 node.scrollExtentMax = scrollExtentMax;
397 node.scrollPosition = scrollPosition;
399 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
406 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
407 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
408 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
410 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
413 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, (w + scrollExtentMax) * effectivelyScale,
415 XCTAssertEqualWithAccuracy(scrollView.contentSize.height, h * effectivelyScale,
418 XCTAssertEqualWithAccuracy(scrollView.contentOffset.x, scrollPosition * effectivelyScale,
420 XCTAssertEqual(scrollView.contentOffset.y, 0);
423 - (void)testCanHandleInfiniteScrollExtent {
424 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
426 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
428 float transformScale = 0.5f;
429 float screenScale = [[bridge->view() window] screen].scale;
430 float effectivelyScale = transformScale / screenScale;
435 float scrollExtentMax = INFINITY;
436 float scrollPosition = 150.0;
438 flutter::SemanticsNode node;
439 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
440 node.actions = flutter::kVerticalScrollSemanticsActions;
441 node.rect = SkRect::MakeXYWH(x, y, w, h);
442 node.scrollExtentMax = scrollExtentMax;
443 node.scrollPosition = scrollPosition;
445 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
451 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
452 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
453 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
455 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
458 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
460 XCTAssertEqualWithAccuracy(scrollView.contentSize.height,
464 XCTAssertEqual(scrollView.contentOffset.x, 0);
465 XCTAssertEqualWithAccuracy(scrollView.contentOffset.y, scrollPosition * effectivelyScale,
469 - (void)testCanHandleNaNScrollExtentAndScrollPoisition {
470 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
472 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
474 float transformScale = 0.5f;
475 float screenScale = [[bridge->view() window] screen].scale;
476 float effectivelyScale = transformScale / screenScale;
481 float scrollExtentMax = std::nan(
"");
482 float scrollPosition = std::nan(
"");
484 flutter::SemanticsNode node;
485 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
486 node.actions = flutter::kVerticalScrollSemanticsActions;
487 node.rect = SkRect::MakeXYWH(x, y, w, h);
488 node.scrollExtentMax = scrollExtentMax;
489 node.scrollPosition = scrollPosition;
491 transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
498 XCTAssertEqualWithAccuracy(scrollView.frame.origin.x, x * effectivelyScale,
kFloatCompareEpsilon);
499 XCTAssertEqualWithAccuracy(scrollView.frame.origin.y, y * effectivelyScale,
kFloatCompareEpsilon);
500 XCTAssertEqualWithAccuracy(scrollView.frame.size.width, w * effectivelyScale,
502 XCTAssertEqualWithAccuracy(scrollView.frame.size.height, h * effectivelyScale,
506 XCTAssertEqualWithAccuracy(scrollView.contentSize.width, w * effectivelyScale,
508 XCTAssertEqualWithAccuracy(scrollView.contentSize.height, h * effectivelyScale,
511 XCTAssertEqual(scrollView.contentOffset.x, 0);
512 XCTAssertEqual(scrollView.contentOffset.y, 0);
515 - (void)testFlutterScrollableSemanticsObjectIsNotHittestable {
516 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
518 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
520 flutter::SemanticsNode node;
521 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
522 node.actions = flutter::kHorizontalScrollSemanticsActions;
523 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
524 node.scrollExtentMax = 100.0;
525 node.scrollPosition = 0.0;
532 XCTAssertEqual([scrollView hitTest:CGPointMake(10, 10) withEvent:nil], nil);
535 - (void)testFlutterScrollableSemanticsObjectIsHiddenWhenVoiceOverIsRunning {
538 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
539 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
541 flutter::SemanticsNode node;
542 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
543 node.actions = flutter::kHorizontalScrollSemanticsActions;
544 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
545 node.scrollExtentMax = 100.0;
546 node.scrollPosition = 0.0;
553 XCTAssertTrue(scrollView.isAccessibilityElement);
555 XCTAssertFalse(scrollView.isAccessibilityElement);
558 - (void)testFlutterSemanticsObjectHasIdentifier {
561 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
562 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
564 flutter::SemanticsNode node;
565 node.identifier =
"identifier";
569 XCTAssertTrue([
object.accessibilityIdentifier isEqualToString:
@"identifier"]);
572 - (void)testFlutterScrollableSemanticsObjectWithLabelValueHintIsNotHiddenWhenVoiceOverIsRunning {
575 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
576 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
578 flutter::SemanticsNode node;
579 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
580 node.actions = flutter::kHorizontalScrollSemanticsActions;
581 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
582 node.label =
"label";
583 node.value =
"value";
585 node.scrollExtentMax = 100.0;
586 node.scrollPosition = 0.0;
593 XCTAssertTrue(scrollView.isAccessibilityElement);
595 [scrollView.accessibilityLabel isEqualToString:NSLocalizedString(
@"label",
@"test")]);
597 [scrollView.accessibilityValue isEqualToString:NSLocalizedString(
@"value",
@"test")]);
598 XCTAssertTrue([scrollView.accessibilityHint isEqualToString:NSLocalizedString(
@"hint",
@"test")]);
601 - (void)testFlutterSemanticsObjectMergeTooltipToLabel {
604 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
605 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
607 flutter::SemanticsNode node;
608 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
609 node.label =
"label";
610 node.tooltip =
"tooltip";
613 XCTAssertTrue(
object.isAccessibilityElement);
614 XCTAssertTrue([
object.accessibilityLabel isEqualToString:
@"label\ntooltip"]);
617 - (void)testFlutterSemanticsObjectAttributedStringsDoNotCrashWhenEmpty {
620 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
621 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
623 flutter::SemanticsNode node;
624 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
627 XCTAssertTrue(
object.accessibilityAttributedLabel == nil);
630 - (void)testFlutterScrollableSemanticsObjectReturnsParentContainerIfNoChildren {
633 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
634 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
636 flutter::SemanticsNode parent;
638 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
639 parent.label =
"label";
640 parent.value =
"value";
641 parent.hint =
"hint";
643 flutter::SemanticsNode node;
645 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
646 node.actions = flutter::kHorizontalScrollSemanticsActions;
647 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
648 node.label =
"label";
649 node.value =
"value";
651 node.scrollExtentMax = 100.0;
652 node.scrollPosition = 0.0;
653 parent.childrenInTraversalOrder.push_back(1);
664 parentObject.
children = @[ scrollable ];
667 XCTAssertTrue(scrollView.isAccessibilityElement);
673 - (void)testFlutterScrollableSemanticsObjectNoScrollBarOrContentInsets {
674 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
676 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
678 flutter::SemanticsNode node;
679 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
680 node.actions = flutter::kHorizontalScrollSemanticsActions;
681 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
682 node.scrollExtentMax = 100.0;
683 node.scrollPosition = 0.0;
691 XCTAssertFalse(scrollView.showsHorizontalScrollIndicator);
692 XCTAssertFalse(scrollView.showsVerticalScrollIndicator);
693 XCTAssertEqual(scrollView.contentInsetAdjustmentBehavior,
694 UIScrollViewContentInsetAdjustmentNever);
695 XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, UIEdgeInsetsZero));
698 - (void)testSemanticsObjectBuildsAttributedString {
699 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
701 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
702 flutter::SemanticsNode node;
703 node.label =
"label";
704 std::shared_ptr<flutter::SpellOutStringAttribute> attribute =
705 std::make_shared<flutter::SpellOutStringAttribute>();
706 attribute->start = 1;
708 attribute->type = flutter::StringAttributeType::kSpellOut;
709 node.labelAttributes.push_back(attribute);
710 node.value =
"value";
711 attribute = std::make_shared<flutter::SpellOutStringAttribute>();
712 attribute->start = 2;
714 attribute->type = flutter::StringAttributeType::kSpellOut;
715 node.valueAttributes.push_back(attribute);
717 std::shared_ptr<flutter::LocaleStringAttribute> local_attribute =
718 std::make_shared<flutter::LocaleStringAttribute>();
719 local_attribute->start = 3;
720 local_attribute->end = 4;
721 local_attribute->type = flutter::StringAttributeType::kLocale;
722 local_attribute->locale =
"en-MX";
723 node.hintAttributes.push_back(local_attribute);
726 NSMutableAttributedString* expectedAttributedLabel =
727 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"label", @"test")];
728 NSDictionary* attributeDict = @{
729 UIAccessibilitySpeechAttributeSpellOut : @YES,
731 [expectedAttributedLabel setAttributes:attributeDict range:NSMakeRange(1, 1)];
733 [
object.accessibilityAttributedLabel isEqualToAttributedString:expectedAttributedLabel]);
735 NSMutableAttributedString* expectedAttributedValue =
736 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"value", @"test")];
738 UIAccessibilitySpeechAttributeSpellOut : @YES,
740 [expectedAttributedValue setAttributes:attributeDict range:NSMakeRange(2, 1)];
742 [
object.accessibilityAttributedValue isEqualToAttributedString:expectedAttributedValue]);
744 NSMutableAttributedString* expectedAttributedHint =
745 [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"hint", @"test")];
747 UIAccessibilitySpeechAttributeLanguage :
@"en-MX",
749 [expectedAttributedHint setAttributes:attributeDict range:NSMakeRange(3, 1)];
751 [
object.accessibilityAttributedHint isEqualToAttributedString:expectedAttributedHint]);
754 - (void)testShouldTriggerAnnouncement {
755 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
757 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
761 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
764 flutter::SemanticsNode node;
765 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsLiveRegion);
767 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
771 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:nil]);
774 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&node]);
777 flutter::SemanticsNode updatedNode;
778 updatedNode.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsLiveRegion);
779 updatedNode.label =
"bar";
780 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&updatedNode]);
783 updatedNode.flags = 0;
784 XCTAssertFalse([
object nodeShouldTriggerAnnouncement:&updatedNode]);
787 updatedNode.label =
"foo";
789 XCTAssertTrue([
object nodeShouldTriggerAnnouncement:&node]);
792 - (void)testShouldDispatchShowOnScreenActionForHeader {
793 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
795 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
799 flutter::SemanticsNode node;
800 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsHeader);
806 [object accessibilityElementDidBecomeFocused];
808 XCTAssertTrue(bridge->observations.size() == 1);
809 XCTAssertTrue(bridge->observations[0].id == 1);
810 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
813 - (void)testShouldDispatchShowOnScreenActionForHidden {
814 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
816 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
820 flutter::SemanticsNode node;
821 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsHidden);
827 [object accessibilityElementDidBecomeFocused];
829 XCTAssertTrue(bridge->observations.size() == 1);
830 XCTAssertTrue(bridge->observations[0].id == 1);
831 XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
834 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitch {
835 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
837 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
842 flutter::SemanticsNode node;
843 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasToggledState) |
844 static_cast<int32_t
>(flutter::SemanticsFlags::kIsToggled) |
845 static_cast<int32_t
>(flutter::SemanticsFlags::kIsEnabled);
849 UISwitch* nativeSwitch = [[UISwitch alloc] init];
850 nativeSwitch.on = YES;
852 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
853 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
856 flutter::SemanticsNode update;
857 update.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasToggledState) |
858 static_cast<int32_t
>(flutter::SemanticsFlags::kIsEnabled);
859 update.label =
"foo";
862 nativeSwitch.on = NO;
864 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
865 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
868 - (void)testFlutterSemanticsObjectOfRadioButton {
869 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
871 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
875 flutter::SemanticsNode node;
876 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsInMutuallyExclusiveGroup) |
877 static_cast<int32_t
>(flutter::SemanticsFlags::kHasCheckedState) |
878 static_cast<int32_t
>(flutter::SemanticsFlags::kHasEnabledState) |
879 static_cast<int32_t
>(flutter::SemanticsFlags::kIsEnabled);
882 XCTAssertTrue((
object.accessibilityTraits & UIAccessibilityTraitButton) > 0);
883 XCTAssertNil(
object.accessibilityValue);
886 - (void)testFlutterSwitchSemanticsObjectMatchesUISwitchDisabled {
887 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
889 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
894 flutter::SemanticsNode node;
895 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasToggledState) |
896 static_cast<int32_t
>(flutter::SemanticsFlags::kIsToggled);
900 UISwitch* nativeSwitch = [[UISwitch alloc] init];
901 nativeSwitch.on = YES;
902 nativeSwitch.enabled = NO;
904 XCTAssertEqual(
object.accessibilityTraits, nativeSwitch.accessibilityTraits);
905 XCTAssertEqualObjects(
object.accessibilityValue, nativeSwitch.accessibilityValue);
908 - (void)testSemanticsObjectDeallocated {
909 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
911 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
919 XCTAssertNil(weakObject);
922 - (void)testFlutterSemanticsObjectReturnsNilContainerWhenBridgeIsNotAlive {
927 flutter::SemanticsNode parent;
929 parent.rect = SkRect::MakeXYWH(0, 0, 100, 200);
930 parent.label =
"label";
931 parent.value =
"value";
932 parent.hint =
"hint";
934 flutter::SemanticsNode node;
936 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
937 node.actions = flutter::kHorizontalScrollSemanticsActions;
938 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
939 node.label =
"label";
940 node.value =
"value";
942 node.scrollExtentMax = 100.0;
943 node.scrollPosition = 0.0;
944 parent.childrenInTraversalOrder.push_back(1);
946 flutter::SemanticsNode node2;
948 node2.rect = SkRect::MakeXYWH(0, 0, 100, 200);
949 node2.label =
"label";
950 node2.value =
"value";
952 node2.scrollExtentMax = 100.0;
953 node2.scrollPosition = 0.0;
954 parent.childrenInTraversalOrder.push_back(2);
960 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
961 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
973 parentObject.
children = @[ scrollable, object2 ];
988 XCTAssertNil(scrollable.accessibilityContainer);
989 XCTAssertNil(object2.accessibilityContainer);
992 - (void)testAccessibilityHitTestSearchCanReturnPlatformView {
993 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
995 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1004 platformView:platformView];
1008 object1.
children = @[ platformViewSemanticsContainer, object3 ];
1011 flutter::SemanticsNode node0;
1013 node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1017 flutter::SemanticsNode node1;
1019 node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1023 flutter::SemanticsNode node2;
1025 node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
1029 flutter::SemanticsNode node3;
1031 node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1035 CGPoint point = CGPointMake(10, 10);
1038 XCTAssertEqual(hitTestResult, platformView);
1041 - (void)testFlutterPlatformViewSemanticsContainer {
1042 fml::WeakPtrFactory<flutter::testing::MockAccessibilityBridge> factory(
1044 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1049 weakPlatformView = platformView;
1055 platformView:platformView];
1056 weakContainer = container;
1058 XCTAssertNotNil(weakPlatformView);
1059 XCTAssertNotNil(weakContainer);
1063 XCTAssertNotNil(weakPlatformView);
1064 XCTAssertNotNil(weakContainer);
1068 XCTAssertNil(weakPlatformView);
1069 XCTAssertNil(weakContainer);
1072 - (void)testTextInputSemanticsObject {
1073 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1075 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1077 flutter::SemanticsNode node;
1079 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsTextField) |
1080 static_cast<int32_t
>(flutter::SemanticsFlags::kIsReadOnly);
1084 XCTAssertEqual([
object accessibilityTraits], UIAccessibilityTraitNone);
1087 - (void)testTextInputSemanticsObject_canPerformAction {
1088 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1090 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1092 flutter::SemanticsNode node;
1094 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsTextField) |
1095 static_cast<int32_t
>(flutter::SemanticsFlags::kIsReadOnly);
1100 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1101 id partialSemanticsObject = OCMPartialMock(
object);
1102 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1104 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1106 XCTAssertTrue([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1108 OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY])
1110 XCTAssertFalse([partialSemanticsObject canPerformAction:
@selector(copy:) withSender:nil]);
1113 - (void)testTextInputSemanticsObject_editActions {
1114 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1116 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1118 flutter::SemanticsNode node;
1120 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsTextField) |
1121 static_cast<int32_t
>(flutter::SemanticsFlags::kIsReadOnly);
1126 id textInputSurrogate = OCMClassMock([UIResponder
class]);
1127 id partialSemanticsObject = OCMPartialMock(
object);
1128 OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate);
1130 XCTestExpectation* copyExpectation =
1131 [
self expectationWithDescription:@"Surrogate's copy method is called."];
1132 XCTestExpectation* cutExpectation =
1133 [
self expectationWithDescription:@"Surrogate's cut method is called."];
1134 XCTestExpectation* pasteExpectation =
1135 [
self expectationWithDescription:@"Surrogate's paste method is called."];
1136 XCTestExpectation* selectAllExpectation =
1137 [
self expectationWithDescription:@"Surrogate's selectAll method is called."];
1138 XCTestExpectation* deleteExpectation =
1139 [
self expectationWithDescription:@"Surrogate's delete method is called."];
1141 OCMStub([textInputSurrogate copy:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1142 [copyExpectation fulfill];
1144 OCMStub([textInputSurrogate cut:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1145 [cutExpectation fulfill];
1147 OCMStub([textInputSurrogate paste:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1148 [pasteExpectation fulfill];
1150 OCMStub([textInputSurrogate selectAll:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1151 [selectAllExpectation fulfill];
1153 OCMStub([textInputSurrogate
delete:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
1154 [deleteExpectation fulfill];
1157 [partialSemanticsObject copy:nil];
1158 [partialSemanticsObject cut:nil];
1159 [partialSemanticsObject paste:nil];
1160 [partialSemanticsObject selectAll:nil];
1161 [partialSemanticsObject delete:nil];
1163 [
self waitForExpectationsWithTimeout:1 handler:nil];
1166 - (void)testSliderSemanticsObject {
1167 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1169 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1171 flutter::SemanticsNode node;
1172 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsSlider);
1176 XCTAssertEqual([
object accessibilityActivate], YES);
1179 - (void)testUIFocusItemConformance {
1180 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1182 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1188 XCTAssertTrue([parent.parentFocusEnvironment isKindOfClass:[UIView
class]]);
1189 XCTAssertEqual(child.parentFocusEnvironment, child.
parent);
1192 flutter::SemanticsNode childNode;
1193 childNode.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kIsHidden);
1194 childNode.actions =
static_cast<int32_t
>(flutter::SemanticsAction::kTap);
1196 XCTAssertFalse(child.canBecomeFocused);
1197 childNode.flags = 0;
1199 XCTAssertTrue(child.canBecomeFocused);
1200 childNode.actions = 0;
1202 XCTAssertFalse(child.canBecomeFocused);
1204 CGFloat scale = ((bridge->view().window.screen ?: UIScreen.mainScreen)).scale;
1206 childNode.rect = SkRect::MakeXYWH(0, 0, 100 * scale, 100 * scale);
1208 flutter::SemanticsNode parentNode;
1209 parentNode.rect = SkRect::MakeXYWH(0, 0, 200, 200);
1212 XCTAssertTrue(CGRectEqualToRect(child.frame, CGRectMake(0, 0, 100, 100)));
1215 - (void)testUIFocusItemContainerConformance {
1216 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1218 fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1225 NSArray<id<UIFocusItem>>* itemsInRect = [parent focusItemsInRect:CGRectMake(0, 0, 100, 100)];
1226 XCTAssertEqual(itemsInRect.count, (
unsigned long)2);
1227 XCTAssertTrue([itemsInRect containsObject:child1]);
1228 XCTAssertTrue([itemsInRect containsObject:child2]);
1231 - (void)testUIFocusItemScrollableContainerConformance {
1232 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1234 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1239 CGPoint p = CGPointMake(123.0, 456.0);
1240 [scrollable.scrollView scrollViewWillEndDragging:scrollable.scrollView
1241 withVelocity:CGPointZero
1242 targetContentOffset:&p];
1244 [scrollable.scrollView scrollViewDidEndDecelerating:scrollable.scrollView];
1245 XCTAssertEqual(bridge->observations.size(), (
size_t)1);
1246 XCTAssertEqual(bridge->observations[0].id, 5);
1247 XCTAssertEqual(bridge->observations[0].action, flutter::SemanticsAction::kScrollToOffset);
1249 std::vector<uint8_t> args = bridge->observations[0].args;
1250 XCTAssertEqual(args.size(), 3 *
sizeof(CGFloat));
1252 NSData* encoded = [NSData dataWithBytes:args.data() length:args.size()];
1254 CGPoint point = CGPointZero;
1255 memcpy(&point, decoded.
data.bytes, decoded.
data.length);
1256 XCTAssertTrue(CGPointEqualToPoint(point, p));
1259 - (void)testUIFocusItemScrollableContainerNoFeedbackLoops {
1260 fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1262 fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
1267 const CGPoint p = CGPointMake(0.0, 456.0);
1269 bridge->observations.clear();
1271 const SkScalar scrollPosition = p.y + 0.0000000000000001;
1272 flutter::SemanticsNode node;
1273 node.flags =
static_cast<int32_t
>(flutter::SemanticsFlags::kHasImplicitScrolling);
1274 node.actions = flutter::kVerticalScrollSemanticsActions;
1275 node.rect = SkRect::MakeXYWH(0, 0, 100, 200);
1276 node.scrollExtentMax = 10000;
1277 node.scrollPosition = scrollPosition;
1278 node.transform = {1.0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 1.0, 0, 0, scrollPosition, 0, 1.0};
1282 XCTAssertEqual(bridge->observations.size(), (
size_t)0);