Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package atspi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNativeBrowserSetPositions(t *testing.T) {
|
||||
if os.Getenv("CTHULHU_NATIVE_BROWSER") != "1" {
|
||||
t.Skip("requires private browser session")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
adapter := New()
|
||||
if err := adapter.Start(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer adapter.Stop(context.Background())
|
||||
tree, err := adapter.CaptureDesktop(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
position, size int
|
||||
}{
|
||||
{"First item", 1, 3}, {"Middle item", 2, 3}, {"Last item", 3, 3},
|
||||
{"Virtual item", 501, 1001}, {"Unknown size", 0, 0},
|
||||
{"Nested tree item", 2, 4},
|
||||
{"First menu item", 1, 2}, {"Second menu item", 2, 2},
|
||||
{"First radio", 1, 2}, {"Second radio", 2, 2},
|
||||
} {
|
||||
snapshot, err := tree.Resolve(findNamedReference(t, tree, test.name))
|
||||
if err != nil || snapshot.PositionInSet != test.position || snapshot.SetSize != test.size {
|
||||
t.Errorf("%s (%s): position %d of %d, want %d of %d, err=%v", test.name, snapshot.Role,
|
||||
snapshot.PositionInSet, snapshot.SetSize, test.position, test.size, err)
|
||||
}
|
||||
}
|
||||
// Snapshot capture for a focused event must carry provider metadata too,
|
||||
// rather than only the document-tree path used by browse navigation.
|
||||
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Tab").CombinedOutput(); err != nil {
|
||||
t.Fatalf("focus virtual item: %v %s", err, out)
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case event := <-adapter.Events():
|
||||
if event.Type != FocusedStateEvent || event.Detail1 != 1 || event.Source.Name != "Virtual item" {
|
||||
continue
|
||||
}
|
||||
if event.Source.PositionInSet != 501 || event.Source.SetSize != 1001 {
|
||||
t.Fatalf("focus lost set position: %+v", event.Source)
|
||||
}
|
||||
return
|
||||
case <-ctx.Done():
|
||||
t.Fatal("virtual item focus event missing")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user