@@ -155,6 +155,66 @@ TEST(AccessibilityBridgeTest, canFireChildrenChangedCorrectly) {
155
155
actual_event.end ());
156
156
}
157
157
158
+ TEST (AccessibilityBridgeTest, canUpdateDelegate) {
159
+ std::shared_ptr<AccessibilityBridge> bridge =
160
+ std::make_shared<AccessibilityBridge>(
161
+ std::make_unique<TestAccessibilityBridgeDelegate>());
162
+ FlutterSemanticsNode root;
163
+ root.id = 0 ;
164
+ root.flags = static_cast <FlutterSemanticsFlag>(0 );
165
+ root.actions = static_cast <FlutterSemanticsAction>(0 );
166
+ root.text_selection_base = -1 ;
167
+ root.text_selection_extent = -1 ;
168
+ root.label = " root" ;
169
+ root.hint = " " ;
170
+ root.value = " " ;
171
+ root.increased_value = " " ;
172
+ root.decreased_value = " " ;
173
+ root.child_count = 1 ;
174
+ int32_t children[] = {1 };
175
+ root.children_in_traversal_order = children;
176
+ root.custom_accessibility_actions_count = 0 ;
177
+ bridge->AddFlutterSemanticsNodeUpdate (&root);
178
+
179
+ FlutterSemanticsNode child1;
180
+ child1.id = 1 ;
181
+ child1.flags = static_cast <FlutterSemanticsFlag>(0 );
182
+ child1.actions = static_cast <FlutterSemanticsAction>(0 );
183
+ child1.text_selection_base = -1 ;
184
+ child1.text_selection_extent = -1 ;
185
+ child1.label = " child 1" ;
186
+ child1.hint = " " ;
187
+ child1.value = " " ;
188
+ child1.increased_value = " " ;
189
+ child1.decreased_value = " " ;
190
+ child1.child_count = 0 ;
191
+ child1.custom_accessibility_actions_count = 0 ;
192
+ bridge->AddFlutterSemanticsNodeUpdate (&child1);
193
+
194
+ bridge->CommitUpdates ();
195
+
196
+ auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID (0 );
197
+ auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID (1 );
198
+ EXPECT_FALSE (root_node.expired ());
199
+ EXPECT_FALSE (child1_node.expired ());
200
+ // Update Delegate
201
+ bridge->UpdateDelegate (std::make_unique<TestAccessibilityBridgeDelegate>());
202
+
203
+ // Old tree is destroyed.
204
+ EXPECT_TRUE (root_node.expired ());
205
+ EXPECT_TRUE (child1_node.expired ());
206
+
207
+ // New tree still has the data.
208
+ auto new_root_node = bridge->GetFlutterPlatformNodeDelegateFromID (0 ).lock ();
209
+ auto new_child1_node = bridge->GetFlutterPlatformNodeDelegateFromID (1 ).lock ();
210
+ EXPECT_EQ (new_root_node->GetChildCount (), 1 );
211
+ EXPECT_EQ (new_root_node->GetData ().child_ids [0 ], 1 );
212
+ EXPECT_EQ (new_root_node->GetName (), " root" );
213
+
214
+ EXPECT_EQ (new_child1_node->GetChildCount (), 0 );
215
+ EXPECT_EQ (new_child1_node->GetName (), " child 1" );
216
+ }
217
+
158
218
TEST (AccessibilityBridgeTest, canHandleSelectionChangeCorrectly) {
159
219
TestAccessibilityBridgeDelegate* delegate =
160
220
new TestAccessibilityBridgeDelegate ();
@@ -200,5 +260,34 @@ TEST(AccessibilityBridgeTest, canHandleSelectionChangeCorrectly) {
200
260
ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED);
201
261
}
202
262
263
+ TEST (AccessibilityBridgeTest, doesNotAssignEditableRootToSelectableText) {
264
+ std::shared_ptr<AccessibilityBridge> bridge =
265
+ std::make_shared<AccessibilityBridge>(
266
+ std::make_unique<TestAccessibilityBridgeDelegate>());
267
+ FlutterSemanticsNode root;
268
+ root.id = 0 ;
269
+ root.flags = static_cast <FlutterSemanticsFlag>(
270
+ FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
271
+ FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly );
272
+ root.actions = static_cast <FlutterSemanticsAction>(0 );
273
+ root.text_selection_base = -1 ;
274
+ root.text_selection_extent = -1 ;
275
+ root.label = " root" ;
276
+ root.hint = " " ;
277
+ root.value = " " ;
278
+ root.increased_value = " " ;
279
+ root.decreased_value = " " ;
280
+ root.child_count = 0 ;
281
+ root.custom_accessibility_actions_count = 0 ;
282
+ bridge->AddFlutterSemanticsNodeUpdate (&root);
283
+
284
+ bridge->CommitUpdates ();
285
+
286
+ auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID (0 ).lock ();
287
+
288
+ EXPECT_FALSE (root_node->GetData ().GetBoolAttribute (
289
+ ax::mojom::BoolAttribute::kEditableRoot ));
290
+ }
291
+
203
292
} // namespace testing
204
293
} // namespace flutter
0 commit comments