Fix Wayland internal UI lifecycle edge cases
This commit is contained in:
1 parent
fc25f7e7e8
commit
ac7f7acc43
12 files changed
+477
-90
No files matched your search
@@ -172,15 +172,16 @@ func (worker *Worker) listDocument(ctx context.Context, cursor *DocumentCursor,
|
||||
// its own name, else its text, else its children's labels in provider
|
||||
// order. Password text never contributes its text or descendants.
|
||||
func documentNodeLabel(snapshot atspi.Snapshot, childLabels []string) string {
|
||||
label := snapshot.Name
|
||||
label := strings.TrimSpace(snapshot.Name)
|
||||
if snapshot.Role != "password text" {
|
||||
if label == "" {
|
||||
label = snapshot.Text
|
||||
label = strings.TrimSpace(snapshot.Text)
|
||||
}
|
||||
if label == "" {
|
||||
var parts []string
|
||||
size := 0
|
||||
for _, part := range childLabels {
|
||||
part = strings.TrimSpace(part)
|
||||
if part != "" {
|
||||
parts = append(parts, part)
|
||||
size += len(part)
|
||||
@@ -192,6 +193,7 @@ func documentNodeLabel(snapshot atspi.Snapshot, childLabels []string) string {
|
||||
label = strings.Join(parts, " ")
|
||||
}
|
||||
}
|
||||
label = strings.TrimSpace(label)
|
||||
runes := []rune(label)
|
||||
if len(runes) > 225 {
|
||||
label = string(runes[:225])
|
||||
|
||||
@@ -113,53 +113,76 @@ func TestDocumentListDescendantLabelsExcludeHiddenAndPasswordText(t *testing.T)
|
||||
}
|
||||
|
||||
func TestDocumentClickableMoveNamesUnnamedSectionFromDescendants(t *testing.T) {
|
||||
node := func(path, role, text string, children ...string) atspi.TreeNode {
|
||||
snapshot := atspi.Snapshot{BusName: webID(path).BusName, Path: path, Role: role, Text: text}
|
||||
entry := atspi.TreeNode{Snapshot: snapshot}
|
||||
for _, child := range children {
|
||||
entry.Children = append(entry.Children, webID(child))
|
||||
}
|
||||
return entry
|
||||
}
|
||||
nodes := []atspi.TreeNode{
|
||||
node("/doc", "document web", "", "/start", "/clickable"),
|
||||
node("/start", "static", "Before"),
|
||||
node("/clickable", "section", "", "/text", "/hidden", "/password"),
|
||||
node("/text", "static", "Clickable text"),
|
||||
node("/hidden", "static", "Hidden content"),
|
||||
node("/password", "password text", "private fixture password"),
|
||||
}
|
||||
nodes[2].Snapshot.SupportsClick = true
|
||||
nodes[4].Geometry = atspi.Geometry{VisibilityKnown: true}
|
||||
tree, err := atspi.NewAccessibleTree(webID("/doc"), nodes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cursor, err := NewDocumentCursor(tree)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
if _, err := cursor.SyncFocus(ctx, webID("/start")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
move, err := cursor.Move(ctx, DocumentClickable, 0, false)
|
||||
if err != nil || !move.Moved || move.Position.Object.ID() != webID("/clickable") {
|
||||
t.Fatalf("clickable move: %+v %v", move, err)
|
||||
}
|
||||
if move.Position.Snapshot.Name != "Clickable text" {
|
||||
t.Fatalf("landed snapshot name = %q, want descendant label", move.Position.Snapshot.Name)
|
||||
}
|
||||
ref, err := tree.Reference(webID("/clickable"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
captured, err := tree.Resolve(ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if captured.Name != "" {
|
||||
t.Fatalf("captured snapshot mutated: name = %q", captured.Name)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
rootName string
|
||||
rootText string
|
||||
editable bool
|
||||
wantName string
|
||||
}{
|
||||
{name: "descendant label", wantName: "Clickable text"},
|
||||
{name: "whitespace name and text", rootName: " \t", rootText: " ", wantName: "Clickable text"},
|
||||
{name: "editable clickable", editable: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
node := func(path, role, text string, children ...string) atspi.TreeNode {
|
||||
snapshot := atspi.Snapshot{BusName: webID(path).BusName, Path: path, Role: role, Text: text}
|
||||
entry := atspi.TreeNode{Snapshot: snapshot}
|
||||
for _, child := range children {
|
||||
entry.Children = append(entry.Children, webID(child))
|
||||
}
|
||||
return entry
|
||||
}
|
||||
nodes := []atspi.TreeNode{
|
||||
node("/doc", "document web", "", "/start", "/clickable"),
|
||||
node("/start", "static", "Before"),
|
||||
node("/clickable", "section", tc.rootText, "/text", "/hidden", "/password"),
|
||||
node("/text", "static", "Clickable text"),
|
||||
node("/hidden", "static", "Hidden content"),
|
||||
node("/password", "password text", "private fixture password"),
|
||||
}
|
||||
nodes[2].Snapshot.Name = tc.rootName
|
||||
nodes[2].Snapshot.SupportsClick = true
|
||||
nodes[2].Snapshot.Editable = tc.editable
|
||||
nodes[4].Geometry = atspi.Geometry{VisibilityKnown: true}
|
||||
tree, err := atspi.NewAccessibleTree(webID("/doc"), nodes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cursor, err := NewDocumentCursor(tree)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
focused, err := cursor.SyncFocus(ctx, webID("/clickable"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if focused.Snapshot.Name != tc.rootName {
|
||||
t.Fatalf("non-structural snapshot name = %q, want captured name %q", focused.Snapshot.Name, tc.rootName)
|
||||
}
|
||||
if _, err := cursor.SyncFocus(ctx, webID("/start")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
move, err := cursor.Move(ctx, DocumentClickable, 0, false)
|
||||
if err != nil || !move.Moved || move.Position.Object.ID() != webID("/clickable") {
|
||||
t.Fatalf("clickable move: %+v %v", move, err)
|
||||
}
|
||||
if move.Position.Snapshot.Name != tc.wantName {
|
||||
t.Fatalf("landed snapshot name = %q, want %q", move.Position.Snapshot.Name, tc.wantName)
|
||||
}
|
||||
ref, err := tree.Reference(webID("/clickable"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
captured, err := tree.Resolve(ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if captured.Name != tc.rootName {
|
||||
t.Fatalf("captured snapshot mutated: name = %q, want %q", captured.Name, tc.rootName)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user