|
59 | 59 | [engine shutDownEngine]; |
60 | 60 | } |
61 | 61 |
|
| 62 | +TEST(FlutterPlatformNodeDelegateMac, SelectableTextHasCorrectSemantics) { |
| 63 | + FlutterEngine* engine = CreateTestEngine(); |
| 64 | + engine.semanticsEnabled = YES; |
| 65 | + auto bridge = engine.accessibilityBridge.lock(); |
| 66 | + // Initialize ax node data. |
| 67 | + FlutterSemanticsNode root; |
| 68 | + root.id = 0; |
| 69 | + root.flags = |
| 70 | + static_cast<FlutterSemanticsFlag>(FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField | |
| 71 | + FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly); |
| 72 | + root.actions = static_cast<FlutterSemanticsAction>(0); |
| 73 | + root.text_selection_base = 1; |
| 74 | + root.text_selection_extent = 3; |
| 75 | + root.label = ""; |
| 76 | + root.hint = ""; |
| 77 | + // Selectable text store its text in value |
| 78 | + root.value = "selectable text"; |
| 79 | + root.increased_value = ""; |
| 80 | + root.decreased_value = ""; |
| 81 | + root.child_count = 0; |
| 82 | + root.custom_accessibility_actions_count = 0; |
| 83 | + bridge->AddFlutterSemanticsNodeUpdate(&root); |
| 84 | + |
| 85 | + bridge->CommitUpdates(); |
| 86 | + |
| 87 | + auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock(); |
| 88 | + // Verify the accessibility attribute matches. |
| 89 | + NSAccessibilityElement* native_accessibility = |
| 90 | + root_platform_node_delegate->GetNativeViewAccessible(); |
| 91 | + std::string value = [native_accessibility.accessibilityValue UTF8String]; |
| 92 | + EXPECT_EQ(value, "selectable text"); |
| 93 | + EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole); |
| 94 | + EXPECT_EQ([native_accessibility.accessibilityChildren count], 0u); |
| 95 | + NSRange selection = native_accessibility.accessibilitySelectedTextRange; |
| 96 | + EXPECT_EQ(selection.location, 1u); |
| 97 | + EXPECT_EQ(selection.length, 2u); |
| 98 | + std::string selected_text = [native_accessibility.accessibilitySelectedText UTF8String]; |
| 99 | + EXPECT_EQ(selected_text, "el"); |
| 100 | +} |
| 101 | + |
| 102 | +TEST(FlutterPlatformNodeDelegateMac, SelectableTextWithoutSelectionReturnZeroRange) { |
| 103 | + FlutterEngine* engine = CreateTestEngine(); |
| 104 | + engine.semanticsEnabled = YES; |
| 105 | + auto bridge = engine.accessibilityBridge.lock(); |
| 106 | + // Initialize ax node data. |
| 107 | + FlutterSemanticsNode root; |
| 108 | + root.id = 0; |
| 109 | + root.flags = |
| 110 | + static_cast<FlutterSemanticsFlag>(FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField | |
| 111 | + FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly); |
| 112 | + root.actions = static_cast<FlutterSemanticsAction>(0); |
| 113 | + root.text_selection_base = -1; |
| 114 | + root.text_selection_extent = -1; |
| 115 | + root.label = ""; |
| 116 | + root.hint = ""; |
| 117 | + // Selectable text store its text in value |
| 118 | + root.value = "selectable text"; |
| 119 | + root.increased_value = ""; |
| 120 | + root.decreased_value = ""; |
| 121 | + root.child_count = 0; |
| 122 | + root.custom_accessibility_actions_count = 0; |
| 123 | + bridge->AddFlutterSemanticsNodeUpdate(&root); |
| 124 | + |
| 125 | + bridge->CommitUpdates(); |
| 126 | + |
| 127 | + auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock(); |
| 128 | + // Verify the accessibility attribute matches. |
| 129 | + NSAccessibilityElement* native_accessibility = |
| 130 | + root_platform_node_delegate->GetNativeViewAccessible(); |
| 131 | + NSRange selection = native_accessibility.accessibilitySelectedTextRange; |
| 132 | + EXPECT_TRUE(selection.location == NSNotFound); |
| 133 | + EXPECT_EQ(selection.length, 0u); |
| 134 | +} |
| 135 | + |
62 | 136 | TEST(FlutterPlatformNodeDelegateMac, CanPerformAction) { |
63 | 137 | FlutterEngine* engine = CreateTestEngine(); |
64 | 138 | engine.semanticsEnabled = YES; |
|
0 commit comments