Some browser fixes for reliability.

This commit is contained in:
Storm Dragon committed 2026-11-13 22:49:10 -05:00
1 parent d95dc2d00d
commit 679d81a804
10 files changed
+287 -23

No files matched your search

+21
View File
@@ -10,6 +10,21 @@ focus and typing events, leaving browse-mode grabs active. Window ancestry now
resolves the enclosing frame, including nested frames in the same provider. resolves the enclosing frame, including nested frames in the same provider.
Separate application windows still undergo the existing foreground checks. Separate application windows still undergo the existing foreground checks.
## Firefox focus and delayed labels
Firefox can expose a newly created Find entry before localization supplies its
name. libatspi can retain that empty name after Firefox has the label. On focus,
Cthulhu refreshes only an unnamed editable Gecko entry's own cache. If it is
still unnamed, the existing GLib timer checks for its label for at most 350 ms.
The update uses the provider's label and normal name-change presentation.
It stops on focus loss, a different focus, window/secure ownership changes,
defunct state, or expiry; password fields and other toolkits are excluded.
The native Find test also drains delayed speech around address-bar setup and
return from Find. Previously, a queued heading announcement could satisfy setup
while native focus was still in the address bar or moving to another control.
Find label, typing, caret and heading-command assertions remain intact.
## Automated checks ## Automated checks
```sh ```sh
@@ -25,6 +40,12 @@ entry speech, browse-key release, typing a structural-navigation letter,
Tab/Shift+Tab, Escape, restored caret/heading commands and reopening Find. Tab/Shift+Tab, Escape, restored caret/heading commands and reopening Find.
It records requests without producing audible speech. It records requests without producing audible speech.
On 2026-11-13, the unchanged Firefox Find assertions passed 30 consecutive
fresh-profile runs with the bounded recovery and synchronized setup (the
baseline failed 4 of 10 runs). Firefox baseline/tab checks, the AT-SPI, app and
review package tests, and AT-SPI/app `go vet` also passed. This is repeat-run
reliability evidence, not a guarantee against all browser/provider failures.
## Live acceptance ## Live acceptance
With a rebuilt reader, check Brave and Firefox separately: With a rebuilt reader, check Brave and Firefox separately:
+25 -13
View File
@@ -137,9 +137,31 @@ func TestNativeBrowserFind(t *testing.T) {
} }
} }
} }
// Drain delayed focus speech at setup/transition boundaries so a previous
// heading cannot satisfy the next step while native focus is elsewhere.
settleSpeech := func() {
t.Helper()
quiet := time.NewTimer(200 * time.Millisecond)
defer quiet.Stop()
for {
select {
case <-output.speech:
quiet.Reset(200 * time.Millisecond)
case <-quiet.C:
return
case <-ctx.Done():
t.Fatal(ctx.Err())
}
}
}
// A focusable heading gives both browser families a known browse-mode start. // A focusable heading gives both browser families a known browse-mode start.
key("ctrl+l") key("ctrl+l")
if os.Getenv("CTHULHU_NATIVE_FIREFOX") == "1" {
waitSpeech("", "combo box")
}
settleSpeech()
key("Escape") key("Escape")
settleSpeech()
heading := false heading := false
for attempt := 0; attempt < 25 && !heading; attempt++ { for attempt := 0; attempt < 25 && !heading; attempt++ {
key("Tab") key("Tab")
@@ -163,6 +185,7 @@ func TestNativeBrowserFind(t *testing.T) {
if !heading { if !heading {
t.Fatal("fixture heading focus missing") t.Fatal("fixture heading focus missing")
} }
settleSpeech()
for !commands.BrowseNavigationEnabled() { for !commands.BrowseNavigationEnabled() {
select { select {
case <-time.After(5 * time.Millisecond): case <-time.After(5 * time.Millisecond):
@@ -174,19 +197,7 @@ func TestNativeBrowserFind(t *testing.T) {
waitStart() waitStart()
// Wait for the native caret/focus echoes of navigation before opening // Wait for the native caret/focus echoes of navigation before opening
// browser chrome. They must not satisfy the Find field assertion. // browser chrome. They must not satisfy the Find field assertion.
quiet := time.NewTimer(200 * time.Millisecond) settleSpeech()
defer quiet.Stop()
settle:
for {
select {
case <-output.speech:
quiet.Reset(200 * time.Millisecond)
case <-quiet.C:
break settle
case <-ctx.Done():
t.Fatal(ctx.Err())
}
}
key("ctrl+f") key("ctrl+f")
waitSpeech("Find", "entry") waitSpeech("Find", "entry")
for commands.BrowseNavigationEnabled() { for commands.BrowseNavigationEnabled() {
@@ -203,6 +214,7 @@ settle:
key("shift+Tab") key("shift+Tab")
waitSpeech("Find", "entry") waitSpeech("Find", "entry")
key("Escape") key("Escape")
settleSpeech()
for !commands.BrowseNavigationEnabled() { for !commands.BrowseNavigationEnabled() {
select { select {
case <-time.After(5 * time.Millisecond): case <-time.After(5 * time.Millisecond):
@@ -11,6 +11,7 @@ import (
"net/http/httptest" "net/http/httptest"
"os" "os"
"os/exec" "os/exec"
"strings"
"testing" "testing"
"time" "time"
@@ -133,17 +134,58 @@ document.addEventListener('keydown', event => {
return review.Result{} return review.Result{}
} }
} }
if generated {
// The inline link now shares its paragraph's visual line. Move by
// word to retain a caret in the generated text while it is replaced.
move(review.CaretNextLine, "Published ↺ by Publisher some hours ago. Article continues")
move(review.CaretNextWord, "Published")
old := move(review.CaretNextWord, "↺").DocumentPosition.Object
move(review.CaretNextWord, "by")
for {
tree, err := adapter.CaptureDocument(ctx, document)
if err != nil {
t.Fatal(err)
}
if _, err := tree.Resolve(old); err != nil {
break
}
select {
case <-adapter.Events():
case <-ctx.Done():
t.Fatal("native generated-link object was not replaced: ", ctx.Err())
}
}
move(review.CaretPreviousWord, "by")
current := move(review.CaretPreviousWord, "↺")
if current.DocumentPosition.Object == old {
t.Fatal("backward word navigation retained the replaced generated text")
}
if err := worker.ReadAll(ctx); err != nil {
t.Fatal(err)
}
select {
case result := <-worker.Results():
if result.Err != nil || len(result.ReadAllLines) != 1 {
t.Fatalf("Read All after generated-link replacement: err=%v lines=%d", result.Err, len(result.ReadAllLines))
}
var text strings.Builder
for _, part := range result.ReadAllLines[0].Contents {
text.WriteString(part.RawText)
}
if got, want := text.String(), "↺ by Publisher some hours ago. Article continues"; got != want {
t.Fatalf("Read All after generated-link replacement: %q, want %q", got, want)
}
case <-ctx.Done():
t.Fatal(ctx.Err())
}
return
}
move(review.CaretNextLine, "Published") move(review.CaretNextLine, "Published")
attribution, after := "↺ by Publisher", "Article continues" attribution, after := "↺ by Publisher", "Article continues"
if generated {
attribution, after = "↺ by Publisher some hours ago", ". Article continues"
}
current := move(review.CaretNextLine, attribution) current := move(review.CaretNextLine, attribution)
for generation := 0; generation < 4; generation++ { for generation := 0; generation < 4; generation++ {
old := current.DocumentPosition.Object old := current.DocumentPosition.Object
if !generated { command("key", "--clearmodifiers", "F8")
command("key", "--clearmodifiers", "F8")
}
// Require a genuinely replaced native static-text object. Merely // Require a genuinely replaced native static-text object. Merely
// changing a label would not exercise recovery of a missing cursor. // changing a label would not exercise recovery of a missing cursor.
for { for {
+4 -3
View File
@@ -127,9 +127,10 @@ type Adapter struct {
foregroundChanges chan struct{} foregroundChanges chan struct{}
foregroundTitle atomic.Pointer[ForegroundTitle] foregroundTitle atomic.Pointer[ForegroundTitle]
titleChanges chan struct{} titleChanges chan struct{}
foregroundWindow ObjectID // GLib thread: correlated accessible for current X client foregroundWindow ObjectID // GLib thread: correlated accessible for current X client
promptRefreshWindow ObjectID // GLib thread: frame activated before its prompt label appeared entryNameRefresh pendingEntryName // GLib thread: delayed Gecko entry localization
promptScannedWindow ObjectID // GLib thread: avoid rescanning repeated activations promptRefreshWindow ObjectID // GLib thread: frame activated before its prompt label appeared
promptScannedWindow ObjectID // GLib thread: avoid rescanning repeated activations
promptScannedEpoch uint64 promptScannedEpoch uint64
foregroundRecovery int // GLib thread: bounded retries while a new client publishes AT-SPI foregroundRecovery int // GLib thread: bounded retries while a new client publishes AT-SPI
recoveringForeground bool recoveringForeground bool
@@ -128,6 +128,22 @@ func (adapter *Adapter) captureNativeEventSnapshot(event *C.AtspiEvent, target *
C.g_object_unref(C.gpointer(editor)) C.g_object_unref(C.gpointer(editor))
} }
} }
// Gecko can cache the empty name of a newly created Find entry before
// localization supplies its label. Refresh only unnamed editable entries
// gaining focus, and only this object's cache; never guess a Find label.
if snapshot.Role == "entry" && snapshot.Editable && snapshot.Name == "" &&
(eventType == FocusEvent || eventType == FocusedStateEvent && C.cthulhu_event_detail1(event) != 0) {
toolkit := C.atspi_accessible_get_toolkit_name(target, nil)
snapshot.ToolkitName = sanitizeSnapshotField(C.GoString(toolkit))
gecko := strings.EqualFold(snapshot.ToolkitName, "Gecko")
C.g_free(C.gpointer(toolkit))
if gecko {
C.atspi_accessible_clear_cache_single(target)
name := C.atspi_accessible_get_name(target, nil)
snapshot.Name = sanitizeSnapshotField(C.GoString(name))
C.g_free(C.gpointer(name))
}
}
snapshot.ApplicationProcess = adapter.applicationProcess(target) snapshot.ApplicationProcess = adapter.applicationProcess(target)
if snapshot.Role == "slider" || if snapshot.Role == "slider" ||
snapshot.Role == "combo box" && (snapshot.Name == "Key echo speech synthesizer" || snapshot.Name == "Key echo person") { snapshot.Role == "combo box" && (snapshot.Name == "Key echo speech synthesizer" || snapshot.Name == "Key echo person") {
@@ -650,5 +666,6 @@ func dispatch_native_event(event *C.AtspiEvent, userData unsafe.Pointer, deferre
C.g_object_unref(C.gpointer(target)) C.g_object_unref(C.gpointer(target))
} }
adapter.entryNameRefresh.observe(focusEvent, adapter.Foreground().Epoch, secureEpoch, time.Now())
adapter.enqueueSecureEvent(focusEvent, secureEpoch) adapter.enqueueSecureEvent(focusEvent, secureEpoch)
} }
@@ -60,6 +60,7 @@ func cthulhuAtspiForegroundCallback(data unsafe.Pointer) {
adapter.foregroundRecovery = 8 adapter.foregroundRecovery = 8
} }
adapter.recoverForeground() adapter.recoverForeground()
adapter.refresh_entry_name()
} }
func (adapter *Adapter) matchesForeground(source, window *C.AtspiAccessible, id ObjectID) bool { func (adapter *Adapter) matchesForeground(source, window *C.AtspiAccessible, id ObjectID) bool {
+38
View File
@@ -0,0 +1,38 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package atspi
import (
"strings"
"time"
)
// Only owned event data is retained; native references remain in nativeFocus.
type pendingEntryName struct {
event Event
deadline time.Time
foregroundEpoch, secureEpoch uint64
}
func (pending *pendingEntryName) observe(event Event, foregroundEpoch, secureEpoch uint64, now time.Time) {
focusGain := event.Type == FocusEvent || event.Type == FocusedStateEvent && event.Detail1 != 0
if pending.event.Source.ID().Valid() && ((focusGain && event.Source.ID() != pending.event.Source.ID()) ||
(event.Source.ID() == pending.event.Source.ID() && (event.Source.Name != "" || event.Source.Defunct ||
event.Type == FocusedStateEvent && event.Detail1 == 0)) ||
event.Type == WindowDeactivatedEvent || event.Type == WindowDestroyedEvent) {
*pending = pendingEntryName{}
}
if !focusGain || event.ForegroundMismatch || event.Source.Defunct || event.Source.Name != "" ||
event.Source.Role != "entry" || !event.Source.Editable || !event.Source.ID().Valid() ||
!strings.EqualFold(event.Source.ToolkitName, "Gecko") || pending.event.Source.ID().Valid() {
return
}
*pending = pendingEntryName{event: event, deadline: now.Add(350 * time.Millisecond), foregroundEpoch: foregroundEpoch, secureEpoch: secureEpoch}
}
func (pending pendingEntryName) current(focus ObjectID, foregroundEpoch, secureEpoch uint64, now time.Time) bool {
return focus.Valid() && focus == pending.event.Source.ID() && now.Before(pending.deadline) &&
foregroundEpoch == pending.foregroundEpoch && secureEpoch == pending.secureEpoch
}
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package atspi
/*
#include "adapter_native.h"
*/
import "C"
import "time"
// Called by the existing GLib timer. Never sleep in the event callback or
// retain a separate native object; stop on focus, foreground or secure changes.
func (adapter *Adapter) refresh_entry_name() {
pending := &adapter.entryNameRefresh
if !pending.event.Source.ID().Valid() {
return
}
if len(adapter.nativeFocus) == 0 {
*pending = pendingEntryName{}
return
}
focus := adapter.nativeFocus[len(adapter.nativeFocus)-1]
if !pending.current(focus.id, adapter.Foreground().Epoch, adapter.secureEpoch.Load(), time.Now()) {
*pending = pendingEntryName{}
return
}
C.atspi_accessible_clear_cache_single(focus.source)
snapshot := snapshotFromNativeWithCaret(focus.source, true, false, false, adapter.captureSound.Load(), adapter.captureTextAttributes.Load())
if snapshot.Defunct || !snapshot.Focused || snapshot.Role != "entry" || !snapshot.Editable {
*pending = pendingEntryName{}
return
}
if snapshot.Name == "" {
return
}
if !adapter.nativeFocusIs(focus.id) || !pending.current(focus.id, adapter.Foreground().Epoch, adapter.secureEpoch.Load(), time.Now()) {
*pending = pendingEntryName{}
return
}
event, secureEpoch := pending.event, pending.secureEpoch
*pending = pendingEntryName{}
event.Type = AccessibleNameEvent
snapshot.ToolkitName = event.Source.ToolkitName
snapshot.ApplicationProcess = event.Source.ApplicationProcess
event.Source = snapshot
adapter.enqueueSecureEvent(event, secureEpoch)
}
+82
View File
@@ -0,0 +1,82 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package atspi
import (
"testing"
"time"
)
func TestDelayedEntryNameOwnership(t *testing.T) {
now := time.Now()
source := Snapshot{BusName: ":1.42", Path: "/entry", Role: "entry", Editable: true, ToolkitName: "Gecko"}
event := NewEventWithPayload(FocusEvent, source, "")
var pending pendingEntryName
pending.observe(event, 1, 2, now)
if !pending.current(source.ID(), 1, 2, now.Add(50*time.Millisecond)) {
t.Fatal("unnamed Gecko entry did not schedule a refresh")
}
// Duplicate focus must not extend the bounded query window.
pending.observe(event, 1, 2, now.Add(300*time.Millisecond))
if pending.current(source.ID(), 1, 2, now.Add(350*time.Millisecond)) {
t.Fatal("duplicate focus extended the deadline")
}
if pending.current(NewObjectID(":1.42", "/other"), 1, 2, now) ||
pending.current(source.ID(), 3, 2, now) || pending.current(source.ID(), 1, 3, now) {
t.Fatal("refresh survived an ownership change")
}
for _, kind := range []string{"focus elsewhere", "focus loss", "label arrived", "destroyed", "window deactivated"} {
t.Run(kind, func(t *testing.T) {
candidate := pending
next := event
switch kind {
case "focus elsewhere":
next.Source.Path = "/other"
case "focus loss":
next.Type = FocusedStateEvent
case "label arrived":
next.Type = AccessibleNameEvent
next.Source.Name = "Find in page"
case "destroyed":
next.Type = DefunctStateEvent
next.Source.Defunct = true
case "window deactivated":
next.Type = WindowDeactivatedEvent
}
candidate.observe(next, 1, 2, now)
if candidate.current(source.ID(), 1, 2, now) {
t.Fatal("stale refresh retained")
}
})
}
}
func TestDelayedEntryNameScope(t *testing.T) {
for _, kind := range []string{"named", "other toolkit", "password", "readonly", "background", "defunct"} {
t.Run(kind, func(t *testing.T) {
source := Snapshot{BusName: ":1.42", Path: "/entry", Role: "entry", Editable: true, ToolkitName: "Gecko"}
event := NewEventWithPayload(FocusEvent, source, "")
switch kind {
case "named":
event.Source.Name = "Search"
case "other toolkit":
event.Source.ToolkitName = "gtk"
case "password":
event.Source.Role = "password text"
case "readonly":
event.Source.Editable = false
case "background":
event.ForegroundMismatch = true
case "defunct":
event.Source.Defunct = true
}
var pending pendingEntryName
pending.observe(event, 1, 2, time.Now())
if pending.event.Source.ID().Valid() {
t.Fatal("unrelated entry scheduled a refresh")
}
})
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ import "strings"
const Name = "Cthulhu" const Name = "Cthulhu"
const Version = "2026.11.11" const Version = "2026.11.13"
const Channel = "testing" const Channel = "testing"
var Build = Version var Build = Version