Files
openchamber-android-native/third_party/mygo/internal/darwin/surface_frame_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

118 lines
3.3 KiB
Go

//go:build darwin && !ios
package darwin
import (
"testing"
"github.com/egoist/mygo/internal/platform"
)
// frameHandler is a window handler that leaves the paced frames it is
// sent to draw later while wait is true.
type frameHandler struct {
platform.WindowHandler
wait bool
paced []bool
}
func (h *frameHandler) SurfaceEvent(ev platform.SurfaceEvent) bool {
if ev.Kind != platform.SurfaceFrame {
return false
}
h.paced = append(h.paced, ev.Paced)
return ev.Paced && h.wait
}
// TestDeferredFrames checks that the display link keeps running while the
// content leaves a paced frame to draw later, and only then: once FrameNow
// draws it, and once the content draws any other frame instead (as a
// resize's, or a paced one it can draw), which draws what the one left
// would have, as the content then never calls FrameNow for it.
func TestDeferredFrames(t *testing.T) {
h := &frameHandler{}
s := &surface{w: &window{h: h}}
h.wait = true
s.frameNow(true)
if !s.deferred {
t.Fatal("a paced frame left to draw later: not deferred")
}
h.wait = false
s.FrameNow()
if s.deferred || h.paced[len(h.paced)-1] {
t.Fatalf("drawn at once: deferred %v, sent paced %v", s.deferred, h.paced[len(h.paced)-1])
}
// A frame AppKit displays, not paced, draws the one left.
h.wait = true
s.frameNow(true)
s.frameNow(false)
if s.deferred {
t.Fatal("a frame drawn meanwhile left the link running")
}
// A paced frame the content draws, as after its renderer was let go.
s.frameNow(true)
h.wait = false
s.frameNow(true)
if s.deferred {
t.Fatal("a paced frame drawn left the link running")
}
// Refreshes passing while the content waits keep it deferred.
h.wait = true
s.frameNow(true)
s.frameNow(true)
if !s.deferred {
t.Fatal("refreshes passing while the content waits: not deferred")
}
}
// TestDrawSoon checks that a frame asked for after a pause draws from the
// backend's queue, outside AppKit's display of views (#883), once however
// often it is asked for meanwhile, and not at all when another drew
// first, as a resize's does when AppKit displays the view, unless it was
// asked for again after that one.
func TestDrawSoon(t *testing.T) {
h := &frameHandler{}
b := &Backend{bySurface: map[id]*surface{}}
s := &surface{w: &window{b: b, h: h}, view: 1}
b.bySurface[s.view] = s
s.drawSoon()
s.drawSoon()
if len(h.paced) != 0 {
t.Fatal("drew at once")
}
drainMainQueue()
if len(h.paced) != 1 || h.paced[0] {
t.Fatalf("frames drawn from the queue: %v, want one not paced", h.paced)
}
s.drawSoon()
s.frameNow(false)
drainMainQueue()
if len(h.paced) != 2 {
t.Fatalf("drew %d frames, want the one drawn meanwhile alone", len(h.paced)-1)
}
// One asked for after the frame drawn meanwhile, as once the window
// whose first frame AppKit drew while the window was out of sight
// shows (SurfaceShown), still draws: dropped with the first, what
// moves would stop for good.
s.drawSoon()
s.frameNow(false)
s.drawSoon()
drainMainQueue()
if len(h.paced) != 4 || s.soon {
t.Fatalf("asked for after the frame drawn meanwhile: drew %d frames from the queue, want 1", len(h.paced)-3)
}
// A window closed meanwhile draws none.
s.drawSoon()
s.w.closed = true
drainMainQueue()
if len(h.paced) != 4 || s.soon {
t.Fatalf("a closed window drew %d frames (soon %v)", len(h.paced)-4, s.soon)
}
}