Files
openchamber-android-native/third_party/mygo/webview_available_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

63 lines
1.8 KiB
Go

//go:build !js
package mygo
import (
"testing"
"github.com/egoist/mygo/ui"
)
// TestWebViewAvailable: the call reports what the backend says, so an app
// can ask before it creates its first window showing a page, as NewWindow
// panics where the platform has no webview.
func TestWebViewAvailable(t *testing.T) {
if !WebViewAvailable() {
t.Error("WebViewAvailable = false with a webview the fake has")
}
onMain(func() { fb.NoWebView = true })
t.Cleanup(func() { onMain(func() { fb.NoWebView = false }) })
if WebViewAvailable() {
t.Error("WebViewAvailable = true with NoWebView set")
}
}
// TestWebViewAvailableChoosesWindowKind: what the call is for, the guard an
// app writes, opens the window the machine can show, and both kinds work
// here: with no webview it opens one showing native UI, which needs none.
func TestWebViewAvailableChoosesWindowKind(t *testing.T) {
for _, noWebView := range []bool{false, true} {
name := "webview"
if noWebView {
name = "no webview"
}
t.Run(name, func(t *testing.T) {
onMain(func() { fb.NoWebView = noWebView })
t.Cleanup(func() { onMain(func() { fb.NoWebView = false }) })
var w *Window
if WebViewAvailable() {
w = NewWindow(WindowOptions{URL: "https://example.com"})
} else {
w = NewWindow(WindowOptions{Content: ui.View(func(c *ui.Context) { ui.Box(c) })})
}
t.Cleanup(w.Destroy)
// The window is of the kind the guard chose: a page, or native
// UI, which has none and needs no webview to be built.
if noWebView {
if w.Page() != nil {
t.Error("a window of native UI has a page")
}
if _, err := w.NewWebView(WebViewOptions{}); err != nil {
t.Errorf("NewWebView in a window of native UI: %v", err)
}
return
}
if w.Page() == nil {
t.Error("a window showing a page has none")
}
})
}
}