1use crate::*;
102
103pub(crate) mod debug;
104
105use crate::{App, Bounds, FocusId, Pixels, SharedString, Window};
106use accesskit::{Action, NodeId, TreeUpdate};
107use collections::{FxHashMap, FxHashSet};
108use smallvec::SmallVec;
109use std::hash::{Hash, Hasher};
110use std::sync::{
111 Arc,
112 atomic::{AtomicBool, Ordering},
113};
114
115pub(crate) const ROOT_NODE_ID: NodeId = NodeId(0);
117
118pub(crate) type A11yActionListener =
120 Box<dyn FnMut(Option<&accesskit::ActionData>, &mut Window, &mut App) + 'static>;
121
122pub(crate) struct A11y {
127 force_disabled: bool,
131 active_flag: Arc<AtomicBool>,
136 active_this_frame: bool,
148 pub(crate) nodes: A11yNodeBuilder,
149 pub(crate) focus_ids: FxHashMap<NodeId, FocusId>,
150 pub(crate) node_bounds: FxHashMap<NodeId, Bounds<Pixels>>,
151 pub(crate) action_listeners: FxHashMap<NodeId, Vec<(Action, A11yActionListener)>>,
152 window_title: Option<SharedString>,
155 last_focus_without_node: Option<FocusId>,
158 debug: debug::A11yDebug,
161 #[cfg(debug_assertions)]
163 pub(crate) view_type_names: FxHashMap<EntityId, &'static str>,
164}
165
166impl A11y {
167 pub(crate) fn new(
168 active_flag: Arc<AtomicBool>,
169 force_disabled: bool,
170 window_title: Option<SharedString>,
171 ) -> Self {
172 Self {
173 force_disabled,
174 active_flag,
175 active_this_frame: false,
176 nodes: A11yNodeBuilder::new(),
177 focus_ids: FxHashMap::default(),
178 node_bounds: FxHashMap::default(),
179 action_listeners: FxHashMap::default(),
180 window_title,
181 last_focus_without_node: None,
182 debug: debug::A11yDebug::default(),
183 #[cfg(debug_assertions)]
184 view_type_names: FxHashMap::default(),
185 }
186 }
187
188 pub(crate) fn note_focus_without_node(&mut self, focus_id: FocusId, reason: &str) {
194 if self.last_focus_without_node != Some(focus_id) {
195 self.last_focus_without_node = Some(focus_id);
196 log::info!(
197 "a11y: focused element ({focus_id:?}) has no accessibility node \
198 ({reason}); assistive technology will announce the whole window \
199 instead. Give it both an `.id(...)` and a `.role(...)` to expose it."
200 );
201 }
202 }
203
204 pub(crate) fn set_window_title(&mut self, title: impl Into<SharedString>) {
205 self.window_title = Some(title.into());
206 }
207
208 pub(crate) fn sync_active_flag(&mut self) {
213 self.active_this_frame = self.is_enabled() && self.active_flag.load(Ordering::SeqCst);
214 }
215
216 pub(crate) fn is_enabled(&self) -> bool {
217 !self.force_disabled
218 }
219
220 pub(crate) fn is_active(&self) -> bool {
221 self.active_this_frame
222 }
223
224 pub(crate) fn set_focusable(&mut self, node_id: NodeId, focus_id: FocusId) {
225 self.focus_ids.insert(node_id, focus_id);
226 }
227
228 pub(crate) fn set_focus(&mut self, node_id: NodeId) {
233 if !self.focus_ids.contains_key(&node_id) {
235 if cfg!(debug_assertions) {
236 panic!("set_focus called for a node that was not registered with set_focusable");
237 } else {
238 log::warn!(
239 "a11y: set_focus called for a node that was not registered with \
240 set_focusable ({node_id:?})"
241 );
242 }
243 }
244 if self.nodes.has_node(node_id) {
245 self.last_focus_without_node = None;
248 self.nodes.set_focus(node_id);
249 } else {
250 if let Some(focus_id) = self.focus_ids.get(&node_id).copied() {
253 self.note_focus_without_node(focus_id, "it has an id but no role");
254 }
255 }
256 }
257
258 pub(crate) fn set_active_descendant(&mut self, node_id: NodeId) {
259 if self.nodes.node_is_focused(node_id) {
262 if cfg!(debug_assertions) {
263 panic!("set_active_descendant called on the focused node");
264 } else {
265 log::warn!("a11y: set_active_descendant called on the focused node ({node_id:?})");
266 }
267 return;
268 }
269 if self.nodes.has_node(node_id) && self.nodes.focus_is_ancestor_of_current() {
270 self.nodes.set_active_descendant(node_id);
271 }
272 }
273
274 pub(crate) fn begin_frame(&mut self) {
276 self.focus_ids.clear();
277 self.node_bounds.clear();
278 self.action_listeners.clear();
279 self.nodes.begin_frame(self.window_title.as_ref());
280 }
281
282 pub(crate) fn end_frame(&mut self, frame: debug::FrameDebugInfo) -> TreeUpdate {
284 let update = self.nodes.finalize();
285 self.debug.capture(
286 &update,
287 self.nodes.focus,
288 self.nodes.active_descendant,
289 self.window_title.as_ref(),
290 frame,
291 );
292 #[cfg(debug_assertions)]
293 self.debug.capture_node_info(&self.nodes.node_info);
294 update
295 }
296
297 pub(crate) fn debug_tree_json(&self) -> Option<String> {
298 self.debug.to_json()
299 }
300}
301
302pub struct A11ySubtreeBuilder<'a> {
305 parent_id: NodeId,
306 nodes: &'a mut A11yNodeBuilder,
307 #[cfg(debug_assertions)]
310 creator: debug::NodeCreator,
311}
312
313impl<'a> A11ySubtreeBuilder<'a> {
314 pub(crate) fn new(parent_id: NodeId, nodes: &'a mut A11yNodeBuilder) -> Self {
315 Self {
316 parent_id,
317 nodes,
318 #[cfg(debug_assertions)]
319 creator: debug::NodeCreator::default(),
320 }
321 }
322
323 #[cfg(debug_assertions)]
324 pub(crate) fn with_creator(mut self, creator: debug::NodeCreator) -> Self {
325 self.creator = creator;
326 self
327 }
328
329 pub fn synthetic_node_id(&self, key: impl Hash) -> NodeId {
336 let mut hasher = std::hash::DefaultHasher::default();
337 self.parent_id.0.hash(&mut hasher);
338 key.hash(&mut hasher);
339 NodeId(hasher.finish())
340 }
341
342 pub fn push_child(&mut self, id: NodeId, node: accesskit::Node) -> bool {
347 let pushed = self.nodes.push_leaf(id, node);
348 #[cfg(debug_assertions)]
349 if pushed {
350 self.nodes.record_node_info(
351 id,
352 debug::NodeDebugInfo {
353 synthetic: true,
354 view: self.creator.view,
355 element_id: self.creator.element_id.clone(),
356 source_location: self.creator.source_location,
357 },
358 );
359 }
360 pushed
361 }
362
363 pub fn parent_node(&mut self) -> &mut accesskit::Node {
365 self.nodes
366 .current_node_mut()
367 .expect("A11ySubtreeBuilder exists only while its element's node is on the stack")
368 }
369}
370
371pub(crate) struct A11yNodeBuilder {
372 ids_stack: SmallVec<[NodeId; 16]>,
373 nodes_stack: SmallVec<[accesskit::Node; 16]>,
374 all_nodes: Vec<(NodeId, accesskit::Node)>,
377 seen_ids: FxHashSet<NodeId>,
378 focus: Option<NodeId>,
381 active_descendant: Option<NodeId>,
386 adoptions: Vec<(NodeId, NodeId)>,
389 #[cfg(debug_assertions)]
390 node_info: FxHashMap<NodeId, debug::NodeDebugInfo>,
391}
392
393impl A11yNodeBuilder {
394 fn new() -> Self {
395 Self {
396 ids_stack: SmallVec::new(),
397 nodes_stack: SmallVec::new(),
398 all_nodes: Vec::new(),
399 seen_ids: FxHashSet::default(),
400 focus: None,
401 active_descendant: None,
402 adoptions: Vec::new(),
403 #[cfg(debug_assertions)]
404 node_info: FxHashMap::default(),
405 }
406 }
407
408 #[cfg(debug_assertions)]
410 pub(crate) fn record_node_info(&mut self, id: NodeId, info: debug::NodeDebugInfo) {
411 self.node_info.insert(id, info);
412 }
413
414 #[must_use]
415 fn can_push(&mut self, id: NodeId) -> bool {
416 debug_assert!(!self.ids_stack.is_empty(), "node pushed before push_root");
417
418 if !self.seen_ids.insert(id) {
419 debug_assert!(
420 false,
421 "Duplicate a11y node id: {id:?}. In a release build, this node would be silently discarded from the a11y tree."
422 );
423 return false;
424 }
425
426 true
427 }
428
429 pub(crate) fn push(&mut self, id: NodeId, node: accesskit::Node) -> bool {
434 if !self.can_push(id) {
435 return false;
436 }
437
438 if let Some(parent) = self.nodes_stack.last_mut() {
439 parent.push_child(id);
440 }
441 self.ids_stack.push(id);
442 self.nodes_stack.push(node);
443 true
444 }
445
446 pub(crate) fn push_leaf(&mut self, id: NodeId, node: accesskit::Node) -> bool {
452 if !self.can_push(id) {
453 return false;
454 }
455
456 if let Some(parent) = self.nodes_stack.last_mut() {
457 parent.push_child(id);
458 }
459 self.all_nodes.push((id, node));
460 true
461 }
462
463 pub(crate) fn current_node_mut(&mut self) -> Option<&mut accesskit::Node> {
464 self.nodes_stack.last_mut()
465 }
466
467 pub(crate) fn current_id(&self) -> NodeId {
470 self.ids_stack.last().copied().unwrap_or(ROOT_NODE_ID)
471 }
472
473 pub(crate) fn begin_adopted(&mut self, parent: NodeId) {
482 self.ids_stack.push(parent);
483 self.nodes_stack
484 .push(accesskit::Node::new(accesskit::Role::GenericContainer));
485 }
486
487 pub(crate) fn end_adopted(&mut self) {
489 if let (Some(parent), Some(stand_in)) = (self.ids_stack.pop(), self.nodes_stack.pop()) {
490 self.adoptions
491 .extend(stand_in.children().iter().map(|&child| (parent, child)));
492 }
493 }
494
495 fn link_adoptions(&mut self) {
499 if self.adoptions.is_empty() {
500 return;
501 }
502 let index: FxHashMap<NodeId, usize> = self
503 .all_nodes
504 .iter()
505 .enumerate()
506 .map(|(ix, (id, _))| (*id, ix))
507 .collect();
508 for (parent, child) in std::mem::take(&mut self.adoptions) {
509 let ix = index
510 .get(&parent)
511 .or_else(|| index.get(&ROOT_NODE_ID))
512 .copied();
513 if let Some(ix) = ix {
514 self.all_nodes[ix].1.push_child(child);
515 }
516 }
517 }
518
519 pub(crate) fn pop(&mut self) {
522 debug_assert!(self.ids_stack.len() > 1, "pop would remove the root node");
523
524 if let (Some(id), Some(node)) = (self.ids_stack.pop(), self.nodes_stack.pop()) {
525 self.all_nodes.push((id, node));
526 }
527 }
528
529 fn begin_frame(&mut self, window_title: Option<&SharedString>) {
531 self.all_nodes.clear();
532 self.ids_stack.clear();
533 self.nodes_stack.clear();
534 self.seen_ids.clear();
535 self.adoptions.clear();
536 #[cfg(debug_assertions)]
537 self.node_info.clear();
538 let mut root_node = accesskit::Node::new(accesskit::Role::Window);
539 if let Some(title) = window_title {
540 root_node.set_label(title.to_string());
541 }
542
543 self.ids_stack.push(ROOT_NODE_ID);
544 self.nodes_stack.push(root_node);
545 self.focus = None;
546 self.active_descendant = None;
547 }
548
549 pub(crate) fn has_node(&self, id: NodeId) -> bool {
551 id == ROOT_NODE_ID || self.seen_ids.contains(&id)
552 }
553
554 pub(crate) fn node_is_focused(&self, id: NodeId) -> bool {
556 self.focus == Some(id)
557 }
558
559 pub(crate) fn focus_is_ancestor_of_current(&self) -> bool {
560 let Some(focus) = self.focus else {
561 return false;
562 };
563
564 let ancestor_count = self.ids_stack.len().saturating_sub(1);
567 self.ids_stack[..ancestor_count].contains(&focus)
568 }
569
570 pub(crate) fn set_active_descendant(&mut self, id: NodeId) {
571 if self
572 .active_descendant
573 .is_some_and(|existing| existing != id)
574 {
575 if cfg!(debug_assertions) {
576 panic!("active descendant claimed by multiple nodes in one frame");
577 } else {
578 log::warn!(
579 "a11y: multiple nodes claimed the active descendant this frame; \
580 using last-wins ({id:?})"
581 );
582 }
583 }
584 self.active_descendant = Some(id);
585 }
586
587 pub(crate) fn set_focus(&mut self, id: NodeId) {
588 if self.focus.is_some() {
589 if cfg!(debug_assertions) {
590 panic!("set_focus called more than once in a single frame");
591 } else {
592 log::warn!(
593 "a11y: set_focus called more than once in a single frame; \
594 using last-wins ({id:?})"
595 );
596 }
597 }
598 self.focus = Some(id);
599 }
600
601 fn finalize(&mut self) -> TreeUpdate {
602 debug_assert_eq!(self.ids_stack.len(), 1);
604 debug_assert_eq!(self.ids_stack[0], ROOT_NODE_ID);
605
606 if self.ids_stack.len() != 1 {
607 log::error!(
608 "a11y: Stack imbalance at end of frame: expected 1 (root), got {}. \
609 Some elements may have pushed without popping.",
610 self.ids_stack.len()
611 );
612 }
613
614 while !self.ids_stack.is_empty() {
616 if let (Some(id), Some(node)) = (self.ids_stack.pop(), self.nodes_stack.pop()) {
617 self.all_nodes.push((id, node));
618 }
619 }
620 self.link_adoptions();
621
622 let focus = match self.active_descendant {
623 Some(id) if self.has_node(id) => id,
624 Some(id) => {
625 if cfg!(debug_assertions) {
626 panic!("active_descendant set to {id:?}, which is not in the tree");
627 } else {
628 log::warn!("active_descendant set to {id:?}, which is not in the tree");
629 self.focus.unwrap_or(ROOT_NODE_ID)
630 }
631 }
632
633 _ => self.focus.unwrap_or(ROOT_NODE_ID),
634 };
635
636 let nodes = std::mem::take(&mut self.all_nodes);
637 let update = TreeUpdate {
638 nodes,
639 tree: Some(accesskit::Tree::new(ROOT_NODE_ID)),
640 tree_id: accesskit::TreeId::ROOT,
641 focus,
642 };
643
644 Self::repair_tree_update(update)
645 }
646
647 fn repair_tree_update(mut update: TreeUpdate) -> TreeUpdate {
650 let node_ids: FxHashSet<NodeId> = update.nodes.iter().map(|(id, _)| *id).collect();
651
652 if !node_ids.contains(&update.focus) {
654 log::error!(
655 "a11y: Focused node {:?} is not in the tree ({} nodes). \
656 Falling back to root. This is a bug in the a11y tree builder.",
657 update.focus,
658 update.nodes.len()
659 );
660 update.focus = ROOT_NODE_ID;
661 }
662
663 for (id, node) in &mut update.nodes {
665 let has_invalid_child = node
666 .children()
667 .iter()
668 .any(|child_id| !node_ids.contains(child_id));
669 if has_invalid_child {
670 let children = node.children();
671 let invalid_count = children
672 .iter()
673 .filter(|child_id| !node_ids.contains(child_id))
674 .count();
675 log::error!(
676 "a11y: Node {:?} references {} children not present in the tree. \
677 Stripping invalid child references.",
678 id,
679 invalid_count
680 );
681 let valid: Vec<NodeId> = children
682 .iter()
683 .copied()
684 .filter(|child_id| node_ids.contains(child_id))
685 .collect();
686 node.set_children(valid);
687 }
688 }
689
690 update
691 }
692}
693
694#[cfg(test)]
695mod tests {
696 use super::{A11y, A11yNodeBuilder, ROOT_NODE_ID};
699 use crate::FocusId;
700 use accesskit::{NodeId, Role};
701 use std::sync::{Arc, atomic::AtomicBool};
702
703 fn test_node() -> accesskit::Node {
704 accesskit::Node::new(Role::GenericContainer)
705 }
706
707 fn new_builder() -> A11yNodeBuilder {
708 let mut builder = A11yNodeBuilder::new();
709 builder.begin_frame(None);
710 builder
711 }
712
713 fn new_a11y() -> A11y {
714 let mut a11y = A11y::new(Arc::new(AtomicBool::new(true)), false, None);
715 a11y.begin_frame();
716 a11y
717 }
718
719 #[test]
720 fn accessibility_enabled_is_independent_of_activation() {
721 for force_disabled in [false, true] {
722 for active in [false, true] {
723 let mut a11y = A11y::new(Arc::new(AtomicBool::new(active)), force_disabled, None);
724 a11y.sync_active_flag();
725
726 assert_eq!(a11y.is_enabled(), !force_disabled);
727 assert_eq!(a11y.is_active(), !force_disabled && active);
728 }
729 }
730 }
731
732 #[test]
733 fn active_descendant_honored_when_container_focused() {
734 let mut builder = new_builder();
735 let container = NodeId(1);
736 let item = NodeId(2);
737
738 assert!(builder.push(container, test_node()));
739 builder.set_focus(container);
740 assert!(builder.push(item, test_node()));
741
742 assert!(builder.focus_is_ancestor_of_current());
745 builder.set_active_descendant(item);
746
747 builder.pop(); builder.pop(); let update = builder.finalize();
750 assert_eq!(update.focus, item);
751 }
752
753 #[test]
754 fn active_descendant_honored_for_deep_descendant() {
755 let mut builder = new_builder();
756 let container = NodeId(1);
757 let group = NodeId(2);
758 let item = NodeId(3);
759
760 assert!(builder.push(container, test_node()));
761 builder.set_focus(container);
762 assert!(builder.push(group, test_node()));
763 assert!(builder.push(item, test_node()));
764
765 assert!(builder.focus_is_ancestor_of_current());
768 builder.set_active_descendant(item);
769
770 builder.pop(); builder.pop(); builder.pop(); let update = builder.finalize();
774 assert_eq!(update.focus, item);
775 }
776
777 #[test]
778 fn active_descendant_ignored_when_focus_in_other_subtree() {
779 let mut builder = new_builder();
780 let focused_container = NodeId(1);
781 let focused_leaf = NodeId(2);
782 let other_container = NodeId(3);
783 let other_item = NodeId(4);
784
785 assert!(builder.push(focused_container, test_node()));
787 assert!(builder.push(focused_leaf, test_node()));
788 builder.set_focus(focused_leaf);
789 builder.pop(); builder.pop(); assert!(builder.push(other_container, test_node()));
795 assert!(builder.push(other_item, test_node()));
796 assert!(!builder.focus_is_ancestor_of_current());
797 builder.pop(); builder.pop(); let update = builder.finalize();
801 assert_eq!(update.focus, focused_leaf);
802 }
803
804 #[test]
805 fn active_descendant_ignored_when_nothing_focused() {
806 let mut builder = new_builder();
807 let container = NodeId(1);
808 let item = NodeId(2);
809
810 assert!(builder.push(container, test_node()));
811 assert!(builder.push(item, test_node()));
812
813 assert!(!builder.focus_is_ancestor_of_current());
816 builder.pop();
817 builder.pop();
818
819 let update = builder.finalize();
820 assert_eq!(update.focus, ROOT_NODE_ID);
821 }
822
823 #[test]
824 fn regular_focus_used_when_no_active_descendant() {
825 let mut builder = new_builder();
826 let focused = NodeId(1);
827
828 assert!(builder.push(focused, test_node()));
829 builder.set_focus(focused);
830 builder.pop();
831
832 let update = builder.finalize();
833 assert_eq!(update.focus, focused);
834 }
835
836 #[test]
837 fn focus_is_ancestor_excludes_self_and_non_ancestors() {
838 let mut builder = new_builder();
839 let container = NodeId(1);
840 let item = NodeId(2);
841
842 assert!(builder.push(container, test_node()));
843 builder.set_focus(container);
844
845 assert!(!builder.focus_is_ancestor_of_current());
848
849 assert!(builder.push(item, test_node()));
850 assert!(builder.focus_is_ancestor_of_current());
852
853 builder.pop();
854 builder.pop();
855 }
856
857 #[test]
860 #[cfg_attr(
861 debug_assertions,
862 should_panic(expected = "active descendant claimed by multiple nodes")
863 )]
864 fn multiple_active_descendant_claims_panic_in_debug() {
865 let mut builder = new_builder();
866 builder.set_active_descendant(NodeId(1));
867 builder.set_active_descendant(NodeId(2));
868 }
869
870 #[test]
873 #[cfg_attr(
874 debug_assertions,
875 should_panic(expected = "set_focus called more than once")
876 )]
877 fn setting_focus_twice_panics_in_debug() {
878 let mut builder = new_builder();
879 builder.set_focus(NodeId(1));
880 builder.set_focus(NodeId(2));
881 }
882
883 #[test]
886 #[cfg_attr(
887 debug_assertions,
888 should_panic(expected = "was not registered with set_focusable")
889 )]
890 fn set_focus_without_set_focusable() {
891 let mut a11y = new_a11y();
892 let node = NodeId(1);
893 assert!(a11y.nodes.push(node, test_node()));
894 a11y.set_focus(node);
896 }
897
898 #[test]
901 #[cfg_attr(debug_assertions, should_panic(expected = "on the focused node"))]
902 fn set_active_descendant_on_focused_node() {
903 let mut a11y = new_a11y();
904 let node = NodeId(1);
905 assert!(a11y.nodes.push(node, test_node()));
906 a11y.set_focusable(node, FocusId::default());
907 a11y.set_focus(node);
908 a11y.set_active_descendant(node);
909 }
910
911 #[test]
915 #[cfg_attr(
916 debug_assertions,
917 should_panic(expected = "active descendant claimed by multiple nodes")
918 )]
919 fn two_siblings_claiming_active_descendant() {
920 let mut a11y = new_a11y();
921 let container = NodeId(1);
922 let first = NodeId(2);
923 let second = NodeId(3);
924
925 assert!(a11y.nodes.push(container, test_node()));
926 a11y.set_focusable(container, FocusId::default());
927 a11y.set_focus(container);
928
929 assert!(a11y.nodes.push(first, test_node()));
930 a11y.set_active_descendant(first);
931 a11y.nodes.pop(); assert!(a11y.nodes.push(second, test_node()));
934 a11y.set_active_descendant(second);
935 a11y.nodes.pop(); a11y.nodes.pop(); }
939
940 #[test]
943 fn active_descendant_in_unfocused_subtree_keeps_real_focus() {
944 let mut a11y = new_a11y();
945 let a = NodeId(1);
946 let b = NodeId(2);
947 let c = NodeId(3);
948
949 assert!(a11y.nodes.push(a, test_node()));
950 a11y.set_focusable(a, FocusId::default());
951 a11y.set_focus(a);
952 a11y.nodes.pop(); assert!(a11y.nodes.push(b, test_node()));
955 assert!(a11y.nodes.push(c, test_node()));
956 a11y.set_active_descendant(c);
957 a11y.nodes.pop(); a11y.nodes.pop(); let update = a11y.end_frame(Default::default());
961 assert_eq!(update.focus, a);
962 }
963}
964
965#[cfg(test)]
968mod vn_adoption_tests {
969 use super::{A11yNodeBuilder, ROOT_NODE_ID};
970 use accesskit::{NodeId, Role};
971
972 fn node() -> accesskit::Node {
973 accesskit::Node::new(Role::GenericContainer)
974 }
975
976 fn children_of(update: &accesskit::TreeUpdate, id: NodeId) -> Vec<NodeId> {
977 update
978 .nodes
979 .iter()
980 .find(|(n, _)| *n == id)
981 .map(|(_, node)| node.children().to_vec())
982 .unwrap_or_default()
983 }
984
985 #[test]
986 fn a_deferred_node_is_a_child_of_the_node_it_was_deferred_from() {
987 let (dialog, title, close, icon) = (NodeId(1), NodeId(2), NodeId(3), NodeId(4));
988 let mut b = A11yNodeBuilder::new();
989 b.begin_frame(None);
990
991 assert!(b.push(dialog, node()));
994 assert!(b.push_leaf(title, node()));
995 let deferred_from = b.current_id();
996 b.pop();
997 assert_eq!(deferred_from, dialog);
998
999 b.begin_adopted(deferred_from);
1001 assert!(b.push(close, node()));
1002 assert!(b.push_leaf(icon, node()));
1003 b.pop();
1004 b.end_adopted();
1005
1006 let update = b.finalize();
1007 assert_eq!(children_of(&update, dialog), vec![title, close]);
1008 assert_eq!(children_of(&update, close), vec![icon]);
1009 assert_eq!(children_of(&update, ROOT_NODE_ID), vec![dialog], "not on the root");
1010 let dialogs = update.nodes.iter().filter(|(id, _)| *id == dialog).count();
1011 assert_eq!(dialogs, 1, "the stand-in is not a node of its own");
1012 }
1013}