Preparing for release.
This commit is contained in:
commit
a7e69b1632
30 files changed
+1026
-21
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/cthulhu/internal/review"
|
||||
"git.stormux.org/storm/cthulhu/internal/sound"
|
||||
"git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
)
|
||||
|
||||
type documentContextCapturer interface {
|
||||
@@ -52,6 +53,7 @@ type browserModeController struct {
|
||||
cancel context.CancelFunc
|
||||
done chan struct{}
|
||||
document atspi.ObjectID
|
||||
focusProcess string // provider process of the latest native focus
|
||||
navigation atspi.ObjectID
|
||||
navigationDocument atspi.ObjectID
|
||||
navigationFocus atspi.ObjectID
|
||||
@@ -240,6 +242,11 @@ func (browser *browserModeController) accept(result browserModeResult, speech sp
|
||||
browser.mutex.Unlock()
|
||||
browser.state = review.DocumentModeState{}
|
||||
browser.state.SetSticky(browser.stickyModes[browser.document.BusName])
|
||||
// Steam popups own their arrow keys and close when focus leaves.
|
||||
// Start them in focus mode; a manual toggle still clears this.
|
||||
if browser.state.Sticky() == review.InactiveMode && gamepadPopupDocument(browser.focusProcess, result.owner) {
|
||||
browser.state.SetSticky(review.FocusMode)
|
||||
}
|
||||
}
|
||||
browser.ready = true
|
||||
modeInput := runtimeModeInput(result.owner)
|
||||
@@ -247,6 +254,16 @@ func (browser *browserModeController) accept(result browserModeResult, speech sp
|
||||
mode := browser.state.Update(modeInput, browser.modeSettings())
|
||||
browser.set(mode, speech, false)
|
||||
}
|
||||
func gamepadPopupDocument(process string, owner atspi.DocumentContext) bool {
|
||||
document := owner.TopLevel.ID()
|
||||
for _, ancestor := range owner.Ancestors {
|
||||
if ancestor.ID() == document {
|
||||
return webscripts.GamepadPopupDocument(process, ancestor.Name)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (browser *browserModeController) modeSettings() review.ModeSettings {
|
||||
if browser.settings != nil {
|
||||
return browser.settings()
|
||||
|
||||
@@ -806,3 +806,56 @@ func TestStructuralNavigationAutomaticFocus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func steamDocumentContext(t *testing.T, documentPath, documentName string) atspi.DocumentContext {
|
||||
t.Helper()
|
||||
button := atspi.Snapshot{BusName: ":1.42", Path: documentPath + "/button", Role: "button", StatesKnown: true, Focusable: true}
|
||||
doc := atspi.Snapshot{BusName: ":1.42", Path: documentPath, Name: documentName, Role: "document web", StatesKnown: true}
|
||||
tree, err := atspi.NewAccessibleTree(doc.ID(), []atspi.TreeNode{{Snapshot: doc, Children: []atspi.ObjectID{button.ID()}}, {Snapshot: button}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ref, _ := tree.Reference(button.ID())
|
||||
owner, err := tree.DocumentContext(ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return owner
|
||||
}
|
||||
|
||||
func TestBrowserModeSteamPopupStartsInFocusMode(t *testing.T) {
|
||||
keys := &modeKeys{}
|
||||
browser := newBrowserModeController(nil, keys, nil)
|
||||
queue := &fakeSpeechQueue{spoken: make(chan string, 16)}
|
||||
main := steamDocumentContext(t, "/main", "Steam Big Picture Mode")
|
||||
popup := steamDocumentContext(t, "/popup", "QuickAccess_uid2")
|
||||
browser.focusProcess = "steamwebhelper"
|
||||
|
||||
browser.follow(main.Ancestors[0].ID())
|
||||
browser.accept(browserModeResult{focus: main.Ancestors[0].ID(), generation: 1, owner: main}, queue)
|
||||
if browser.mode != review.BrowseMode || !keys.enabled {
|
||||
t.Fatalf("main Big Picture view mode = %v, want browse", browser.mode)
|
||||
}
|
||||
browser.follow(popup.Ancestors[0].ID())
|
||||
browser.accept(browserModeResult{focus: popup.Ancestors[0].ID(), generation: 2, owner: popup}, queue)
|
||||
if browser.mode != review.FocusMode || keys.enabled {
|
||||
t.Fatalf("Quick Access mode = %v, want focus so Steam keeps its arrow keys", browser.mode)
|
||||
}
|
||||
browser.toggle(queue)
|
||||
if browser.mode != review.BrowseMode {
|
||||
t.Fatal("manual toggle could not leave focus mode in a Steam popup")
|
||||
}
|
||||
browser.follow(main.Ancestors[0].ID())
|
||||
browser.accept(browserModeResult{focus: main.Ancestors[0].ID(), generation: 3, owner: main}, queue)
|
||||
if browser.mode != review.BrowseMode {
|
||||
t.Fatalf("returning to the main view kept mode %v", browser.mode)
|
||||
}
|
||||
|
||||
other := newBrowserModeController(nil, &modeKeys{}, nil)
|
||||
other.focusProcess = "chrome"
|
||||
other.follow(popup.Ancestors[0].ID())
|
||||
other.accept(browserModeResult{focus: popup.Ancestors[0].ID(), generation: 1, owner: popup}, queue)
|
||||
if other.mode != review.BrowseMode {
|
||||
t.Fatalf("non-Steam document named like a popup got mode %v", other.mode)
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ func (handler *accessibilityEventHandler) filterNavigationAndNames(event atspi.E
|
||||
}
|
||||
if browser != nil && isFocusEvent(event.Type) && !ownedAutocompletePopup(event) {
|
||||
browser.nativeButtonFocus(isFocusGainEvent(event) && (event.Source.Role == "button" || event.Source.Role == "push button" || event.Source.Role == "toggle button"))
|
||||
browser.focusProcess = event.Source.ApplicationProcess
|
||||
browser.follow(event.Source.ID())
|
||||
} else if browser != nil && event.Type == atspi.CaretEvent && !event.Source.Editable {
|
||||
browser.followCaret(event.Source.ID())
|
||||
|
||||
@@ -561,7 +561,12 @@ cthulhu_snapshot cthulhu_capture_snapshot(AtspiAccessible *source, gboolean capt
|
||||
error = NULL;
|
||||
GHashTable *attributes = NULL;
|
||||
gboolean captureSetPosition = !snapshot.defunct && cthulhu_has_set_position(snapshot.role);
|
||||
if (captureDocumentMetadata || g_strcmp0(snapshot.role, "heading") == 0 || captureSetPosition) {
|
||||
// Focus-mode policy needs to distinguish native summaries from ARIA
|
||||
// disclosure buttons, including in the narrow ancestor-only capture.
|
||||
gboolean captureTag = captureDocumentMetadata || (snapshot.expandable && snapshot.focusable);
|
||||
// Event presentation names otherwise unnamed Steam tabs by their ID.
|
||||
gboolean captureElementID = captureDocumentMetadata || g_strcmp0(snapshot.role, "page tab") == 0;
|
||||
if (captureTag || captureElementID || g_strcmp0(snapshot.role, "heading") == 0 || captureSetPosition) {
|
||||
attributes = atspi_accessible_get_attributes(source, &error);
|
||||
}
|
||||
if (error != NULL) {
|
||||
@@ -569,6 +574,12 @@ cthulhu_snapshot cthulhu_capture_snapshot(AtspiAccessible *source, gboolean capt
|
||||
}
|
||||
if (captureSetPosition) cthulhu_capture_set_position(source, attributes, &snapshot);
|
||||
if (attributes != NULL) {
|
||||
if (captureTag) {
|
||||
snapshot.htmlTag = g_strdup(g_hash_table_lookup(attributes, "tag"));
|
||||
}
|
||||
if (captureElementID) {
|
||||
snapshot.elementID = g_strdup(g_hash_table_lookup(attributes, "id"));
|
||||
}
|
||||
if (captureDocumentMetadata) {
|
||||
snapshot.explicitName = g_strcmp0(g_hash_table_lookup(attributes, "explicit-name"), "true") == 0;
|
||||
const gchar *xmlRoles = g_hash_table_lookup(attributes, "xml-roles");
|
||||
@@ -576,12 +587,6 @@ cthulhu_snapshot cthulhu_capture_snapshot(AtspiAccessible *source, gboolean capt
|
||||
snapshot.xmlRoles = g_strdup(xmlRoles);
|
||||
}
|
||||
snapshot.display = g_strdup(g_hash_table_lookup(attributes, "display"));
|
||||
const gchar *htmlTag = g_hash_table_lookup(attributes, "tag");
|
||||
if (htmlTag != NULL) snapshot.htmlTag = g_strdup(htmlTag);
|
||||
const gchar *elementID = g_hash_table_lookup(attributes, "id");
|
||||
if (elementID != NULL) {
|
||||
snapshot.elementID = g_strdup(elementID);
|
||||
}
|
||||
const gchar *containerLive = g_hash_table_lookup(attributes, "container-live");
|
||||
if (containerLive != NULL && (g_strcmp0(containerLive, "off") == 0 ||
|
||||
g_strcmp0(containerLive, "polite") == 0 ||
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
)
|
||||
|
||||
func shouldSpeakEvent(eventType string, detail1 int) bool {
|
||||
@@ -151,6 +153,9 @@ func (adapter *Adapter) captureNativeEventSnapshot(event *C.AtspiEvent, target *
|
||||
}
|
||||
}
|
||||
snapshot.ApplicationProcess = adapter.applicationProcess(target)
|
||||
if name, ok := webscripts.SteamName(snapshot.ApplicationProcess, snapshot.Role, snapshot.Name, snapshot.ElementID); ok {
|
||||
snapshot.Name = name
|
||||
}
|
||||
if snapshot.Role == "slider" ||
|
||||
snapshot.Role == "combo box" && (snapshot.Name == "Key echo speech synthesizer" || snapshot.Name == "Key echo person") {
|
||||
snapshot.ApplicationPID = int(C.atspi_accessible_get_process_id(target, nil))
|
||||
@@ -312,6 +317,10 @@ func (adapter *Adapter) enrichNativeWindowEvent(event *C.AtspiEvent, target *C.A
|
||||
focusEvent.ForegroundMismatch = !adapter.matchForeground(target, window, focusEvent.Window, &focusEvent.ForegroundCheck, false)
|
||||
} else {
|
||||
focusEvent.ForegroundMismatch = !adapter.matchForeground(target, window, focusEvent.Window, nil, focusedMenuItem)
|
||||
if focusEvent.ForegroundMismatch && (eventType == FocusEvent || eventType == FocusedStateEvent) && snapshot.Focused &&
|
||||
adapter.matchSteamOverlayFocus(window) {
|
||||
focusEvent.ForegroundMismatch = false
|
||||
}
|
||||
}
|
||||
if !focusEvent.ForegroundMismatch && window != nil &&
|
||||
(eventType == WindowActivatedEvent || snapshot.Role == "table" || snapshot.Role == "table cell") {
|
||||
|
||||
@@ -9,6 +9,8 @@ package atspi
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
|
||||
// Reject routine background updates before resolving a selected descendant or
|
||||
// capturing text, attributes, values and geometry. Global lifecycle events and
|
||||
// supported notifications retain their existing handling. No new ownership is
|
||||
@@ -61,6 +63,10 @@ func (adapter *Adapter) filterNativeBackgroundEvent(event *C.AtspiEvent, eventTy
|
||||
if adapter.matchForeground(event.source, window, windowID, nil, focusedMenuItem) {
|
||||
return false
|
||||
}
|
||||
if (eventType == FocusEvent || eventType == FocusedStateEvent && event.detail1 != 0) &&
|
||||
adapter.matchSteamOverlayFocus(window) {
|
||||
return false
|
||||
}
|
||||
if origin.BusName == adapter.foregroundWindow.BusName {
|
||||
// Browser suggestions and tooltips can occupy a different top-level
|
||||
// without taking X11 focus. Preserve their existing event-loop checks;
|
||||
@@ -83,3 +89,26 @@ func (adapter *Adapter) filterNativeBackgroundEvent(event *C.AtspiEvent, eventTy
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// matchSteamOverlayFocus checks fresh frame state for a Steam overlay focus
|
||||
// gain. It never changes the correlated foreground window: the main Big
|
||||
// Picture frame keeps that role and reclaims focus when the overlay closes.
|
||||
func (adapter *Adapter) matchSteamOverlayFocus(window *C.AtspiAccessible) bool {
|
||||
if window == nil {
|
||||
return false
|
||||
}
|
||||
process := adapter.applicationProcess(window)
|
||||
if webscripts.MatchProcess(process) != webscripts.Steam {
|
||||
return false
|
||||
}
|
||||
pid := adapter.foregroundProcessID(int(C.atspi_accessible_get_process_id(window, nil)))
|
||||
C.atspi_accessible_clear_cache_single(window)
|
||||
states := C.atspi_accessible_get_state_set(window)
|
||||
if states == nil {
|
||||
return false
|
||||
}
|
||||
showing := C.atspi_state_set_contains(states, C.ATSPI_STATE_SHOWING) != 0
|
||||
iconified := C.atspi_state_set_contains(states, C.ATSPI_STATE_ICONIFIED) != 0
|
||||
C.g_object_unref(C.gpointer(states))
|
||||
return steamOverlayFocusMatches(adapter.Foreground().Client, process, pid, true, showing, iconified)
|
||||
}
|
||||
@@ -87,6 +87,20 @@ func refreshNativeEventTarget(event *C.AtspiEvent, target *C.AtspiAccessible, ev
|
||||
// query the current state/name before using either event path.
|
||||
C.atspi_accessible_clear_cache_single(target)
|
||||
}
|
||||
if eventType == CaretEvent || (eventType == FocusEvent || eventType == FocusedStateEvent) && staleEditableCandidate(target) {
|
||||
// Chromium does not announce children (or a generic container) that
|
||||
// become editable when an ancestor turns contenteditable, so a state
|
||||
// cached while the text was read-only survives (ChatGPT canvas). Only
|
||||
// a cached read-only state can be stale this way; re-read it once.
|
||||
states := C.atspi_accessible_get_state_set(target)
|
||||
if states != nil {
|
||||
editable := C.atspi_state_set_contains(states, C.ATSPI_STATE_EDITABLE) != 0
|
||||
C.g_object_unref(C.gpointer(states))
|
||||
if !editable {
|
||||
C.atspi_accessible_clear_cache_single(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
if eventType == WindowDeactivatedEvent {
|
||||
// Match Python's key-grab churn check against fresh window state rather
|
||||
// than an AT-SPI cache entry from before the deactivation event.
|
||||
@@ -142,3 +156,14 @@ func normalizeNativeMenuFocus(event *C.AtspiEvent, target *C.AtspiAccessible, ev
|
||||
}
|
||||
return eventType, inlineMenuID
|
||||
}
|
||||
|
||||
// staleEditableCandidate limits focus refreshes to generic text containers,
|
||||
// the roles a contenteditable root reports. Controls keep their cached state.
|
||||
func staleEditableCandidate(target *C.AtspiAccessible) bool {
|
||||
switch C.atspi_accessible_get_role(target, nil) {
|
||||
case C.ATSPI_ROLE_SECTION, C.ATSPI_ROLE_PARAGRAPH, C.ATSPI_ROLE_PANEL, C.ATSPI_ROLE_TEXT,
|
||||
C.ATSPI_ROLE_ENTRY, C.ATSPI_ROLE_STATIC, C.ATSPI_ROLE_HEADING, C.ATSPI_ROLE_ARTICLE, C.ATSPI_ROLE_BLOCK_QUOTE:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"slices"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/platform/xorg"
|
||||
"git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
)
|
||||
|
||||
// The native caller supplies a complete, fresh, bounded application window
|
||||
@@ -37,6 +38,16 @@ func preferencesForegroundMatches(client xorg.Foreground, pid int, preferencesPI
|
||||
int64(pid) == preferencesPID && client.PID == pid
|
||||
}
|
||||
|
||||
// Steam Big Picture draws overlays such as Quick Access and the main menu as
|
||||
// separate Chromium frames inside its one X11 window. Steam moves focus into
|
||||
// them but never marks their frame active, so the normal active-frame check
|
||||
// discards that focus. Accept only a confirmed focus gain in a showing frame
|
||||
// owned by the X11 foreground process itself.
|
||||
func steamOverlayFocusMatches(client xorg.Foreground, process string, pid int, focusGain, showing, iconified bool) bool {
|
||||
return focusGain && showing && !iconified && webscripts.MatchProcess(process) == webscripts.Steam &&
|
||||
client.Known && client.Window != 0 && client.PID > 0 && pid == client.PID
|
||||
}
|
||||
|
||||
func foregroundWindowMatches(client xorg.Foreground, pid int, bounds Rectangle) bool {
|
||||
if client.PID > 0 && pid > 0 && client.PID != pid {
|
||||
return false
|
||||
|
||||
@@ -216,3 +216,30 @@ func TestForegroundWindowReplacement(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSteamOverlayFocusMatchesForegroundProcessOnly(t *testing.T) {
|
||||
client := xorg.Foreground{Known: true, Window: 83886130, PID: 111, Width: 1920, Height: 1080}
|
||||
if !steamOverlayFocusMatches(client, "steamwebhelper", 111, true, true, false) {
|
||||
t.Fatal("Quick Access focus in the foreground Steam process was rejected")
|
||||
}
|
||||
cases := map[string]struct {
|
||||
client xorg.Foreground
|
||||
process string
|
||||
pid int
|
||||
focusGain, showing, iconified bool
|
||||
}{
|
||||
"other application": {client, "chrome", 111, true, true, false},
|
||||
"other process": {client, "steamwebhelper", 222, true, true, false},
|
||||
"not a focus gain": {client, "steamwebhelper", 111, false, true, false},
|
||||
"hidden overlay": {client, "steamwebhelper", 111, true, false, false},
|
||||
"iconified overlay": {client, "steamwebhelper", 111, true, true, true},
|
||||
"no foreground window": {xorg.Foreground{Known: true, PID: 111}, "steamwebhelper", 111, true, true, false},
|
||||
"unknown foreground": {xorg.Foreground{Window: 83886130, PID: 111}, "steamwebhelper", 111, true, true, false},
|
||||
"unknown foreground pid": {xorg.Foreground{Known: true, Window: 83886130}, "steamwebhelper", 0, true, true, false},
|
||||
}
|
||||
for name, test := range cases {
|
||||
if steamOverlayFocusMatches(test.client, test.process, test.pid, test.focusGain, test.showing, test.iconified) {
|
||||
t.Errorf("%s: accepted Steam overlay focus", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// A paragraph captured before its container became contenteditable keeps a
|
||||
// read-only state in the AT-SPI cache. Caret events in it must still report
|
||||
// editable text, or the reader drops them as stray document caret movement
|
||||
// (ChatGPT canvas: the first verse went silent while later ones spoke).
|
||||
func TestNativeBrowserLateEditableCaret(t *testing.T) {
|
||||
if os.Getenv("CTHULHU_NATIVE_BROWSER") != "1" {
|
||||
t.Skip("requires private browser session")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 25*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)
|
||||
}
|
||||
// Resolving the paragraph caches its read-only state before the editor opens.
|
||||
paragraph := findRoleReference(t, tree, "paragraph")
|
||||
if snapshot, err := tree.Resolve(paragraph); err != nil || snapshot.Editable {
|
||||
t.Fatalf("fixture paragraph before opening: %+v, %v", snapshot, err)
|
||||
}
|
||||
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Return").CombinedOutput(); err != nil {
|
||||
t.Fatalf("open editor: %v %s", err, out)
|
||||
}
|
||||
moved := false
|
||||
for {
|
||||
select {
|
||||
case event := <-adapter.Events():
|
||||
if !moved && event.Type == FocusedStateEvent && event.Detail1 == 1 && event.Source.Name == "Start writing" {
|
||||
if !event.Source.Editable {
|
||||
t.Fatalf("editor focus reported read-only: role %q", event.Source.Role)
|
||||
}
|
||||
moved = true
|
||||
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Right").CombinedOutput(); err != nil {
|
||||
t.Fatalf("move caret: %v %s", err, out)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !moved || event.Type != CaretEvent || event.Source.Role != "paragraph" {
|
||||
continue
|
||||
}
|
||||
if !event.Source.Editable {
|
||||
t.Fatal("caret in editable paragraph reported read-only")
|
||||
}
|
||||
return
|
||||
case <-ctx.Done():
|
||||
t.Fatal("editor focus or caret event missing")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func findRoleReference(t *testing.T, tree *AccessibleTree, role string) ObjectReference {
|
||||
t.Helper()
|
||||
root, err := tree.Root()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pending := []ObjectReference{root}
|
||||
for len(pending) != 0 {
|
||||
current := pending[0]
|
||||
pending = pending[1:]
|
||||
snapshot, err := tree.Resolve(current)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if snapshot.Role == role {
|
||||
return current
|
||||
}
|
||||
for child, ok, err := tree.FirstChild(current); ok || err != nil; child, ok, err = tree.NextSibling(child) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pending = append(pending, child)
|
||||
}
|
||||
}
|
||||
t.Fatalf("no %s in desktop capture", role)
|
||||
return ObjectReference{}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
)
|
||||
|
||||
// Records how the browser exposes the widgets behind three web mode and
|
||||
// presentation rules: a native disclosure summary, a focusable splitter, and
|
||||
// checkable tree items. The reader's rules depend on these exact traits.
|
||||
func TestNativeBrowserWebWidgetTraits(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())
|
||||
if _, err := adapter.CaptureDesktop(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Native focus decides mode from the narrow ancestor-only context, not
|
||||
// the full document capture used by structural navigation.
|
||||
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Tab").CombinedOutput(); err != nil {
|
||||
t.Fatalf("move focus: %v %s", err, out)
|
||||
}
|
||||
var focus ObjectID
|
||||
for !focus.Valid() {
|
||||
select {
|
||||
case event := <-adapter.Events():
|
||||
if (event.Type == FocusedStateEvent || event.Type == FocusEvent) && event.Detail1 == 1 && event.Source.Name == "Disclosure summary" {
|
||||
focus = event.Source.ID()
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("focus event in the page missing")
|
||||
}
|
||||
}
|
||||
owner, err := adapter.CaptureDocumentContext(ctx, focus)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if summary := owner.Ancestors[0]; summary.HTMLTag != "summary" || !summary.Focusable || !summary.Expandable {
|
||||
t.Fatalf("summary focus context: tag=%q focusable=%v expandable=%v", summary.HTMLTag, summary.Focusable, summary.Expandable)
|
||||
}
|
||||
document, err := adapter.CaptureDocument(ctx, focus)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resolve := func(name string) Snapshot {
|
||||
t.Helper()
|
||||
snapshot, err := document.Resolve(findNamedReference(t, document, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("%s: role=%q tag=%q focusable=%v expandable=%v expanded=%v checkable=%v checked=%v xml-roles=%q",
|
||||
name, snapshot.Role, snapshot.HTMLTag, snapshot.Focusable, snapshot.Expandable, snapshot.Expanded,
|
||||
snapshot.Checkable, snapshot.Checked, snapshot.XMLRoles)
|
||||
return snapshot
|
||||
}
|
||||
if summary := resolve("Disclosure summary"); summary.HTMLTag != "summary" || summary.Role != "toggle button" || !summary.Focusable || !summary.Expandable {
|
||||
t.Errorf("summary traits: %+v", summary)
|
||||
}
|
||||
if splitter := resolve("Pane splitter"); splitter.Role != "separator" || !splitter.Focusable {
|
||||
t.Errorf("splitter traits: %+v", splitter)
|
||||
}
|
||||
if static := resolve("Static separator"); static.Role != "separator" || static.Focusable {
|
||||
t.Errorf("static separator traits: %+v", static)
|
||||
}
|
||||
if checked := resolve("Checked option"); checked.Role != "tree item" || !checked.Checkable || !checked.Checked {
|
||||
t.Errorf("checked tree item traits: %+v", checked)
|
||||
}
|
||||
if unchecked := resolve("Unchecked option"); !unchecked.Checkable || unchecked.Checked {
|
||||
t.Errorf("unchecked tree item traits: %+v", unchecked)
|
||||
}
|
||||
if plain := resolve("Plain option"); plain.Checkable {
|
||||
t.Errorf("plain tree item reported checkable: %+v", plain)
|
||||
}
|
||||
// The Steam naming fallback consumes an event snapshot. A full document
|
||||
// capture carrying IDs does not prove the event path carries them too.
|
||||
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Tab", "Tab", "Tab").CombinedOutput(); err != nil {
|
||||
t.Fatalf("focus unnamed tab: %v %s", err, out)
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case event := <-adapter.Events():
|
||||
if (event.Type != FocusedStateEvent && event.Type != FocusEvent) || !event.Source.Focused || event.Source.Role != "page tab" {
|
||||
continue
|
||||
}
|
||||
if event.Source.ElementID != "quickaccess_tab_3" || event.Source.Name != "" {
|
||||
t.Fatalf("unnamed tab event: id=%q name=%q", event.Source.ElementID, event.Source.Name)
|
||||
}
|
||||
name, ok := webscripts.SteamName("steamwebhelper", event.Source.Role, event.Source.Name, event.Source.ElementID)
|
||||
if !ok || name != "Friends" {
|
||||
t.Fatalf("Steam tab name from native event = %q, %v", name, ok)
|
||||
}
|
||||
if _, ok := webscripts.SteamName(event.Source.ApplicationProcess, event.Source.Role, event.Source.Name, event.Source.ElementID); ok {
|
||||
t.Fatal("ordinary browser received a Steam tab name")
|
||||
}
|
||||
return
|
||||
case <-ctx.Done():
|
||||
t.Fatal("unnamed tab focus event missing")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,9 +93,15 @@ func (adapter *Adapter) webNotification(event *C.AtspiEvent) *webscripts.Notific
|
||||
C.g_object_unref(C.gpointer(ancestor))
|
||||
}
|
||||
}()
|
||||
documentName, documentFound := "", false
|
||||
for current := C.web_ref(source); current != nil; {
|
||||
ancestors = append(ancestors, current)
|
||||
role := C.atspi_accessible_get_role(current, nil)
|
||||
if role == C.ATSPI_ROLE_DOCUMENT_WEB && !documentFound {
|
||||
name := C.atspi_accessible_get_name(current, nil)
|
||||
documentName, documentFound = C.GoString(name), true
|
||||
C.g_free(C.gpointer(name))
|
||||
}
|
||||
candidate := webscripts.NotificationCandidate{}
|
||||
switch role {
|
||||
case C.ATSPI_ROLE_NOTIFICATION:
|
||||
@@ -116,7 +122,7 @@ func (adapter *Adapter) webNotification(event *C.AtspiEvent) *webscripts.Notific
|
||||
current = C.atspi_accessible_get_parent(current, nil)
|
||||
}
|
||||
index := webscripts.NotificationRoot(candidates)
|
||||
if index < 0 {
|
||||
if index < 0 || candidates[index].Role == "" && !webscripts.ToastDocument(documentName) {
|
||||
return nil
|
||||
}
|
||||
root := ancestors[index]
|
||||
|
||||
@@ -88,7 +88,12 @@ func controlValue(snapshot atspi.Snapshot) string {
|
||||
|
||||
func controlStates(snapshot atspi.Snapshot) []string {
|
||||
var states []string
|
||||
switch snapshot.ControlRole() {
|
||||
role := snapshot.ControlRole()
|
||||
if role == "tree item" && snapshot.Checkable {
|
||||
// aria-checked tree items (checkbox trees) report their checked state.
|
||||
role = "check box"
|
||||
}
|
||||
switch role {
|
||||
case "check box", "check menu item":
|
||||
switch {
|
||||
case snapshot.Indeterminate:
|
||||
|
||||
@@ -38,6 +38,10 @@ func TestFocusTextPresentsControlStates(t *testing.T) {
|
||||
{name: "toggle pressed", snapshot: atspi.Snapshot{Name: "Bold", Role: "toggle button", Checked: true}, want: "Bold, toggle button, pressed"},
|
||||
{name: "collapsed item", snapshot: atspi.Snapshot{Name: "Documents", Role: "tree item", Expandable: true}, want: "Documents, tree item, collapsed"},
|
||||
{name: "expanded selected item", snapshot: atspi.Snapshot{Name: "Documents", Role: "tree item", Expandable: true, Expanded: true, Selected: true}, want: "Documents, tree item, expanded, selected"},
|
||||
{name: "checked tree item", snapshot: atspi.Snapshot{Name: "Backups", Role: "tree item", Checkable: true, Checked: true}, want: "Backups, tree item, checked"},
|
||||
{name: "unchecked tree item", snapshot: atspi.Snapshot{Name: "Backups", Role: "tree item", Checkable: true}, want: "Backups, tree item, not checked"},
|
||||
{name: "mixed tree item", snapshot: atspi.Snapshot{Name: "Backups", Role: "tree item", Checkable: true, Indeterminate: true}, want: "Backups, tree item, partially checked"},
|
||||
{name: "plain tree item", snapshot: atspi.Snapshot{Name: "Backups", Role: "tree item"}, want: "Backups, tree item"},
|
||||
{name: "selected menu item", snapshot: atspi.Snapshot{Name: "Open", Role: "menu item", Selected: true}, want: "Open, menu item"},
|
||||
{name: "unchecked generic menu", snapshot: atspi.Snapshot{Name: "Updates", Role: "menu item", Checkable: true}, want: "Updates, check menu item, not checked"},
|
||||
{name: "checked generic menu without marker", snapshot: atspi.Snapshot{Name: "Updates", Role: "menu item", Checked: true}, want: "Updates, check menu item, checked"},
|
||||
@@ -67,6 +71,8 @@ func TestEventTextPresentsOnlyChangedState(t *testing.T) {
|
||||
{name: "checked", event: atspi.NewEvent("object:state-changed:checked", atspi.Snapshot{Name: "Updates", Role: "check box", Checked: true}), want: "checked"},
|
||||
{name: "generic menu checked", event: atspi.NewEvent("object:state-changed:checked", atspi.Snapshot{Name: "Updates", Role: "menu item", Checkable: true, Checked: true}), want: "checked"},
|
||||
{name: "generic menu unchecked without marker", event: atspi.NewEvent("object:state-changed:checked", atspi.Snapshot{Name: "Updates", Role: "menu item"}), want: "not checked"},
|
||||
{name: "tree item checked", event: atspi.NewEvent("object:state-changed:checked", atspi.Snapshot{Name: "Backups", Role: "tree item", Checkable: true, Checked: true}), want: "checked"},
|
||||
{name: "tree item unchecked", event: atspi.NewEvent("object:state-changed:checked", atspi.Snapshot{Name: "Backups", Role: "tree item", Checkable: true}), want: "not checked"},
|
||||
{name: "expanded", event: atspi.NewEvent("object:state-changed:expanded", atspi.Snapshot{Name: "Files", Role: "tree item", Expanded: true}), want: "expanded"},
|
||||
{name: "menu selection omitted", event: atspi.NewEvent("object:state-changed:selected", atspi.Snapshot{Name: "Open", Role: "menu item", Selected: true}), want: ""},
|
||||
{name: "tree selection", event: atspi.NewEvent("object:state-changed:selected", atspi.Snapshot{Name: "Files", Role: "tree item", Selected: true}), want: "selected"},
|
||||
|
||||
@@ -158,7 +158,9 @@ func FocusSpeechWithOptions(snapshot atspi.Snapshot, options Options) Speech {
|
||||
if options.SpeakDescription {
|
||||
fields = append(fields, snapshot.Description)
|
||||
}
|
||||
if snapshot.Role != "spin button" {
|
||||
// An empty rich editor can expose only an embedded paragraph's object
|
||||
// replacement character (ChatGPT's message box). It is not content.
|
||||
if snapshot.Role != "spin button" && strings.TrimSpace(strings.ReplaceAll(snapshot.Text, "\ufffc", "")) != "" {
|
||||
fields = append(fields, snapshot.Text)
|
||||
}
|
||||
if snapshot.Autocomplete && snapshot.SelectionEnd > snapshot.SelectionStart {
|
||||
|
||||
@@ -292,3 +292,14 @@ func TestDocumentLoadAnnouncesOnlyTitle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFocusTextOmitsEmbeddedObjectPlaceholder(t *testing.T) {
|
||||
entry := atspi.Snapshot{Name: "Ask ChatGPT", Role: "entry", Editable: true, Text: ""}
|
||||
if got := FocusTextWithOptions(entry, DefaultOptions()); strings.ContainsRune(got, '') || got != FocusTextWithOptions(atspi.Snapshot{Name: "Ask ChatGPT", Role: "entry", Editable: true}, DefaultOptions()) {
|
||||
t.Fatalf("empty rich editor focus = %q", got)
|
||||
}
|
||||
entry.Text = "Hello"
|
||||
if got := FocusTextWithOptions(entry, DefaultOptions()); !strings.Contains(got, "Hello") {
|
||||
t.Fatalf("editor with text lost its content: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,20 @@ func (cursor *DocumentCursor) captureAnchor(focus atspi.ObjectID) (atspi.ObjectI
|
||||
return document, true
|
||||
}
|
||||
|
||||
// savedDocument reports the document of the most recent saved place.
|
||||
func (cursor *DocumentCursor) savedDocument() (atspi.ObjectID, bool) {
|
||||
if cursor == nil {
|
||||
return atspi.ObjectID{}, false
|
||||
}
|
||||
cursor.mu.Lock()
|
||||
defer cursor.mu.Unlock()
|
||||
if len(cursor.places) == 0 {
|
||||
return atspi.ObjectID{}, false
|
||||
}
|
||||
document := cursor.places[len(cursor.places)-1].document.ID()
|
||||
return document, document.Valid()
|
||||
}
|
||||
|
||||
func NewDocumentCursor(tree *atspi.AccessibleTree) (*DocumentCursor, error) {
|
||||
if tree == nil {
|
||||
return nil, errors.New("create document cursor: nil accessible tree")
|
||||
|
||||
@@ -152,7 +152,13 @@ func (state *DocumentModeState) decide(input ModeInput, settings ModeSettings) D
|
||||
func focusModeWidget(input ModeInput) bool {
|
||||
object := input.Context.Ancestors[0]
|
||||
traits := input.Traits
|
||||
if object.Editable || object.Expandable && object.Focusable && object.Role != "link" {
|
||||
// A native <summary> stays in browse mode so its expanded details can be
|
||||
// read without switching back (Orca issue #543).
|
||||
if object.Editable || object.Expandable && object.Focusable && object.Role != "link" && object.HTMLTag != "summary" {
|
||||
return true
|
||||
}
|
||||
// A focusable separator is a splitter: arrow keys resize the panes.
|
||||
if object.Role == "separator" && object.Focusable {
|
||||
return true
|
||||
}
|
||||
switch object.Role {
|
||||
|
||||
@@ -217,3 +217,26 @@ func TestDocumentModeUnknownStates(t *testing.T) {
|
||||
t.Fatalf("recaptured states did not restore mode: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocumentModeSummaryAndSplitter(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
snapshot atspi.Snapshot
|
||||
want DocumentMode
|
||||
}{
|
||||
{"native summary", atspi.Snapshot{Role: "toggle button", HTMLTag: "summary", Focusable: true, Expandable: true, Expanded: true}, BrowseMode},
|
||||
{"aria disclosure button", atspi.Snapshot{Role: "toggle button", HTMLTag: "div", Focusable: true, Expandable: true}, FocusMode},
|
||||
{"focusable splitter", atspi.Snapshot{Role: "separator", HTMLTag: "div", Focusable: true}, FocusMode},
|
||||
{"static separator", atspi.Snapshot{Role: "separator", HTMLTag: "hr"}, BrowseMode},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
input := modeInput(t, test.snapshot.Role)
|
||||
test.snapshot.StatesKnown = true
|
||||
input.Context.Ancestors[0] = test.snapshot
|
||||
var state DocumentModeState
|
||||
if got := state.Update(input, DefaultModeSettings()); got != test.want {
|
||||
t.Fatalf("got %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func TestDocumentRecoveryKeepsVirtualPlaceWhenNativeAnchorDisappears(t *testing.
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := Result{DocumentFocus: webID("/text")}
|
||||
if !worker.recoverCapturedDocumentFocus(cursor, cursor.tree, &result) {
|
||||
if !worker.recoverCapturedDocumentFocus(cursor, cursor.tree, &result, false) {
|
||||
t.Fatal("removed native anchor was not recovered")
|
||||
}
|
||||
if _, err := cursor.SyncFocus(ctx, result.DocumentFocus); err != nil {
|
||||
|
||||
@@ -198,6 +198,52 @@ func (worker *Worker) captureDocumentForMove(ctx context.Context, cursor *Docume
|
||||
return fallbackTree, duration + fallbackDuration, nil
|
||||
}
|
||||
|
||||
// maxDeadFocusDocuments bounds the documents tried for one dead focus, so an
|
||||
// unresponsive provider cannot multiply the interactive capture budget.
|
||||
const maxDeadFocusDocuments = 2
|
||||
|
||||
// captureRetainedDocumentForDeadFocus handles a focus that died before any
|
||||
// navigation adopted it, such as Steam's loading spinner after a popup
|
||||
// closes. captureAnchor cannot help because the dead focus was never a saved
|
||||
// place. Try the current document first. Only a confirmed missing document
|
||||
// permits trying another retained document of the same provider: a timeout or
|
||||
// failed refresh is not evidence that focus belongs elsewhere. A live focus
|
||||
// never gets here: capture keyed on it succeeds or fails with another error.
|
||||
func (worker *Worker) captureRetainedDocumentForDeadFocus(ctx context.Context, current *DocumentCursor, focus atspi.ObjectID, loadEpoch uint64) (*atspi.AccessibleTree, *DocumentCursor, time.Duration, bool) {
|
||||
if current == nil || worker.documentCursorEpochs[current.tree] != loadEpoch {
|
||||
return nil, nil, 0, false
|
||||
}
|
||||
document, ok := current.savedDocument()
|
||||
if !ok || document.BusName != focus.BusName || document == focus {
|
||||
return nil, nil, 0, false
|
||||
}
|
||||
candidates := append([]*DocumentCursor{current}, worker.retainedCursorsExcept(current, loadEpoch)...)
|
||||
var total time.Duration
|
||||
tried := 0
|
||||
for _, retained := range candidates {
|
||||
document, ok := retained.savedDocument()
|
||||
if !ok || document.BusName != focus.BusName || document == focus {
|
||||
continue
|
||||
}
|
||||
if tried == maxDeadFocusDocuments {
|
||||
break
|
||||
}
|
||||
tried++
|
||||
captureContext, cancel := context.WithTimeout(ctx, worker.documentCaptureTimeout)
|
||||
started := time.Now()
|
||||
tree, err := worker.capturer.CaptureDocument(captureContext, document)
|
||||
total += time.Since(started)
|
||||
cancel()
|
||||
if err == nil && tree != nil {
|
||||
return tree, retained, total, true
|
||||
}
|
||||
if !errors.Is(err, atspi.ErrObjectNotFound) && !errors.Is(err, atspi.ErrDeadObject) {
|
||||
return nil, nil, total, false
|
||||
}
|
||||
}
|
||||
return nil, nil, total, false
|
||||
}
|
||||
|
||||
func (worker *Worker) moveDocument(ctx context.Context, cursor *DocumentCursor, target DocumentTarget, level int, backwards bool, epoch, loadEpoch uint64) (Result, *DocumentCursor) {
|
||||
return worker.moveDocumentRepeated(ctx, cursor, target, level, backwards, epoch, loadEpoch, 1)
|
||||
}
|
||||
@@ -261,6 +307,15 @@ func (worker *Worker) moveDocumentRepeated(ctx context.Context, cursor *Document
|
||||
result.CaptureReason = result.Err
|
||||
result.DocumentDiagnostics.CaptureAttempts++
|
||||
tree, captureDuration, err := worker.captureDocumentForMove(ctx, cursor, result.DocumentFocus)
|
||||
adopted := false
|
||||
if errors.Is(err, atspi.ErrObjectNotFound) {
|
||||
if retainedTree, retained, retainedDuration, ok := worker.captureRetainedDocumentForDeadFocus(ctx, cursor, result.DocumentFocus, loadEpoch); ok {
|
||||
tree, err, cursor, adopted = retainedTree, nil, retained, true
|
||||
captureDuration += retainedDuration
|
||||
} else {
|
||||
captureDuration += retainedDuration
|
||||
}
|
||||
}
|
||||
result.CaptureDuration = captureDuration
|
||||
if err != nil {
|
||||
result.Err = err
|
||||
@@ -270,7 +325,7 @@ func (worker *Worker) moveDocumentRepeated(ctx context.Context, cursor *Document
|
||||
result.Err = errors.New("capture document tree: nil tree")
|
||||
return result, cursor
|
||||
}
|
||||
recovered := worker.recoverCapturedDocumentFocus(cursor, tree, &result)
|
||||
recovered := worker.recoverCapturedDocumentFocus(cursor, tree, &result, adopted)
|
||||
if cursor == nil || cursor.tree != tree {
|
||||
retained, created, _ := worker.cursorForTree(tree, loadEpoch)
|
||||
result.DocumentDiagnostics.CursorRecreated = created
|
||||
@@ -395,6 +450,31 @@ func documentCaretNeedsRecapture(err error) bool {
|
||||
}
|
||||
|
||||
func (worker *Worker) moveDocumentCaret(ctx context.Context, cursor *DocumentCursor, command DocumentCaretCommand, epoch, loadEpoch uint64) (Result, *DocumentCursor) {
|
||||
result, cursor := worker.moveDocumentCaretOnce(ctx, cursor, command, epoch, loadEpoch)
|
||||
if command != CaretDocumentStart && command != CaretDocumentEnd || !errors.Is(result.Err, atspi.ErrDeadObject) ||
|
||||
!worker.CurrentDocumentResult(result) || worker.focus() != result.DocumentFocus {
|
||||
return result, cursor
|
||||
}
|
||||
// The selected first or last object died before placement and is absent
|
||||
// from the fresh tree. Unlike relative moves, start and end name the same
|
||||
// place however often they run, so choosing again cannot skip content.
|
||||
tree, captureDuration, err := worker.captureDocumentForMove(ctx, cursor, result.DocumentFocus)
|
||||
if err != nil || tree == nil {
|
||||
return result, cursor
|
||||
}
|
||||
if cursor == nil || cursor.tree != tree {
|
||||
cursor, _, err = worker.cursorForTree(tree, loadEpoch)
|
||||
if err != nil {
|
||||
return result, cursor
|
||||
}
|
||||
}
|
||||
retry, cursor := worker.moveDocumentCaretOnce(ctx, cursor, command, epoch, loadEpoch)
|
||||
retry.CaptureDuration += result.CaptureDuration + captureDuration
|
||||
retry.DocumentDiagnostics.CaptureAttempts += result.DocumentDiagnostics.CaptureAttempts + 1
|
||||
return retry, cursor
|
||||
}
|
||||
|
||||
func (worker *Worker) moveDocumentCaretOnce(ctx context.Context, cursor *DocumentCursor, command DocumentCaretCommand, epoch, loadEpoch uint64) (Result, *DocumentCursor) {
|
||||
result := Result{DocumentEpoch: epoch, DocumentCaretCommand: command, DocumentFocus: worker.focus()}
|
||||
if !result.DocumentFocus.Valid() {
|
||||
result.Err = ErrNoCurrent
|
||||
@@ -456,6 +536,15 @@ func (worker *Worker) moveDocumentCaret(ctx context.Context, cursor *DocumentCur
|
||||
result.CaptureReason = result.Err
|
||||
result.DocumentDiagnostics.CaptureAttempts++
|
||||
tree, captureDuration, err := worker.captureDocumentForMove(ctx, cursor, result.DocumentFocus)
|
||||
adopted := false
|
||||
if errors.Is(err, atspi.ErrObjectNotFound) {
|
||||
if retainedTree, retained, retainedDuration, ok := worker.captureRetainedDocumentForDeadFocus(ctx, cursor, result.DocumentFocus, loadEpoch); ok {
|
||||
tree, err, cursor, adopted = retainedTree, nil, retained, true
|
||||
captureDuration += retainedDuration
|
||||
} else {
|
||||
captureDuration += retainedDuration
|
||||
}
|
||||
}
|
||||
result.CaptureDuration = captureDuration
|
||||
if err != nil {
|
||||
result.Err = err
|
||||
@@ -465,7 +554,7 @@ func (worker *Worker) moveDocumentCaret(ctx context.Context, cursor *DocumentCur
|
||||
result.Err = errors.New("capture document tree: nil tree")
|
||||
return result, cursor
|
||||
}
|
||||
recovered := worker.recoverCapturedDocumentFocus(cursor, tree, &result)
|
||||
recovered := worker.recoverCapturedDocumentFocus(cursor, tree, &result, adopted)
|
||||
if cursor == nil || cursor.tree != tree {
|
||||
retained, created, _ := worker.cursorForTree(tree, loadEpoch)
|
||||
result.DocumentDiagnostics.CursorRecreated = created
|
||||
@@ -665,7 +754,10 @@ func (worker *Worker) refreshDocumentCursorWithRecovery(ctx context.Context, cur
|
||||
return fresh, nil
|
||||
}
|
||||
|
||||
func (worker *Worker) recoverCapturedDocumentFocus(cursor *DocumentCursor, tree *atspi.AccessibleTree, result *Result) bool {
|
||||
// adopted reports that the dead focus was never part of cursor's saved place
|
||||
// and cursor's document was chosen by captureRetainedDocumentForDeadFocus. The
|
||||
// saved place then becomes the anchor, so its reading position is kept.
|
||||
func (worker *Worker) recoverCapturedDocumentFocus(cursor *DocumentCursor, tree *atspi.AccessibleTree, result *Result, adopted bool) bool {
|
||||
if cursor == nil || len(cursor.places) == 0 {
|
||||
return false
|
||||
}
|
||||
@@ -688,7 +780,7 @@ func (worker *Worker) recoverCapturedDocumentFocus(cursor *DocumentCursor, tree
|
||||
if cursor.tree == tree {
|
||||
cursor.mu.Lock()
|
||||
place := &cursor.places[len(cursor.places)-1]
|
||||
if place.document == root && place.focus.ID() == result.DocumentFocus {
|
||||
if place.document == root && (adopted || place.focus.ID() == result.DocumentFocus) {
|
||||
place.focus = root
|
||||
}
|
||||
cursor.mu.Unlock()
|
||||
|
||||
@@ -604,12 +604,12 @@ func TestRecoverRemovedDocumentFocusStaysInActiveDocument(t *testing.T) {
|
||||
}
|
||||
worker.SyncFocus(webID("/first"))
|
||||
result := Result{DocumentFocus: webID("/first"), CaptureReason: atspi.ErrObjectNotFound}
|
||||
if !worker.recoverCapturedDocumentFocus(cursor, tree, &result) || result.DocumentFocus != webID("/doc") || worker.focus() != webID("/doc") {
|
||||
if !worker.recoverCapturedDocumentFocus(cursor, tree, &result, false) || result.DocumentFocus != webID("/doc") || worker.focus() != webID("/doc") {
|
||||
t.Fatalf("same-document recovery failed: %+v, focus %v", result, worker.focus())
|
||||
}
|
||||
worker.SyncFocus(webID("/chrome"))
|
||||
result.DocumentFocus = webID("/first")
|
||||
if worker.recoverCapturedDocumentFocus(cursor, tree, &result) || worker.focus() != webID("/chrome") {
|
||||
if worker.recoverCapturedDocumentFocus(cursor, tree, &result, false) || worker.focus() != webID("/chrome") {
|
||||
t.Fatal("recovery displaced browser chrome focus")
|
||||
}
|
||||
worker.SyncFocus(webID("/first"))
|
||||
@@ -619,7 +619,7 @@ func TestRecoverRemovedDocumentFocusStaysInActiveDocument(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if worker.recoverCapturedDocumentFocus(cursor, otherTree, &result) || worker.focus() != webID("/first") {
|
||||
if worker.recoverCapturedDocumentFocus(cursor, otherTree, &result, false) || worker.focus() != webID("/first") {
|
||||
t.Fatal("recovery crossed to another document")
|
||||
}
|
||||
}
|
||||
@@ -1433,3 +1433,243 @@ func TestCaptureAnchorRequiresSavedPlaceIdentity(t *testing.T) {
|
||||
t.Fatal("capture anchor fired for an unrelated same-bus object")
|
||||
}
|
||||
}
|
||||
|
||||
// Steam shows a loading spinner when a popup closes, focus lands on it, and
|
||||
// the spinner is removed before the next key. That dead focus was never a
|
||||
// saved place, so captureAnchor cannot recover it. The move must continue
|
||||
// from the reading place in the surviving document instead of reporting
|
||||
// "Could not find current location" on every key.
|
||||
func TestDeadFocusNeverSavedRecoversThroughRetainedDocument(t *testing.T) {
|
||||
treeA := retainedDocumentTree(t, "/docA", "/a1", "/a2")
|
||||
treeB := retainedDocumentTree(t, "/docB", "/b1", "/b2", "/b3")
|
||||
cursorA, _ := NewDocumentCursor(treeA)
|
||||
cursorB, _ := NewDocumentCursor(treeB)
|
||||
ctx := context.Background()
|
||||
if _, err := cursorB.SyncFocus(ctx, webID("/b2")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := cursorA.SyncFocus(ctx, webID("/a1")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The popup document is gone; the main document survives unchanged.
|
||||
treeA.Invalidate(webID("/a1"))
|
||||
treeA.Invalidate(webID("/docA"))
|
||||
capturer := &retainedDocumentCapturer{trees: map[atspi.ObjectID]*atspi.AccessibleTree{webID("/docB"): treeB}}
|
||||
worker, err := NewWorker(capturer, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker.rememberDocumentCursor(cursorB, 0)
|
||||
worker.rememberDocumentCursor(cursorA, 0)
|
||||
worker.SyncFocus(webID("/spinner"))
|
||||
result, _ := worker.moveDocument(ctx, cursorA, DocumentHeading, 0, false, 0, 0)
|
||||
if result.Err != nil || !result.Moved || result.DocumentPosition.Object.ID() != webID("/b3") {
|
||||
t.Fatalf("dead unsaved focus: object=%v moved=%v error=%v captures=%v",
|
||||
result.DocumentPosition.Object.ID(), result.Moved, result.Err, capturer.captures)
|
||||
}
|
||||
if worker.focus() != webID("/docB") {
|
||||
t.Fatalf("anchor = %v, want surviving document /docB", worker.focus())
|
||||
}
|
||||
result, _ = worker.moveDocument(ctx, cursorB, DocumentHeading, 0, true, 0, 0)
|
||||
if result.Err != nil || result.DocumentPosition.Object.ID() != webID("/b2") {
|
||||
t.Fatalf("next key after recovery: object=%v error=%v", result.DocumentPosition.Object.ID(), result.Err)
|
||||
}
|
||||
}
|
||||
|
||||
// A transient focus can die in the current document without ever becoming a
|
||||
// saved place. An older document on the same bus must not take over the move.
|
||||
func TestDeadFocusNeverSavedKeepsCurrentDocument(t *testing.T) {
|
||||
for _, retainOther := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(retainOther), func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tree := retainedDocumentTree(t, "/doc", "/first", "/second", "/third")
|
||||
cursor, err := NewDocumentCursor(tree)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := cursor.SyncFocus(ctx, webID("/second")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
capturer := &retainedDocumentCapturer{trees: map[atspi.ObjectID]*atspi.AccessibleTree{webID("/doc"): tree}}
|
||||
worker, err := NewWorker(capturer, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if retainOther {
|
||||
other := retainedDocumentTree(t, "/other", "/old1", "/old2")
|
||||
otherCursor, err := NewDocumentCursor(other)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := otherCursor.SyncFocus(ctx, webID("/old1")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
capturer.trees[webID("/other")] = other
|
||||
worker.rememberDocumentCursor(otherCursor, 0)
|
||||
}
|
||||
worker.rememberDocumentCursor(cursor, 0)
|
||||
worker.SyncFocus(webID("/spinner"))
|
||||
result, recovered := worker.moveDocument(ctx, cursor, DocumentHeading, 0, false, 0, 0)
|
||||
if result.Err != nil || !result.Moved || recovered != cursor || result.DocumentPosition.Object.ID() != webID("/third") || worker.focus() != webID("/doc") {
|
||||
t.Fatalf("dead focus recovery: object=%v focus=%v error=%v captures=%v", result.DocumentPosition.Object.ID(), worker.focus(), result.Err, capturer.captures)
|
||||
}
|
||||
if len(capturer.captures) != 2 || capturer.captures[1] != webID("/doc") {
|
||||
t.Fatalf("captures = %v, want dead focus then current document", capturer.captures)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type retainedCaretCapturer struct {
|
||||
*retainedDocumentCapturer
|
||||
caretTextReader
|
||||
}
|
||||
|
||||
func TestDeadFocusNeverSavedKeepsCurrentCaretOffset(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
reader := caretTextReader{webID("/text"): "Alpha", webID("/next"): "Next"}
|
||||
cursor := newCaretTextCursor(t, reader)
|
||||
if move, err := cursor.MoveCaret(ctx, reader, CaretNextCharacter); err != nil || move.Position.Offset != 1 {
|
||||
t.Fatalf("initial caret move = %+v, %v", move, err)
|
||||
}
|
||||
capturer := &retainedCaretCapturer{
|
||||
retainedDocumentCapturer: &retainedDocumentCapturer{trees: map[atspi.ObjectID]*atspi.AccessibleTree{webID("/doc"): cursor.tree}},
|
||||
caretTextReader: reader,
|
||||
}
|
||||
worker, err := NewWorker(capturer, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker.rememberDocumentCursor(cursor, 0)
|
||||
worker.SyncFocus(webID("/spinner"))
|
||||
result, recovered := worker.moveDocumentCaret(ctx, cursor, CaretNextCharacter, 0, 0)
|
||||
if result.Err != nil || !result.Moved || recovered != cursor || result.DocumentPosition.Object.ID() != webID("/text") || result.DocumentPosition.Offset != 2 {
|
||||
t.Fatalf("caret after dead focus: object=%v offset=%d error=%v", result.DocumentPosition.Object.ID(), result.DocumentPosition.Offset, result.Err)
|
||||
}
|
||||
}
|
||||
|
||||
type failedDocumentCapturer struct {
|
||||
*retainedDocumentCapturer
|
||||
failure error
|
||||
}
|
||||
|
||||
func (capturer *failedDocumentCapturer) CaptureDocument(ctx context.Context, focus atspi.ObjectID) (*atspi.AccessibleTree, error) {
|
||||
if focus == webID("/doc") {
|
||||
capturer.captures = append(capturer.captures, focus)
|
||||
return nil, capturer.failure
|
||||
}
|
||||
return capturer.retainedDocumentCapturer.CaptureDocument(ctx, focus)
|
||||
}
|
||||
|
||||
func TestDeadFocusRecoveryDoesNotLeaveFailedCurrentDocument(t *testing.T) {
|
||||
for _, failure := range []error{context.DeadlineExceeded, atspi.ErrStaleObject, atspi.ErrIncompleteTree, nil} {
|
||||
t.Run(fmt.Sprint(failure), func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tree := retainedDocumentTree(t, "/doc", "/first")
|
||||
other := retainedDocumentTree(t, "/other", "/old")
|
||||
cursor, _ := NewDocumentCursor(tree)
|
||||
otherCursor, _ := NewDocumentCursor(other)
|
||||
if _, err := cursor.SyncFocus(ctx, webID("/first")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := otherCursor.SyncFocus(ctx, webID("/old")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
capturer := &failedDocumentCapturer{retainedDocumentCapturer: &retainedDocumentCapturer{trees: map[atspi.ObjectID]*atspi.AccessibleTree{webID("/other"): other}}, failure: failure}
|
||||
worker, err := NewWorker(capturer, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker.rememberDocumentCursor(otherCursor, 0)
|
||||
worker.rememberDocumentCursor(cursor, 0)
|
||||
worker.SyncFocus(webID("/spinner"))
|
||||
if _, _, _, ok := worker.captureRetainedDocumentForDeadFocus(ctx, cursor, webID("/spinner"), 0); ok {
|
||||
t.Fatal("failed current document adopted another document")
|
||||
}
|
||||
if len(capturer.captures) != 1 || capturer.captures[0] != webID("/doc") || worker.focus() != webID("/spinner") {
|
||||
t.Fatalf("recovery after failed current document: captures=%v focus=%v", capturer.captures, worker.focus())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A dead focus on another provider must not be rebound into an unrelated
|
||||
// application's retained document.
|
||||
func TestDeadFocusRecoveryStaysOnProviderBus(t *testing.T) {
|
||||
treeB := retainedDocumentTree(t, "/docB", "/b1", "/b2")
|
||||
cursorB, _ := NewDocumentCursor(treeB)
|
||||
if _, err := cursorB.SyncFocus(context.Background(), webID("/b1")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
capturer := &retainedDocumentCapturer{trees: map[atspi.ObjectID]*atspi.AccessibleTree{webID("/docB"): treeB}}
|
||||
worker, err := NewWorker(capturer, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker.rememberDocumentCursor(cursorB, 0)
|
||||
other := atspi.NewObjectID(":9.9", "/spinner")
|
||||
if _, _, _, ok := worker.captureRetainedDocumentForDeadFocus(context.Background(), cursorB, other, 0); ok {
|
||||
t.Fatal("dead focus adopted another provider's document")
|
||||
}
|
||||
if len(capturer.captures) != 0 {
|
||||
t.Fatalf("cross-provider recovery captured documents: %v", capturer.captures)
|
||||
}
|
||||
}
|
||||
|
||||
type deadStartNavigator struct {
|
||||
*readAllCapturer
|
||||
caretTextReader
|
||||
placements []atspi.ObjectID
|
||||
replace func()
|
||||
}
|
||||
|
||||
func (navigator *deadStartNavigator) SetDocumentCaretPosition(_ context.Context, position atspi.ObjectReference, _ atspi.ObjectID, _ int) error {
|
||||
navigator.placements = append(navigator.placements, position.ID())
|
||||
if position.ID() == webID("/text") {
|
||||
if navigator.replace != nil {
|
||||
navigator.replace()
|
||||
navigator.replace = nil
|
||||
}
|
||||
return atspi.ErrDeadObject
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Steam replaced the top of its page between capture and placement, so the
|
||||
// first object chosen for document start no longer existed. Start must
|
||||
// choose again from the fresh tree instead of reporting no location.
|
||||
func TestDocumentStartChoosesAgainWhenFirstObjectDies(t *testing.T) {
|
||||
text := caretTextReader{webID("/text"): "Alpha", webID("/next"): "Next line"}
|
||||
cursor := newCaretTextCursor(t, text)
|
||||
ctx := context.Background()
|
||||
if _, err := cursor.SyncFocus(ctx, webID("/next")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if move, err := cursor.MoveCaret(ctx, text, CaretNextCharacter); err != nil || move.Position.Offset != 1 {
|
||||
t.Fatalf("setup move = %+v, %v", move, err)
|
||||
}
|
||||
tree := cursor.tree
|
||||
navigator := &deadStartNavigator{readAllCapturer: &readAllCapturer{tree: tree}, caretTextReader: text}
|
||||
navigator.replace = func() {
|
||||
// The provider retires the dead object; the page keeps /next.
|
||||
tree.Invalidate(webID("/text"))
|
||||
snapshot := atspi.NewSnapshot("/doc", "", "document web", "", "")
|
||||
snapshot.BusName = webID("/doc").BusName
|
||||
next := atspi.NewSnapshot("/next", "", "static", "", "")
|
||||
next.BusName = webID("/next").BusName
|
||||
next.CharacterCount = len("Next line")
|
||||
if err := tree.Replace(webID("/doc"), []atspi.TreeNode{{Snapshot: snapshot, Children: []atspi.ObjectID{webID("/next")}}, {Snapshot: next}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
worker, err := NewWorker(navigator, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker.SyncFocus(webID("/next"))
|
||||
result, _ := worker.moveDocumentCaret(ctx, cursor, CaretDocumentStart, 0, 0)
|
||||
if result.Err != nil || !result.Moved || result.DocumentPosition.Object.ID() != webID("/next") || result.DocumentPosition.Offset != 0 {
|
||||
t.Fatalf("document start after dead first object: object=%v offset=%d moved=%v error=%v placements=%v",
|
||||
result.DocumentPosition.Object.ID(), result.DocumentPosition.Offset, result.Moved, result.Err, navigator.placements)
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import "strings"
|
||||
|
||||
const Name = "Cthulhu"
|
||||
|
||||
const Version = "2026.11.28"
|
||||
const Version = "2026.12.01"
|
||||
const Channel = "master"
|
||||
|
||||
var Build = Version
|
||||
|
||||
@@ -16,6 +16,10 @@ const steamNotificationDelay = 500 * time.Millisecond
|
||||
|
||||
var steamRelativeTime = regexp.MustCompile(`(?i)^(?:just now|now|\d+\s+(?:second|minute|hour|day|week|month|year)s?\s+ago)$`)
|
||||
|
||||
// Steam names each Big Picture popup browser "<Name>_uid<browser>", for
|
||||
// example QuickAccess_uid2. The main view is "Steam Big Picture Mode".
|
||||
var steamPopupDocument = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9]*_uid\d+$`)
|
||||
|
||||
var steamShaderProgress = regexp.MustCompile(`^Processing Vulkan shaders \((\d{1,3})%\)$`)
|
||||
|
||||
// ShaderProgress recognizes Steam's English shader status, which Chromium
|
||||
@@ -33,6 +37,53 @@ func ShaderProgress(processName, eventType, role, name string) (float64, bool) {
|
||||
return float64(percentage), err == nil && percentage <= 100
|
||||
}
|
||||
|
||||
// GamepadPopupDocument reports a Steam Big Picture popup, such as Quick Access
|
||||
// or the main menu. Steam drives these with its own arrow-key navigation and
|
||||
// closes them when focus leaves, so browse-mode caret movement dismisses them.
|
||||
func GamepadPopupDocument(processName, documentName string) bool {
|
||||
return MatchProcess(processName) == Steam && steamPopupDocument.MatchString(strings.TrimSpace(documentName))
|
||||
}
|
||||
|
||||
// Steam's Quick Access tab keys, from its client UI. Some tabs, such as
|
||||
// Friends, carry an icon and no aria-label, so their tab has no name.
|
||||
var steamQuickAccessTabs = map[string]string{
|
||||
"quickaccess_tab_0": "Notifications",
|
||||
"quickaccess_tab_1": "Remote Play Together",
|
||||
"quickaccess_tab_2": "Voice Chat",
|
||||
"quickaccess_tab_3": "Friends",
|
||||
"quickaccess_tab_4": "Quick Settings",
|
||||
"quickaccess_tab_5": "Performance",
|
||||
"quickaccess_tab_6": "Help",
|
||||
"quickaccess_tab_7": "Soundtracks",
|
||||
}
|
||||
|
||||
var steamPopupNameWord = regexp.MustCompile(`[A-Z][a-z0-9]*|[a-z0-9]+`)
|
||||
|
||||
// SteamName replaces names Steam leaves internal or empty: a popup document's
|
||||
// browser name ("QuickAccess_uid2" becomes "Quick Access") and an unnamed
|
||||
// Quick Access tab. It returns false when the name should stay as it is.
|
||||
func SteamName(processName, role, name, elementID string) (string, bool) {
|
||||
if MatchProcess(processName) != Steam {
|
||||
return "", false
|
||||
}
|
||||
switch {
|
||||
case role == "document web" && GamepadPopupDocument(processName, name):
|
||||
base, _, _ := strings.Cut(strings.TrimSpace(name), "_uid")
|
||||
return strings.Join(steamPopupNameWord.FindAllString(base, -1), " "), true
|
||||
case role == "page tab" && strings.TrimSpace(name) == "":
|
||||
title, ok := steamQuickAccessTabs[elementID]
|
||||
return title, ok
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// ToastDocument reports Steam's toast popup, named notificationtoasts_uid<n>-<id>
|
||||
// in Big Picture and notificationtoasts_<id>_desktop otherwise. Live regions
|
||||
// elsewhere, such as the store's event calendar, are page content, not toasts.
|
||||
func ToastDocument(documentName string) bool {
|
||||
return strings.HasPrefix(strings.TrimSpace(documentName), "notificationtoasts_")
|
||||
}
|
||||
|
||||
// NotificationRoot mirrors Python's Steam root selection: notification/alert
|
||||
// ancestors take precedence over inherited live-region attributes on a leaf.
|
||||
// Candidates are ordered from the event source towards its application root.
|
||||
|
||||
@@ -145,3 +145,53 @@ func TestSteamNotificationDeduplicationAndOwnership(t *testing.T) {
|
||||
t.Fatalf("reset presented pending content: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGamepadPopupDocument(t *testing.T) {
|
||||
for _, name := range []string{"QuickAccess_uid2", "MainMenu_uid12", " QuickAccess_uid2 "} {
|
||||
if !GamepadPopupDocument("steamwebhelper", name) {
|
||||
t.Errorf("%q was not a Steam popup", name)
|
||||
}
|
||||
}
|
||||
for _, name := range []string{"Steam Big Picture Mode", "Steam", "", "QuickAccess_uid", "Quick Access_uid2"} {
|
||||
if GamepadPopupDocument("steamwebhelper", name) {
|
||||
t.Errorf("%q was treated as a Steam popup", name)
|
||||
}
|
||||
}
|
||||
if GamepadPopupDocument("chrome", "QuickAccess_uid2") {
|
||||
t.Error("another browser's document was treated as a Steam popup")
|
||||
}
|
||||
}
|
||||
|
||||
func TestToastDocument(t *testing.T) {
|
||||
for _, name := range []string{"notificationtoasts_uid2-41", "notificationtoasts_41_desktop"} {
|
||||
if !ToastDocument(name) {
|
||||
t.Errorf("%q was not a toast document", name)
|
||||
}
|
||||
}
|
||||
for _, name := range []string{"Steam Big Picture Mode", "QuickAccess_uid2", ""} {
|
||||
if ToastDocument(name) {
|
||||
t.Errorf("%q was treated as a toast document", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSteamName(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
process, role, name, elementID, want string
|
||||
ok bool
|
||||
}{
|
||||
{"steamwebhelper", "document web", "QuickAccess_uid2", "", "Quick Access", true},
|
||||
{"steamwebhelper", "document web", "MainMenu_uid12", "", "Main Menu", true},
|
||||
{"steamwebhelper", "document web", "Steam Big Picture Mode", "", "", false},
|
||||
{"steamwebhelper", "page tab", "", "quickaccess_tab_3", "Friends", true},
|
||||
{"steamwebhelper", "page tab", "Notifications", "quickaccess_tab_0", "", false},
|
||||
{"steamwebhelper", "page tab", "", "other_tab", "", false},
|
||||
{"chrome", "page tab", "", "quickaccess_tab_3", "", false},
|
||||
{"chrome", "document web", "QuickAccess_uid2", "", "", false},
|
||||
} {
|
||||
got, ok := SteamName(test.process, test.role, test.name, test.elementID)
|
||||
if got != test.want || ok != test.ok {
|
||||
t.Errorf("SteamName(%q, %q, %q, %q) = %q, %v; want %q, %v", test.process, test.role, test.name, test.elementID, got, ok, test.want, test.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user