Files
core/gui/window/frame_test.go
T
terminarandClaude Opus 5.5 31dbc347e8 gui/window: keep the window frame across starts, take the first click
- Options.FrameFile: the window's position, size and maximized state in
  a small JSON file, read at New (a frame on no connected screen is
  ignored, the window opens centered), written shortly after every move
  or resize and at Destroy. macOS: NSWindow frame (the normal frame
  under a zoomed one), checked against NSScreen visible frames; Windows:
  Get/SetWindowPlacement, checked with MonitorFromRect.
- macOS: the web view is a WKWebView subclass that accepts the first
  mouse click, so a page in an inactive window reacts to it instead of
  the click only activating the window (yanks' start dialog).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:19:45 +01:00

41 lines
1.2 KiB
Go

package window
import (
"os"
"path/filepath"
"testing"
)
func TestFrameFileRoundTrip(t *testing.T) {
path := filepath.Join(t.TempDir(), "state", "window.json")
if _, ok := loadFrame(path); ok {
t.Fatal("a missing file is a frame")
}
s := &frameSaver{path: path}
s.changed(Frame{X: 10, Y: 20, Width: 300, Height: 200})
s.changed(Frame{X: 40, Y: 50, Width: 1200, Height: 800, Maximized: true}) // the last one wins
s.flush()
f, ok := loadFrame(path)
if !ok || f != (Frame{X: 40, Y: 50, Width: 1200, Height: 800, Maximized: true}) {
t.Fatalf("loaded %+v, %v", f, ok)
}
if _, err := os.Stat(path + ".tmp"); !os.IsNotExist(err) {
t.Errorf("temp file left behind: %v", err)
}
// Too small or broken: no frame, the window opens with its default.
for _, data := range []string{`{"x":0,"y":0,"width":50,"height":40}`, `not json`, ``} {
if err := os.WriteFile(path, []byte(data), 0o644); err != nil {
t.Fatal(err)
}
if f, ok := loadFrame(path); ok {
t.Errorf("%q loaded as %+v", data, f)
}
}
s.changed(Frame{Width: 10, Height: 10}) // ignored
s.flush()
if data, _ := os.ReadFile(path); string(data) != "" {
t.Errorf("an unusable frame was written: %q", data)
}
}