access: the controls tests live in the integration binary

This commit is contained in:
aiongg
2026-11-19 06:38:55 +00:00
parent c6537b6d07
commit 4ec453ed5a
4 changed files with 47 additions and 39 deletions
+3 -39
View File
@@ -211,9 +211,9 @@ pub(crate) fn drop_dangling_relations(output: &mut FullOutput) {
prune_controls(update);
}
/// The step itself, for the tests: every `controls` id of `update` that names no node of `update` is
/// dropped. Other relations keep their ids: they are built from nodes this pass wrote.
fn prune_controls(update: &mut egui::accesskit::TreeUpdate) {
/// The step itself: every `controls` id of `update` that names no node of `update` is dropped. Other
/// relations keep their ids: they are built from nodes this pass wrote.
pub(crate) fn prune_controls(update: &mut egui::accesskit::TreeUpdate) {
let ids: std::collections::HashSet<egui::accesskit::NodeId> = update.nodes.iter().map(|(id, _)| *id).collect();
for (_, node) in update.nodes.iter_mut() {
if node.controls().iter().all(|id| ids.contains(id)) {
@@ -223,39 +223,3 @@ fn prune_controls(update: &mut egui::accesskit::TreeUpdate) {
node.set_controls(kept);
}
}
#[cfg(test)]
mod tests {
use super::*;
use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate};
fn update(controls: Vec<NodeId>, carried: Vec<NodeId>) -> TreeUpdate {
let mut node = Node::new(Role::Button);
node.set_controls(controls);
TreeUpdate {
nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(),
tree: None,
tree_id: TreeId::ROOT,
focus: NodeId(1),
}
}
/// A popup that reports itself open on a frame where its node is not emitted leaves its id in
/// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id
/// that has a node stays.
#[test]
fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() {
let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]);
prune_controls(&mut tree);
let kept: Vec<NodeId> = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default();
assert_eq!(kept, vec![NodeId(2)], "the id without a node is gone, the one with a node stays");
}
#[test]
fn controls_with_every_node_carried_are_left_alone() {
let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]);
prune_controls(&mut tree);
let kept: Vec<NodeId> = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default();
assert_eq!(kept, vec![NodeId(2)]);
}
}
+6
View File
@@ -10,6 +10,12 @@ pub fn tree_of(output: &mut crate::runtime::egui::fixture::FullOutput) -> Access
crate::runtime::egui::access::tree_of(output).unwrap_or_else(AccessTree::none)
}
/// Drops every `controls` id of `update` that names no node of `update`, as the runtime does to each
/// frame's AccessKit output.
pub fn prune_controls(update: &mut egui::accesskit::TreeUpdate) {
crate::runtime::egui::access::prune_controls(update);
}
/// Opens the label scope of `container` with `label`, as a field container's body step does; the container's
/// report step closes it.
pub fn begin_label_scope(ctx: &Context, container: Id, label: FieldLabel) {
@@ -0,0 +1,37 @@
//! Relations that name a node the update does not carry.
use craft_ui::testing::access::prune_controls;
use craft_ui::testing::trial;
use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate};
fn update(controls: Vec<NodeId>, carried: Vec<NodeId>) -> TreeUpdate {
let mut node = Node::new(Role::Button);
node.set_controls(controls);
TreeUpdate {
nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(),
tree: None,
tree_id: TreeId::ROOT,
focus: NodeId(1),
}
}
fn controls_of_first(tree: &TreeUpdate) -> Vec<NodeId> {
tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default()
}
/// A popup that reports itself open on a frame where its node is not emitted leaves its id in
/// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id
/// that has a node stays.
#[trial]
fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() {
let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]);
prune_controls(&mut tree);
assert_eq!(controls_of_first(&tree), vec![NodeId(2)], "the id without a node is gone, the one with a node stays");
}
#[trial]
fn controls_with_every_node_carried_are_left_alone() {
let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]);
prune_controls(&mut tree);
assert_eq!(controls_of_first(&tree), vec![NodeId(2)]);
}
@@ -1,6 +1,7 @@
//! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports.
mod bounds;
mod controls;
mod face_record;
mod face_state;
mod nodes;