testhost

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testhost is where a backend built for `nsgo test -target` (the nsgotest build tag) offers its test host, and where nsgotest finds it: the platform's loop on the main thread, an app shown on a real surface, and native input at the surface's points.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoInputMethod = errors.New("no input method composes on this machine")

ErrNoInputMethod is a composition step's answer where the machine has no input method to compose with, as Windows without an IME.

View Source
var ErrNoMenu = errors.New("the platform shows no native menus")

ErrNoMenu is a platform's answer to a menu step where it shows no native menus: a phone's, or the web's.

View Source
var PostToTest func(app any, fn func())

PostToTest queues fn on the goroutine of the test running app, an *nsgotest.App, to run as its next step or wait settles, also on a target, where nsgotest.App.Post runs fn on the engine's goroutine: tsx/tsxtest runs its test VM's work there, as the VM is the test's. nsgotest sets it.

Functions

func MakeUserDirs

func MakeUserDirs(dir string) map[core.StandardDir]string

MakeUserDirs makes a directory in dir for each of the user's folders, named as macOS names them, for a test to use in place of the user's.

func Pin

Pin applies what a test set in pin over env, as the platform reports it: the appearance, reduced motion, increased contrast, the login launch reason, the application in front and whether the platform follows it, the camera, code scanner and timed haptic capabilities, thermal state and low-power mode, and the network when set, and the locale, text size, device name, device model, vertical bar edge and displays when set. The rest, such as the OS, the idiom and the safe area, stays the platform's.

func Register

func Register(h Host)

Register makes h the test host; a backend's init calls it.

func RegisterLive

func RegisterLive(find func(graph int, surface uint32) Surface)

RegisterLive gives `nsgo dev -automation`'s agent the running app's surfaces: find returns the backend's Surface for surface of graph, to act on with native input, or nil where none shows; a backend's init in the builds with the nsgoautomation tag calls it.

func RequireSource added in v0.2.0

func RequireSource(t interface {
	Helper()
	Skip(...any)
})

RequireSource skips a check that reads the package's source files or compiles them with a JDK when the test runs in a browser or under a backend's test host: the browser and a device carry no checkout, and a desktop target runs the test binary outside the package's directory.

Types

type BlurWindowSurface

type BlurWindowSurface interface {
	BlurWindow() error
}

BlurWindowSurface is a surface whose window can lose focus in a test, releasing held keys and mouse buttons as the platform does on focus loss.

type Clicks added in v0.2.0

type Clicks struct {
	// contains filtered or unexported fields
}

Clicks counts nearby scripted presses for hosts whose input entry point takes the click count from the window system.

func (*Clicks) Press added in v0.2.0

func (c *Clicks) Press(at driver.Point, target any, now time.Time, interval time.Duration) int

Press counts a press at at of target, the view the host finds there, within interval and four points of the last. A press of another view starts a new sequence, as headless steps count a press of the view pressed last: a page pushed by a press shows its own control where the press was, which takes the next press as a single click, not the second of a double click that the window system may still send to the view that took the first.

type CloseWindow

type CloseWindow interface {
	RequestClose() error
}

CloseWindow is the native close-button action on a desktop test surface.

type Host

type Host interface {
	// Main runs the platform's loop on the calling goroutine, the main thread, and run on another; it ends the process with run's code once run has returned, never before, as run holds a TestMain's teardown (nsgotest.MainFunc).
	Main(run func() int)
	// Open shows app on a new surface as the backend's Run does, with
	// o's size and what it observes.
	Open(app func(cx *core.Scope) core.Node, o Options) (Surface, error)
	// Several reports whether a process opens several surfaces: a
	// desktop's windows; a phone and a page show one.
	Several() bool
}

Host is a backend's test host.

func Current

func Current() Host

Current returns the test host, or nil when the backend linked has none.

type KeyCodeSurface

type KeyCodeSurface interface {
	KeyCodeDown(code, name string) error
	KeyCodeUp(code, name string) error
}

KeyCodeSurface is a surface that presses a physical position, named as KeyboardEvent.code (KeyW), and holds it (KeyCodeDown) or lets it come up (KeyCodeUp): the platform's event carries the position's own code, so the app reads KeyEvent.Code, and a key name. On macOS, Windows, Linux and the web the platform's current keyboard layout names the key, as it does a real keyboard's, so KeyW is "z" on AZERTY, and name, the US layout's key there, is used only where the layout gives none; the other hosts report name. A modifier held both by KeyDown of its name and by KeyCodeDown of a position stays down until both let it go.

type KeyHoldSurface

type KeyHoldSurface interface {
	KeyDown(key string) error
	KeyUp(key string) error
}

