From e0ee9265efa6c07e6fed45c39aefe4bef6ca4de6 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 5 Nov 2026 01:37:26 +0800 Subject: [PATCH] gui: TestClosingWindowMarksPageOutOfSight reads hidden as app.js does and waits for the page (#4924) The test page read document.hidden from WebKit, which app.js never does: app.js makes hidden and visibilityState follow magpie's signal (#4293). WebKit turns an ordered-out window's document.hidden on in its own time and fires no visibilitychange of its own, so the page recorded the hiding only if WebKit's value was already true when magpie's signal (an async ExecJS after orderOut) arrived. When it wasn't, nothing was recorded, the window was shown again after a fixed 500ms, and the host waited 8s for a report that could never come: "timed out waiting for the page's hidden report", as on macOS CI at 4a9cfb52e and in a full run on mote. A probe on mote showed WebKit reporting hidden=true for this page from the start, before the window was ever ordered out, so there the old test passed on WebKit's value, not on magpie's signal. The page now overrides hidden and visibilityState the way app.js does, and says when it has seen itself hidden; the window is shown again only after that (a wait on state, 15s bound), not after a fixed pause. The runAppKit bound is 2 minutes to cover its waits. app.js is unchanged. Run on mote (macOS) at this tree: - Injected WebKit reporting visible when the signal arrives (hidden and visibilityState pinned to visible in the page): old test red on both tests with "timed out waiting for the page's hidden report"; new test green. - hideWebview's signal broken by hand (pageHiddenJSOn returns ""): new test red on both, "timed out waiting for the page to see itself hidden". - No injection: green, -count=3. - go vet ./internal/gui: ok; gofmt -l: clean. - go test -count=1 ./internal/gui: only TestMainWindowCorners red, the separate #3949, which #4924's body names as well. Not tried: a 1.5s busy page or a 300ms-late orderOut as the injection; neither turned the old test red on mote, since WebKit says hidden there throughout. A CI macOS runner itself. --- internal/gui/window_visibility_darwin_test.go | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/gui/window_visibility_darwin_test.go b/internal/gui/window_visibility_darwin_test.go index 515f8e4ae..fb7cc14d6 100644 --- a/internal/gui/window_visibility_darwin_test.go +++ b/internal/gui/window_visibility_darwin_test.go @@ -20,8 +20,16 @@ import ( // says otherwise. The page here records what it saw as it was hidden, and // reports that record once it is shown again; without hideWebview's signal // it remains a visible page with running animations. +// +// The page reads document.hidden as app.js does, from magpie's signal. +// WebKit does turn an ordered-out window's document.hidden on, but in its +// own time and without a visibilitychange of its own, so a page reading +// WebKit's value saw itself visible whenever magpie's signal arrived first, +// recorded nothing, and the window was shown again after a fixed pause with +// nothing to report (#4924). The window is now shown again only once the +// page has said it saw itself hidden. func TestClosingWindowMarksPageOutOfSight(t *testing.T) { - out, err := runAppKit(t, 30*time.Second, []string{"MAGPIE_TEST_WINDOW_VISIBILITY=1"}) + out, err := runAppKit(t, 2*time.Minute, []string{"MAGPIE_TEST_WINDOW_VISIBILITY=1"}) if err != nil || !strings.Contains(string(out), "window visibility: ok") { t.Fatalf("window visibility: %v\n%s", err, out) } @@ -33,7 +41,7 @@ func TestClosingWindowMarksPageOutOfSight(t *testing.T) { // told it is back and keeps what it was drawn with: Settings' currency and // number units never reached it (blrbrzkj on Discord). func TestPanelHiddenByWailsMarksPageOutOfSight(t *testing.T) { - out, err := runAppKit(t, 30*time.Second, []string{"MAGPIE_TEST_WINDOW_VISIBILITY=panel"}) + out, err := runAppKit(t, 2*time.Minute, []string{"MAGPIE_TEST_WINDOW_VISIBILITY=panel"}) if err != nil || !strings.Contains(string(out), "window visibility: ok") { t.Fatalf("panel visibility: %v\n%s", err, out) } @@ -45,6 +53,7 @@ func init() { return } ready := make(chan struct{}, 1) + hidden := make(chan url.Values, 1) reports := make(chan url.Values, 1) app := application.New(application.Options{ Name: "magpie window visibility regression", @@ -58,13 +67,22 @@ func init() { html.magpie-out-of-sight #probe{animation-play-state:paused!important}