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 ¶
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.
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.
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 Pin ¶
func Pin(env driver.Environment, pin *driver.Environment) driver.Environment
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, and the locale, text size, device name and device model when set. The rest, such as the OS, the idiom and the safe area, stays the platform's.
func RegisterLive ¶
RegisterLive gives `nsgo dev -automation`'s agent the running app's surfaces: find returns the backend's Surface for the surface numbered surface, 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 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.
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.
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 Options ¶
type Options struct {
// CheckCommits enables full-layout diagnostics for this app only.
CheckCommits bool
Size driver.Size
// 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
// 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.
// Neither may block.
Observe func(*driver.MountBatch)
Event func(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
// 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 and Linux; the web and Android measure
// only the engine, with no frame readings.
FPS bool
}
Options are what a test opens an app with.
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 animates anything that ends:
// a transition, a scroll's glide, a modal coming in.
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.