Some checks failed
Security Scan / security (push) Failing after 26s
Window package: - 15 new PlatformWindow methods (zoom, content, bounds, states, print, flash) - 16 new IPC types (tasks + queries for all new capabilities) - ZoomIn/ZoomOut step 0.1, clamped to minimum 0.1 - SetURL, SetHTML, ExecJS for webview content control - 36 new tests with Good/Bad/Ugly coverage Events package (NEW — 17th package): - Custom event system bridged to Core IPC - Emit, On, Off, OnMultiple, Reset via Platform interface - ActionEventFired broadcast for agent consumption - 17 tests All 17 packages build and test clean. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
100 lines
4.5 KiB
Go
100 lines
4.5 KiB
Go
package window
|
|
|
|
// MockPlatform is an exported mock for cross-package integration tests.
|
|
// For internal tests, use the unexported mockPlatform in mock_test.go.
|
|
type MockPlatform struct {
|
|
Windows []*MockWindow
|
|
}
|
|
|
|
func NewMockPlatform() *MockPlatform {
|
|
return &MockPlatform{}
|
|
}
|
|
|
|
func (m *MockPlatform) CreateWindow(options PlatformWindowOptions) PlatformWindow {
|
|
w := &MockWindow{
|
|
name: options.Name, title: options.Title, url: options.URL,
|
|
width: options.Width, height: options.Height,
|
|
x: options.X, y: options.Y,
|
|
}
|
|
m.Windows = append(m.Windows, w)
|
|
return w
|
|
}
|
|
|
|
func (m *MockPlatform) GetWindows() []PlatformWindow {
|
|
out := make([]PlatformWindow, len(m.Windows))
|
|
for i, w := range m.Windows {
|
|
out[i] = w
|
|
}
|
|
return out
|
|
}
|
|
|
|
type MockWindow struct {
|
|
name, title, url string
|
|
width, height, x, y int
|
|
maximised, focused bool
|
|
visible, alwaysOnTop bool
|
|
backgroundColour [4]uint8
|
|
closed bool
|
|
minimised bool
|
|
fullscreened bool
|
|
zoom float64
|
|
html string
|
|
contentProtection bool
|
|
flashed bool
|
|
execJSCalls []string
|
|
eventHandlers []func(WindowEvent)
|
|
fileDropHandlers []func(paths []string, targetID string)
|
|
}
|
|
|
|
func (w *MockWindow) Name() string { return w.name }
|
|
func (w *MockWindow) Title() string { return w.title }
|
|
func (w *MockWindow) Position() (int, int) { return w.x, w.y }
|
|
func (w *MockWindow) Size() (int, int) { return w.width, w.height }
|
|
func (w *MockWindow) IsMaximised() bool { return w.maximised }
|
|
func (w *MockWindow) IsFocused() bool { return w.focused }
|
|
func (w *MockWindow) IsVisible() bool { return w.visible }
|
|
func (w *MockWindow) IsFullscreen() bool { return w.fullscreened }
|
|
func (w *MockWindow) IsMinimised() bool { return w.minimised }
|
|
func (w *MockWindow) GetBounds() (int, int, int, int) { return w.x, w.y, w.width, w.height }
|
|
func (w *MockWindow) GetZoom() float64 {
|
|
if w.zoom == 0 {
|
|
return 1.0
|
|
}
|
|
return w.zoom
|
|
}
|
|
func (w *MockWindow) SetTitle(title string) { w.title = title }
|
|
func (w *MockWindow) SetPosition(x, y int) { w.x = x; w.y = y }
|
|
func (w *MockWindow) SetSize(width, height int) { w.width = width; w.height = height }
|
|
func (w *MockWindow) SetBackgroundColour(r, g, b, a uint8) { w.backgroundColour = [4]uint8{r, g, b, a} }
|
|
func (w *MockWindow) SetVisibility(visible bool) { w.visible = visible }
|
|
func (w *MockWindow) SetAlwaysOnTop(alwaysOnTop bool) { w.alwaysOnTop = alwaysOnTop }
|
|
func (w *MockWindow) SetBounds(x, y, width, height int) {
|
|
w.x = x
|
|
w.y = y
|
|
w.width = width
|
|
w.height = height
|
|
}
|
|
func (w *MockWindow) SetURL(url string) { w.url = url }
|
|
func (w *MockWindow) SetHTML(html string) { w.html = html }
|
|
func (w *MockWindow) SetZoom(magnification float64) { w.zoom = magnification }
|
|
func (w *MockWindow) SetContentProtection(protection bool) { w.contentProtection = protection }
|
|
func (w *MockWindow) Maximise() { w.maximised = true }
|
|
func (w *MockWindow) Restore() { w.maximised = false }
|
|
func (w *MockWindow) Minimise() { w.minimised = true }
|
|
func (w *MockWindow) Focus() { w.focused = true }
|
|
func (w *MockWindow) Close() { w.closed = true }
|
|
func (w *MockWindow) Show() { w.visible = true }
|
|
func (w *MockWindow) Hide() { w.visible = false }
|
|
func (w *MockWindow) Fullscreen() { w.fullscreened = true }
|
|
func (w *MockWindow) UnFullscreen() { w.fullscreened = false }
|
|
func (w *MockWindow) ToggleFullscreen() { w.fullscreened = !w.fullscreened }
|
|
func (w *MockWindow) ToggleMaximise() { w.maximised = !w.maximised }
|
|
func (w *MockWindow) ExecJS(js string) { w.execJSCalls = append(w.execJSCalls, js) }
|
|
func (w *MockWindow) Flash(enabled bool) { w.flashed = enabled }
|
|
func (w *MockWindow) Print() error { return nil }
|
|
func (w *MockWindow) OnWindowEvent(handler func(WindowEvent)) {
|
|
w.eventHandlers = append(w.eventHandlers, handler)
|
|
}
|
|
func (w *MockWindow) OnFileDrop(handler func(paths []string, targetID string)) {
|
|
w.fileDropHandlers = append(w.fileDropHandlers, handler)
|
|
}
|