A few touch ups.
This commit is contained in:
1 parent
210e949f76
commit
105d6de46e
6 files changed
+209
-20
No files matched your search
+20
-6
@@ -105,9 +105,23 @@ aria-label (Friends) are named from their `quickaccess_tab_<n>` id.
|
||||
|
||||
When Steam replaces page content, the remembered native focus can die before
|
||||
any navigation adopts it (its loading spinner after a popup closes). The review
|
||||
worker then recaptures through the most recent retained document of the same
|
||||
provider and keeps that document's reading place, instead of failing with
|
||||
"Could not find current location". Document start and end choose again once
|
||||
if their target died before placement. Verified live on 2026-12-01 in Steam
|
||||
and ChatGPT; covered by `TestDeadFocusNeverSavedRecoversThroughRetainedDocument`
|
||||
and `TestDocumentStartChoosesAgainWhenFirstObjectDies`.
|
||||
worker first recaptures the current document and keeps its reading place,
|
||||
including the caret offset. Only if that document is confirmed missing may
|
||||
it try another retained document of the same provider, within a two-document
|
||||
limit. Timeouts, stale captures and other refresh failures do not switch
|
||||
documents. This avoids navigating an older page when the current page merely
|
||||
removed a temporary focused object. Document start and end choose again once
|
||||
if their target died before placement. Automated checks cover recovery in the
|
||||
current document, caret-offset retention, failed refreshes, popup disappearance
|
||||
and document-start retries. The original popup recovery and start retry were
|
||||
checked live in Steam and ChatGPT on 2026-12-01; the current-document preference
|
||||
still needs live acceptance.
|
||||
|
||||
The `web-widgets` browser proof checks the narrow native-focus context's
|
||||
summary tag and the unnamed tab's ID on its focus event, as well as full
|
||||
document traits. Run it with
|
||||
`CTHULHU_NATIVE_BROWSER_TESTS=web-widgets python3 tests/native_browser.py`.
|
||||
These metadata checks do not establish audible tab naming in the live Steam
|
||||
client. After building, check F2, move to Friends, and confirm its name is
|
||||
spoken; close the popup and verify browse navigation resumes at the saved
|
||||
place in the main view.
|
||||
@@ -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 ||
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/webscripts"
|
||||
)
|
||||
|
||||
// Records how the browser exposes the widgets behind three web mode and
|
||||
@@ -29,8 +31,8 @@ func TestNativeBrowserWebWidgetTraits(t *testing.T) {
|
||||
if _, err := adapter.CaptureDesktop(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Browse mode decides from document captures, which carry HTML tags.
|
||||
// Anchor the capture on the page's own focused button.
|
||||
// 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)
|
||||
}
|
||||
@@ -45,6 +47,13 @@ func TestNativeBrowserWebWidgetTraits(t *testing.T) {
|
||||
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)
|
||||
@@ -78,4 +87,30 @@ func TestNativeBrowserWebWidgetTraits(t *testing.T) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,13 +205,22 @@ 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 most recently used retained documents of the same provider;
|
||||
// the first one that still exists becomes the anchor. A live focus never gets
|
||||
// here: capture keyed on it succeeds or fails with another error.
|
||||
// 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 worker.retainedCursorsExcept(current, loadEpoch) {
|
||||
for _, retained := range candidates {
|
||||
document, ok := retained.savedDocument()
|
||||
if !ok || document.BusName != focus.BusName || document == focus {
|
||||
continue
|
||||
@@ -228,6 +237,9 @@ func (worker *Worker) captureRetainedDocumentForDeadFocus(ctx context.Context, c
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1476,6 +1476,123 @@ func TestDeadFocusNeverSavedRecoversThroughRetainedDocument(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -1491,9 +1608,12 @@ func TestDeadFocusRecoveryStaysOnProviderBus(t *testing.T) {
|
||||
}
|
||||
worker.rememberDocumentCursor(cursorB, 0)
|
||||
other := atspi.NewObjectID(":9.9", "/spinner")
|
||||
if _, _, _, ok := worker.captureRetainedDocumentForDeadFocus(context.Background(), nil, other, 0); ok {
|
||||
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 {
|
||||
|
||||
@@ -15,4 +15,7 @@
|
||||
<div role="treeitem" aria-label="Unchecked option" aria-checked="false" aria-selected="false" tabindex="-1">Unchecked option</div>
|
||||
<div role="treeitem" aria-label="Plain option" aria-selected="false" tabindex="-1">Plain option</div>
|
||||
</div>
|
||||
<div role="tablist">
|
||||
<button role="tab" id="quickaccess_tab_3" aria-selected="true"></button>
|
||||
</div>
|
||||
</html>
|
||||
Reference in new issue
Block a user