Progressbar fix.
This commit is contained in:
1 parent
6754c8ef6c
commit
9205e7280a
10 files changed
+266
-3
No files matched your search
@@ -6,6 +6,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
@@ -15,6 +16,73 @@ import (
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
)
|
||||
|
||||
func TestSteamShaderProgressUsesSharedOutputAndGates(t *testing.T) {
|
||||
for _, step := range []struct {
|
||||
name, mode string
|
||||
background, reportBackground bool
|
||||
hidden, defunct, locked, stale bool
|
||||
wantHandled, wantBeep, wantSpeech bool
|
||||
}{
|
||||
{name: "beep", mode: "beep", wantHandled: true, wantBeep: true},
|
||||
{name: "speak", mode: "speak", wantHandled: true, wantSpeech: true},
|
||||
{name: "both", mode: "both", wantHandled: true, wantBeep: true, wantSpeech: true},
|
||||
{name: "off", mode: "off"},
|
||||
{name: "background suppressed", mode: "both", background: true, wantHandled: true},
|
||||
{name: "background enabled", mode: "both", background: true, reportBackground: true, wantHandled: true, wantBeep: true, wantSpeech: true},
|
||||
{name: "hidden", mode: "both", hidden: true},
|
||||
{name: "defunct", mode: "both", defunct: true},
|
||||
{name: "secure", mode: "both", locked: true, wantHandled: true},
|
||||
{name: "stale", mode: "both", stale: true, wantHandled: true},
|
||||
} {
|
||||
t.Run(step.name, func(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.ProgressBar.OutputMode = step.mode
|
||||
settings.ProgressBar.ReportBackground = step.reportBackground
|
||||
live := &liveSettings{}
|
||||
live.Store(settings)
|
||||
speech := &fakeSpeechQueue{spoken: make(chan string, 8), requests: make(chan speechRequest, 8)}
|
||||
frames := frameRecorder{frames: make(chan braille.Frame, 8)}
|
||||
state := &eventLoopState{}
|
||||
state.current = atspi.Snapshot{BusName: ":1.1", Path: "/button", Role: "button"}
|
||||
before := state.current
|
||||
gate := &focusGate{}
|
||||
gate.secure.Store(step.locked)
|
||||
handler := &accessibilityEventHandler{state: state, live: live, speech: speech, focusGate: gate, brailleOutput: frames}
|
||||
event := atspi.NewEvent(atspi.AccessibleNameEvent, atspi.Snapshot{BusName: ":1.1", Path: "/shader-status", Role: "static",
|
||||
ApplicationProcess: "steamwebhelper", StatesKnown: true, Visible: true, Showing: !step.hidden, Defunct: step.defunct})
|
||||
event.ForegroundMismatch = step.background
|
||||
if step.stale {
|
||||
handler.foreground = &titleProbeSource{}
|
||||
state.foregroundState.Epoch = 1
|
||||
}
|
||||
for _, percentage := range []int{18, 18, 19, 100} {
|
||||
event.Source.Name = fmt.Sprintf("Processing Vulkan shaders (%d%%)", percentage)
|
||||
if handled := handler.handle_progress_bar(event); handled != step.wantHandled {
|
||||
t.Fatalf("handled=%t, want %t", handled, step.wantHandled)
|
||||
}
|
||||
}
|
||||
wantCount := 0
|
||||
if step.wantBeep {
|
||||
wantCount = 3
|
||||
} else if step.wantSpeech {
|
||||
wantCount = 2
|
||||
}
|
||||
if len(speech.requests) != wantCount {
|
||||
t.Fatalf("got %d requests, want %d", len(speech.requests), wantCount)
|
||||
}
|
||||
if wantCount > 0 {
|
||||
request := <-speech.requests
|
||||
if !request.Append || (len(request.Sound) == 1) != step.wantBeep || (request.Text == "18 percent") != step.wantSpeech {
|
||||
t.Fatalf("shader output: %+v", request)
|
||||
}
|
||||
}
|
||||
if state.current.ID() != before.ID() || state.focusedID.Valid() || len(frames.frames) != 0 {
|
||||
t.Fatal("shader progress changed focus or unrelated braille")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressSecureEpochAndBrailleGates(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.ProgressBar.ReportBackground = true
|
||||
|
||||
Reference in new issue
Block a user