KeyHoldSurface is a surface that presses one key and holds it (KeyDown), or lets it come up (KeyUp), as Key's two halves: a modifier it holds stays held through the keys after it until its KeyUp.

type KeyboardSurface added in v0.2.0

type KeyboardSurface interface {
	// PrepareKeyboard activates the app and waits for its window to take the keyboard when the run opted in to that (nsgo test -target macos -activate), and does nothing otherwise.
	PrepareKeyboard() error
	// FocusRefusal names the cause after a click left a field without the focus: an inactive app the run did not opt in to activating. It is nil otherwise.
	FocusRefusal() error
}

KeyboardSurface is a surface whose window takes the keyboard only while its app is active, as macOS's does.

type MediaSurface

type MediaSurface interface {
	MediaCommand(revision uint32, command driver.MediaCommand)
}

MediaSurface is a surface whose app can publish system media controls.

type MouseButtonSurface

type MouseButtonSurface interface {
	MouseDown(at driver.Point, button driver.MouseButton, mods driver.Modifiers) error
	MouseUp(at driver.Point, button driver.MouseButton, mods driver.Modifiers) error
}

MouseButtonSurface is a surface that presses one mouse button at a point and holds it (MouseDown), or lets it come up (MouseUp), with optional modifiers.

type OpenLinksSurface

type OpenLinksSurface interface {
	OpenLinks(links []string)
}

OpenLinksSurface delivers links to the app under test as the system would.

type Options

type Options struct {
	// CheckCommits enables full-layout diagnostics for this app only.
	CheckCommits bool
	// Updater is the test's updater snapshot, not the installed app's updater.
	Updater core.UpdaterState
	Size    driver.Size
	// Windows runs the app with the windowless surface that opens its windows.
	Windows bool
	// Environment pins what the test sets over what the platform reports
	// (Pin's fields), from the first frame.
	Environment *driver.Environment
	// Storage seeds the app's storage; in memory when nil.
	Storage *core.Store
	// Secrets is the app's secure store, in place of the machine's; one in memory when nil.
	Secrets driver.SecretStore
	// DiskSpace is the storage capacity the test sees on every target.
	DiskSpace driver.DiskSpaceResult
	// UserDirs pins core.Scope.UserDir's folders, one left out unavailable; nil gives each a directory of the test's temporary one.
	UserDirs map[core.StandardDir]string
	// Observe sees every batch the engine sends, on the engine's goroutine, before the platform applies it; Event every event the platform reports to the engine, on the goroutine it reports from. Each comes with the number of its surface: 0 for the first, the one Open opens, else the window or panel the app opened (driver.SurfaceConfig.ID). Neither may block.
	Observe func(surface uint32, b *driver.MountBatch)
	Event   func(surface uint32, ev driver.Event)
	// Host is the channel of the test's embedding host, nil without one.
	Host *core.Host
	// Clock is the test's, which the app's timers run on in place of the
	// system's: they fire as the test moves it.
	Clock core.Clock
	// TransitionEnds, when set, takes from the engine as the app starts a function reporting whether a view of the app's waits for its style transition to end before its OnTransitionEnd runs (core.Tree.PendingTransitionEnds), which a step takes Clock's frames for. It may be called on any goroutine but the engine's, and reports false once the engine ended.
	TransitionEnds func(pending func() bool)
	// FPS measures the app with the backend's performance monitor and
	// logs its readings once a second (nsgo test -fps), where the backend
	// has one: macOS, iOS, Windows, Linux and Android. The web measures
	// only the engine, with no frame readings.
	FPS bool
	// PickImages, when set, answers the photo picks the app asks for in place of the system's picker: done takes the files picked, none when the user cancels, and may be called on any goroutine. macOS, Windows and Linux use it; the other targets show their picker.
	PickImages func(driver.PickRequest, func([]driver.PickedFile))
	// TakePhoto, when set, answers the camera requests the app asks for in place of the system's camera: done takes the photo, an error, or nil for a cancellation, and may be called on any goroutine. Tests use it on every target.
	TakePhoto func(driver.PickRequest, func(*driver.PickedFile, error))
	// ScanCode, when set, answers the codes the app asks to scan in place of the platform's camera, on every target: done takes the code read, nil when the user closes the scanner, or why it failed, and may be called on any goroutine.
	ScanCode func(driver.ScanRequest, func(*driver.ScannedCode, error))
}

Options are what a test opens an app with.

type PinchSurface

type PinchSurface interface {
	Pinch(at driver.Point, scales []float32) error
}

PinchSurface is implemented by test hosts that can drive the platform's gesture path for a pinch at a point in the surface.

type PointerLockSurface

