Files
openchamber-android-native/third_party/mygo/internal/e2e/input_region_linux_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

73 lines
2.8 KiB
Go

//go:build linux && !android && (amd64 || arm64)
package e2e
import (
"sync/atomic"
"testing"
"github.com/egoist/mygo"
"github.com/egoist/mygo/ui"
)
// TestInputRegion clicks a desktop pet: a frameless, transparent window
// over another, whose input region takes the clicks on its character and
// lets those elsewhere through to the window behind, through the X
// server's input shape, as a user's would be.
func TestInputRegion(t *testing.T) {
var behind, pet, character atomic.Int32
var drawn atomic.Int32
counted := func(n *atomic.Int32, e ui.Element) {
if e.Clicked() {
n.Add(1)
}
e.Draw(func(*ui.Painter, ui.Rect) { drawn.Add(1) })
}
back := newWindow(t, mygo.WindowOptions{Title: "Behind", X: 120, Y: 120, Width: 320, Height: 240, Content: ui.View(func(c *ui.Context) {
counted(&behind, ui.Box(c).Fill().Background(ui.RGB(240, 240, 240)))
})})
front := newWindow(t, mygo.WindowOptions{Title: "Pet", X: 120, Y: 120, Width: 320, Height: 240, Frameless: true, Transparent: true, AlwaysOnTop: true, Content: ui.View(func(c *ui.Context) {
c.Root().Background(ui.Transparent)
root := ui.Box(c).Fill()
counted(&pet, root)
root.Children(func() {
counted(&character, ui.Box(c).Absolute().Left(20).Top(30).Size(60, 50).Background(ui.RGB(220, 30, 40)))
})
})})
eventually(t, "both windows drawn", func() bool { return back.IsVisible() && front.IsVisible() && drawn.Load() >= 3 })
front.SetInputRegion([]mygo.Rectangle{{X: 20, Y: 30, Width: 60, Height: 50}})
if !click(front, 50, 50) {
t.Skip("surface click automation unavailable")
}
eventually(t, "the character clicked", func() bool { return character.Load() == 1 })
onPet := pet.Load() // the character's click, if it reaches the root too
click(front, 200, 150)
eventually(t, "the window behind clicked", func() bool { return behind.Load() == 1 })
if n := pet.Load(); n != onPet {
t.Fatalf("the pet took %d clicks off the character", n-onPet)
}
// An empty region lets all of it through, and nil none of it.
front.SetInputRegion([]mygo.Rectangle{})
click(front, 50, 50)
eventually(t, "the window behind clicked through the character", func() bool { return behind.Load() == 2 })
front.SetInputRegion(nil)
click(front, 200, 150)
eventually(t, "the pet clicked again", func() bool { return pet.Load() == onPet+1 })
if n := behind.Load(); n != 2 {
t.Fatalf("the window behind took %d clicks, want 2", n)
}
}
// TestInputRegionPage shapes the input of a window showing a page, which
// has no native UI's surface.
func TestInputRegionPage(t *testing.T) {
w := newWindow(t, mygo.WindowOptions{Title: "Page region", Width: 240, Height: 160})
eventually(t, "the window shown", w.IsVisible)
w.SetInputRegion([]mygo.Rectangle{{X: 10, Y: 10, Width: 50, Height: 40}})
w.SetIgnoreMouseEvents(true)
w.SetIgnoreMouseEvents(false)
w.SetInputRegion(nil)
}