Files
magpie/internal/gui/webviewmend_test.go
T
yetone f46a37f509 gui: a WebView2 process that fails is logged and the window comes back by itself
aquaarboraurum on X (magpie 0.1.4040, Windows 11, WebView2 138): the
main window went white after a while, leaving the title bar, a strip at
the left edge and the status bar. Closing it to the tray and opening it
again brought it back, and the log said nothing.

Wails registers for WebView2's ProcessFailed but leaves its
ProcessFailedCallback unset, so nothing in magpie heard any WebView2
process end or fail. Now each window's failures are handled, once its
first page has come (webviewmend*.go):

- each one is logged: "webview (main window): GPU process exited;
  drawing it again", and so on for every COREWEBVIEW2_PROCESS_FAILED_KIND;
- GPU, unknown or a new kind: the controller is hidden and shown again
  (put_IsVisible), what the tray close and open did, without the window
  going;
- a render process that exits or hangs, or a frame's: the page is
  reloaded (ICoreWebView2::Reload);
- the browser process: the window is let go as lightweight mode does and
  the main window made again, once the old browser has let go of the
  profile folder (made at once, Wails ended magpie on a controller
  timeout);
- utility, sandbox helper and plugin processes: logged only;
- a reload or remake again within 30s is logged and left alone, so a
  failing renderer doesn't loop;
- after the computer wakes (SystemDidWake), each open window is drawn
  again the same way, since a GPU that lost its device while asleep is
  the likeliest way to a white surface with the window's frame left.

The cause of the report is not proven. Ending the GPU process on the
Windows box doesn't leave the old code white (WebView2 makes a new one
and the page keeps drawing), and a dead renderer doesn't match a window
that the tray brings back. The log line is what the next report needs.

Run:
- TestWebViewComesBackFromEachProcessEnd (new) on xiaomi-gpu, Windows 11
  25H2, WebView2 157, in the signed-in session (schtasks /it; it skips
  over ssh, session 0): it ends the test build's own renderer, GPU
  process and browser process and checks the page comes back drawn
  (screen pixels over the client area, white share 0.00) - renderer,
  gpu-process and browser all PASS (16.4s).
- Broken by hand (mendWebView taken out of makeMain): all three red -
  "the page didn't load", "hidden=false, never visible again", "timed
  out waiting until the window is made again".
- Old code, GPU process ended, white share sampled 10s: 0.00 every second
  (not white: the cause above is not reproduced).
- TestWebViewMendForEachFailure, TestMendGapHoldsOnlyReloadAndRemake.
- mica: go vet ./internal/gui (darwin, GOOS=windows), go vet -tags nogui
  (darwin, linux, windows), go test -count=1 ./internal/gui ok 137s.
- mica, go test -count=1 -timeout 45m ./... at f9ad4122b plus this
  change: 98 packages ok, one red, TestNoEagerPackageRegexps on
  davsync's setuptext.go (#6534, red on main, fixed in the next commit).
- xiaomi-gpu, go test ./internal/gui over ssh: 9 reds, the same 9 at
  origin/main f9ad4122b run the same way (#6068, #6059, #5928): %AppData%
  unset over ssh, file locks, Smart App Control; none touch WebView2.

Not tried: a real GPU device loss after sleep or display off, the
reporter's WebView2 138, the panel's remake (the same code path as
lightweight mode's let-go).
2026-11-13 19:45:24 +08:00

58 lines
1.8 KiB
Go

package gui
import (
"testing"
"time"
)
// aquaarboraurum on X: a main window gone white came back only when closed
// to the tray and opened again. Each WebView2 process failure now gets the
// mend that brings its window back.
func TestWebViewMendForEachFailure(t *testing.T) {
for kind, want := range map[uint32]webViewMend{
wv2BrowserExited: mendRemake,
wv2RenderExited: mendReload,
wv2RenderUnresponsive: mendReload,
wv2FrameRenderExited: mendReload,
wv2UtilityExited: mendNothing,
wv2SandboxHelperExited: mendNothing,
wv2GPUExited: mendRedraw,
wv2PPAPIPluginExited: mendNothing,
wv2PPAPIBrokerExited: mendNothing,
wv2UnknownExited: mendRedraw,
42: mendRedraw, // a kind of a later runtime
1<<32 - 1: mendRedraw, // the kind couldn't be read
} {
what, got := webViewMendFor(kind)
if got != want || what == "" {
t.Errorf("kind %d: %q %v, want %v", kind, what, got, want)
}
if mendWords[got] == "" {
t.Errorf("kind %d: mend %v has no words for the log", kind, got)
}
}
}
// A page that takes its renderer down again as it loads is not reloaded
// without end; a redraw is never held back.
func TestMendGapHoldsOnlyReloadAndRemake(t *testing.T) {
now := time.Date(2026, 11, 13, 12, 0, 0, 0, time.UTC)
for _, c := range []struct {
m webViewMend
last time.Time
want bool
}{
{mendReload, time.Time{}, true},
{mendReload, now.Add(-mendGap + time.Second), false},
{mendReload, now.Add(-mendGap), true},
{mendRemake, now.Add(-time.Second), false},
{mendRemake, now.Add(-time.Hour), true},
{mendRedraw, now.Add(-time.Second), true},
{mendNothing, now, true},
} {
if got := mendAllowed(c.m, c.last, now); got != c.want {
t.Errorf("%v last %s ago: %v, want %v", c.m, now.Sub(c.last), got, c.want)
}
}
}