type PointerLockSurface interface {
	PointerDelta(dx, dy float64)
}

PointerLockSurface sends device motion through the surface's active lock.

type QuitSurface

type QuitSurface interface {
	RequestQuit(id uint32, forced bool)
}

QuitSurface sends a user or system quit request to the test's app without ending the test host.

type SharedItemsSurface

type SharedItemsSurface interface {
	ReceiveShare(items []driver.SharedItem)
}

SharedItemsSurface delivers an incoming share to the app under test.

type Surface

type Surface interface {
	// Press presses at at for hold (a tap when 0), as a finger or the mouse's primary button does, with mods held for the press only.
	Press(at driver.Point, hold time.Duration, mods driver.Modifiers) error
	// RightClick clicks the secondary button at at.
	RightClick(at driver.Point) error
	// Drag puts a finger or the primary button down at path[0], rests,
	// moves through the rest of path and lifts.
	Drag(path []driver.Point) error
	// Scroll scrolls the content under at by delta, as a wheel, a
	// trackpad or a drag that rests before it lifts does.
	Scroll(at driver.Point, delta driver.Point) error
	// Hover moves the mouse to at; a point outside the surface leaves it.
	Hover(at driver.Point) error
	// Type types text into the focused field, a key at a time.
	Type(text string) error
	// Compose has an input method compose text in the focused field
	// through the platform's text input client, as one marks what it
	// composes: "" ends the composition with nothing. Commit has it
	// commit text there, ending the composition. Both answer
	// ErrNoInputMethod where none can compose.
	Compose(text string) error
	Commit(text string) error
	// Key presses a key with modifiers, as the keymap names them:
	// "Enter", "Backspace", "Escape", "mod+a".
	Key(key string) error
	// Back goes back as the platform's back button, gesture or Escape.
	Back() error
	// Answer presses the button at index of the alert id shows, or
	// dismisses it with -1.
	Answer(id uint32, index int) error
	// ChooseMenu chooses the application menu's item id, as its menu bar
	// does; ErrNoMenu where the platform shows none.
	ChooseMenu(id uint32) error
	// ChooseDockMenu chooses the app icon menu's item id, as the Dock menu or the Jump List does; ErrNoMenu where the platform has none.
	ChooseDockMenu(id uint32) error
	// ChoosePopup chooses item id of the context menu showing, or closes it for 0, doing nothing when none shows; ErrNoMenu where the platform shows none.
	ChoosePopup(id uint32) error
	// Screenshot returns the surface as a PNG.
	Screenshot() ([]byte, error)
	// Animating reports whether the platform is still delivering input, applying
	// batches or running a finite animation, such as a transition or scroll glide.
	Animating() bool
	// Resize resizes the surface; SetEnvironment changes what it reports,
	// as a system setting does.
	Resize(size driver.Size) error
	SetEnvironment(env driver.Environment) error
	// Sync returns once the app's engine ran what was posted to it before and handed the resulting commits to the platform.
	Sync()
}

Surface is an app shown on a platform. Its methods act as the user does, with the platform's own input, at points of the surface (its top left is 0, 0), and return once the input is posted.

func Live

func Live(graph int, surface uint32) Surface

Live returns the backend's Surface for surface of graph, nil where none shows or no backend registered one.

type TabBarSurface

type TabBarSurface interface {
	SelectTab(id driver.NodeID, index int) error
}

TabBarSurface chooses one of the native tab bar's items by index.

type TextSelectionSurface

type TextSelectionSurface interface {
	SelectRange(selection driver.TextRange) (driver.TextRange, error)
}

TextSelectionSurface moves the focused native field's selection in UTF-16 units and returns the range the field reports. Its normal selection callback runs when subscribed; the returned range also updates models without one.

type WindowHost

type WindowHost interface {
	Host
	OpensWindows(app bool) bool
}

WindowHost is a Host whose apps can open their own windows, as Run does with core.RootOptions.Windows. app says whether StartApp supplied an app function; macOS uses its own windowless surface in either case. The main window opens at the platform's default size when Options.Size is zero.

type WindowState

type WindowState struct {
	Frame            driver.WindowFrame
	Visible, Focused bool
}

WindowState is a snapshot read from the native window on its UI thread. Frame uses desktop screen points; Move is false when its position is unknown.

type WindowStateSurface

type WindowStateSurface interface {
	WindowState() (WindowState, error)
}

WindowStateSurface observes native state rather than the app's commands.

type WindowSurfaces

type WindowSurfaces interface {
	WindowSurface(id uint32) Surface
}

WindowSurfaces resolves the native test surface an app opened. It is implemented by the surface returned from a desktop test host's Open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL