The test was wrong, not the panel. It required the quick panel to be key
after Focus, but on this Mac (macOS 26.2 25C56, no input for ~30 min,
frontmost app kitty) macOS makes no non-activating panel key for an app
that isn't active when nothing the user did is behind it. That held at
e5d4c4929, the test's own commit, as well as on main, so there is no
regression to bisect. A control panel shows it: a plain NSPanel, titled +
NonactivatingPanel (canBecomeKeyWindow YES), ordered front and made key
the same way in the same child, isn't key either.
Now the test always checks that the panel can be made key
(canBecomeKeyWindow, which a borderless window has only through Wails'
panel class). It checks that the panel is key only when the session makes
the control panel key, and otherwise prints that it skipped that check.
Its other checks are unchanged: it joins full-screen Spaces, doesn't
activate, keeps the frontmost app, and hides.
Broken by hand, both ways:
- canBeKey returning 0 fails with "the panel can't be made key, so it never
takes the keyboard".
- sessionKeysPanels returning 1 (which says the session gives key status)
fails with "the panel shown doesn't take the keyboard", the old red.
Not tried: a real click on the menu bar icon with someone at the Mac.
That click is input, so a session at the Mac should run the key check
fully rather than skip it.
Run:
- go test ./internal/gui -run TestPanelJoinsFullScreenSpaces: ok, with
the skip line printed.
- gofmt -l: clean.
- go vet -tags nogui ./... with GOOS=darwin, linux and windows: ok.
- go vet ./internal/gui (cgo): ok.
Full suite: set -o pipefail; go test -timeout 45m ./... (sandbox HOME, macOS 26.2, load ~150 from other suites): 66 ok, 18 no test files, 0 FAIL; gateway 2712s, agent 2553s, gui 419s.
108 lines
4.3 KiB
Go
108 lines
4.3 KiB
Go
//go:build darwin && cgo && !nogui
|
|
|
|
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
"github.com/wailsapp/wails/v3/pkg/events"
|
|
)
|
|
|
|
// #2141: with Chrome full screen, a click on the menu bar icon showed the
|
|
// quick panel on the desktop Space it was first shown on, out of sight. A
|
|
// test can't make a full-screen Space, so it checks what decides it on the
|
|
// real window: the panel, made at start and made again after lightweight
|
|
// mode let it go, is on every Space and over a full-screen app's, and is
|
|
// shown and hidden with that set, without activating magpie (activated,
|
|
// the Mac took the user to the Space of magpie's other windows).
|
|
func TestPanelJoinsFullScreenSpaces(t *testing.T) {
|
|
out, err := runAppKit(t, 30*time.Second, []string{"MAGPIE_TEST_PANEL_SPACE=1"})
|
|
if err != nil || !strings.Contains(string(out), "panel space: ok") {
|
|
t.Fatalf("panel space: %v\n%s", err, out)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
if os.Getenv("MAGPIE_TEST_PANEL_SPACE") != "1" {
|
|
return
|
|
}
|
|
app := application.New(application.Options{
|
|
Name: "magpie panel space regression",
|
|
Mac: application.MacOptions{ActivationPolicy: application.ActivationPolicyAccessory},
|
|
Assets: application.AssetOptions{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
fmt.Fprint(w, `<p>magpie</p>`)
|
|
})},
|
|
})
|
|
h := &host{app: app}
|
|
fail := func(format string, a ...any) {
|
|
fmt.Printf("panel space: "+format+"\n", a...)
|
|
os.Exit(1)
|
|
}
|
|
waitFor := func(what string, ok func() bool) {
|
|
for deadline := time.Now().Add(5 * time.Second); !ok(); time.Sleep(20 * time.Millisecond) {
|
|
if time.Now().After(deadline) {
|
|
fail("timed out waiting until %s", what)
|
|
}
|
|
}
|
|
}
|
|
check := func(how string) {
|
|
var w *application.WebviewWindow
|
|
application.InvokeSync(func() { w, _ = h.panelWin() })
|
|
if !application.InvokeSyncWithResult(func() bool { return joinsFullScreenSpaces(w) }) {
|
|
fail("%s: the panel isn't on every Space and over full-screen ones", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return nonActivating(w) }) {
|
|
fail("%s: the panel isn't a non-activating panel", how)
|
|
}
|
|
if application.InvokeSyncWithResult(appFrontmost) {
|
|
fail("%s: magpie is frontmost before the icon is clicked; the test can't tell", how)
|
|
}
|
|
application.InvokeSync(func() { w.Show().Focus() }) // the icon clicked
|
|
waitFor(how+": the panel shows", func() bool { return application.InvokeSyncWithResult(func() bool { return windowOpen(w) }) })
|
|
// activation is asked for and comes a moment later: give it time
|
|
time.Sleep(500 * time.Millisecond)
|
|
if application.InvokeSyncWithResult(appFrontmost) {
|
|
fail("%s: showing the panel brought magpie to the front, which takes the user to the Space of its other windows", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return canBeKey(w) }) {
|
|
fail("%s: the panel can't be made key, so it never takes the keyboard", how)
|
|
}
|
|
// Whether it is key is up to the session too: on a Mac no one was
|
|
// at, macOS 26.2 made no non-activating panel of an app that isn't
|
|
// active key, a plain titled one either (#2450). A click on the
|
|
// icon is input, which this test can't make, so where a plain one
|
|
// isn't made key the check can't tell.
|
|
if !application.InvokeSyncWithResult(w.IsFocused) {
|
|
if application.InvokeSyncWithResult(sessionKeysPanels) {
|
|
fail("%s: the panel shown doesn't take the keyboard", how)
|
|
}
|
|
fmt.Printf("panel space: %s: not checked that it takes the keyboard: this session makes no non-activating panel key\n", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return joinsFullScreenSpaces(w) }) {
|
|
fail("%s: showing the panel took it off full-screen Spaces", how)
|
|
}
|
|
application.InvokeSync(func() { w.Hide() })
|
|
waitFor(how+": the panel hides", func() bool { return !application.InvokeSyncWithResult(func() bool { return windowOpen(w) }) })
|
|
}
|
|
app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) {
|
|
go func() {
|
|
check("made at start")
|
|
application.InvokeSync(func() { h.panel = nil }) // lightweight mode let it go
|
|
check("made again")
|
|
fmt.Println("panel space: ok")
|
|
app.Quit()
|
|
}()
|
|
})
|
|
if err := app.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
os.Exit(0)
|
|
}
|