Cache document validation until the accessible tree changes

This commit is contained in:
Storm Dragon committed 2026-11-19 04:27:31 -05:00
1 parent 8cc293113e
commit eb9dddbc2b
7 files changed
+94 -10

No files matched your search

@@ -0,0 +1,51 @@
package review
import (
"context"
"testing"
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func TestDocumentViewRejectsChangesAfterCachedValidation(t *testing.T) {
invalidations := map[string]func(*atspi.AccessibleTree, atspi.ObjectID) int{
"text": (*atspi.AccessibleTree).InvalidateText,
"snapshot": (*atspi.AccessibleTree).InvalidateSnapshot,
"geometry": (*atspi.AccessibleTree).InvalidateGeometry,
"children": (*atspi.AccessibleTree).InvalidateChildren,
"marked": (*atspi.AccessibleTree).MarkChildrenChanged,
}
for name, invalidate := range invalidations {
t.Run(name, func(t *testing.T) {
tree, contentIDs := benchmarkDocumentTree(&testing.B{}, 40)
reference, err := tree.Reference(contentIDs[1])
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
for range 2 {
if _, err := tree.DocumentView(ctx, reference); err != nil {
t.Fatalf("initial view: %v", err)
}
}
target, err := tree.Reference(contentIDs[30])
if err != nil {
t.Fatal(err)
}
section, _, err := tree.Parent(target)
if err != nil {
t.Fatal(err)
}
targetID := contentIDs[30]
if name == "children" {
targetID = section.ID()
}
if invalidate(tree, targetID) == 0 {
t.Fatal("invalidation changed nothing")
}
if _, err := tree.DocumentView(ctx, reference); err == nil {
t.Fatal("view after invalidation was accepted")
}
})
}
}