62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.stormux.org/storm/cthulhu/internal/atspi"
|
|
"git.stormux.org/storm/cthulhu/internal/config"
|
|
)
|
|
|
|
func TestAcceptedApplicationFocusPublishesSettingsIdentity(t *testing.T) {
|
|
adapter := &fakeAdapter{events: make(chan atspi.Event, 4)}
|
|
speech := &fakeSpeechQueue{spoken: make(chan string, 4)}
|
|
applications := make(chan string, 4)
|
|
live := &liveSettings{onApplication: func(name string) { applications <- name }}
|
|
live.Store(config.DefaultSettings())
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan struct{})
|
|
go func() {
|
|
_ = processEventsWithInput(ctx, slog.New(slog.DiscardHandler), speech, adapter, nil, nil, 0, live, nil, nil, nil)
|
|
close(done)
|
|
}()
|
|
defer func() { cancel(); <-done }()
|
|
frame := atspi.NewSnapshot("/first/window", "First", "frame", "", "")
|
|
frame.BusName, frame.ApplicationName = ":1.41", "First Editor"
|
|
activated := atspi.NewEvent(atspi.WindowActivatedEvent, frame)
|
|
activated.Window = frame.ID()
|
|
adapter.events <- activated
|
|
select {
|
|
case name := <-applications:
|
|
if name != "First Editor" {
|
|
t.Fatalf("application = %q", name)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("accepted window did not publish application")
|
|
}
|
|
background := atspi.NewSnapshot("/background/window", "Background", "frame", "", "")
|
|
background.BusName, background.ApplicationName = ":1.42", "Background Editor"
|
|
ignored := atspi.NewEvent(atspi.FocusedStateEvent, background)
|
|
ignored.Window, ignored.Detail1 = background.ID(), 1
|
|
adapter.events <- ignored
|
|
select {
|
|
case name := <-applications:
|
|
t.Fatalf("background focus published %q", name)
|
|
case <-time.After(30 * time.Millisecond):
|
|
}
|
|
background.Focused = true
|
|
focused := atspi.NewEvent(atspi.FocusedStateEvent, background)
|
|
focused.Window, focused.Detail1 = background.ID(), 1
|
|
adapter.events <- focused
|
|
select {
|
|
case name := <-applications:
|
|
if name != "Background Editor" {
|
|
t.Fatalf("foreground application = %q", name)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("accepted focus did not publish new application")
|
|
}
|
|
}
|