enginetest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package enginetest provides deterministic host-side test doubles for the execution engine and other callers of the frozen device contract.

Index

Constants

This section is empty.

Variables

View Source
var ErrFakeTimerStopped = errors.New("fake timer stopped")

ErrFakeTimerStopped is returned when waiting on an explicitly stopped timer.

Functions

func PNGFixture

func PNGFixture(marker string) []byte

PNGFixture is a REAL PNG signature followed by a marker that keeps two fixtures distinguishable.

A real PNG signature lets tests catch extension and content-type mistakes while the marker keeps fixtures distinguishable.

Types

type Action

type Action struct {
	Sequence uint64
	Method   Method
	Request  any
}

Action records one accepted driver call.

type DriverScript

type DriverScript struct {
	Name                            []string
	Open                            []Result[struct{}]
	Close                           []Result[struct{}]
	DeviceInfo                      []Result[device.DeviceInfo]
	LaunchApp                       []Result[struct{}]
	StopApp                         []Result[struct{}]
	KillApp                         []Result[struct{}]
	ClearAppState                   []Result[struct{}]
	ClearKeychain                   []Result[struct{}]
	Tap                             []Result[struct{}]
	LongPress                       []Result[struct{}]
	PressKey                        []Result[struct{}]
	ContentDescriptor               []Result[device.TreeNode]
	ScrollVertical                  []Result[struct{}]
	IsKeyboardVisible               []Result[bool]
	Swipe                           []Result[struct{}]
	BackPress                       []Result[struct{}]
	InputText                       []Result[struct{}]
	OpenLink                        []Result[struct{}]
	HideKeyboard                    []Result[struct{}]
	TakeScreenshot                  []Result[[]byte]
	StartScreenRecording            []Result[device.CaptureID]
	SetLocation                     []Result[struct{}]
	SetOrientation                  []Result[struct{}]
	EraseText                       []Result[struct{}]
	SetProxy                        []Result[struct{}]
	ResetProxy                      []Result[struct{}]
	IsShutdown                      []Result[bool]
	WaitUntilScreenIsStatic         []Result[bool]
	WaitForAppToSettle              []Result[*device.ViewHierarchy]
	Capabilities                    []device.Capabilities
	SetPermissions                  []Result[struct{}]
	AddMedia                        []Result[struct{}]
	IsAirplaneModeEnabled           []Result[bool]
	SetAirplaneMode                 []Result[struct{}]
	SetAndroidChromeDevToolsEnabled []Result[struct{}]
	QueryOnDeviceElements           []Result[[]device.TreeNode]
	StartDeviceLogCapture           []Result[device.CaptureID]
	StopDeviceLogCapture            []Result[[]device.Artifact]
	CollectCrashArtifacts           []Result[[]device.Artifact]
}

DriverScript appends typed FIFO results to a FakeDriver. Empty queues make their operation return its zero value and a nil error.

type FakeClock

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

FakeClock is a manually advanced, concurrency-safe clock for deterministic engine tests.

func NewFakeClock

func NewFakeClock(start time.Time) *FakeClock

NewFakeClock starts a clock at the supplied instant.

func (*FakeClock) Advance

func (c *FakeClock) Advance(delta time.Duration) time.Time

Advance moves time forward and fires every timer at or before the new time.

func (*FakeClock) NewTimer

func (c *FakeClock) NewTimer(delay time.Duration) *FakeTimer

NewTimer registers a timer relative to the current fake instant.

func (*FakeClock) Now

func (c *FakeClock) Now() time.Time

Now returns the current fake instant.

func (*FakeClock) PendingTimers

func (c *FakeClock) PendingTimers() int

PendingTimers returns the number of registered deadlines that have not fired.

func (*FakeClock) Wait

func (c *FakeClock) Wait(ctx context.Context, delay time.Duration) error

Wait blocks without wall-clock sleeping until delay elapses in fake time or the context is cancelled. A cancelled wait unregisters its timer.

type FakeDriver

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

FakeDriver is a concurrency-safe, deterministic device test double.

func NewFakeDriver

func NewFakeDriver() *FakeDriver

NewFakeDriver returns a driver with empty scripts and a sequence starting at one.

func (*FakeDriver) Actions

func (f *FakeDriver) Actions() []Action

Actions returns an isolated snapshot of accepted calls.

func (*FakeDriver) AddMedia

func (f *FakeDriver) AddMedia(ctx context.Context, request device.AddMediaRequest) error

func (*FakeDriver) BackPress

func (f *FakeDriver) BackPress(ctx context.Context) error

func (*FakeDriver) Capabilities

func (f *FakeDriver) Capabilities() device.Capabilities

func (*FakeDriver) ClearAppState

func (f *FakeDriver) ClearAppState(ctx context.Context, request device.AppRequest) error

func (*FakeDriver) ClearKeychain

func (f *FakeDriver) ClearKeychain(ctx context.Context) error

func (*FakeDriver) Close

func (f *FakeDriver) Close(ctx context.Context) error

func (*FakeDriver) CollectCrashArtifacts

func (f *FakeDriver) CollectCrashArtifacts(ctx context.Context, request device.ArtifactRequest) ([]device.Artifact, error)

func (*FakeDriver) ContentDescriptor

func (f *FakeDriver) ContentDescriptor(ctx context.Context, request device.ContentDescriptorRequest) (device.TreeNode, error)

func (*FakeDriver) DeviceInfo

func (f *FakeDriver) DeviceInfo(ctx context.Context) (device.DeviceInfo, error)

func (*FakeDriver) Enqueue

func (f *FakeDriver) Enqueue(script DriverScript)

Enqueue atomically appends a typed batch of scripted results.

func (*FakeDriver) EraseText

func (f *FakeDriver) EraseText(ctx context.Context, request device.EraseTextRequest) error

func (*FakeDriver) HideKeyboard

func (f *FakeDriver) HideKeyboard(ctx context.Context) error

func (*FakeDriver) InputText

func (f *FakeDriver) InputText(ctx context.Context, request device.InputTextRequest) error

func (*FakeDriver) IsAirplaneModeEnabled

func (f *FakeDriver) IsAirplaneModeEnabled(ctx context.Context) (bool, error)

func (*FakeDriver) IsKeyboardVisible

func (f *FakeDriver) IsKeyboardVisible(ctx context.Context, request device.KeyboardRequest) (bool, error)

func (*FakeDriver) IsShutdown

func (f *FakeDriver) IsShutdown(ctx context.Context) (bool, error)

func (*FakeDriver) KillApp

func (f *FakeDriver) KillApp(ctx context.Context, request device.AppRequest) error

func (*FakeDriver) LaunchApp

func (f *FakeDriver) LaunchApp(ctx context.Context, request device.LaunchAppRequest) error

func (*FakeDriver) LongPress

func (f *FakeDriver) LongPress(ctx context.Context, request device.LongPressRequest) error

func (*FakeDriver) Name

func (f *FakeDriver) Name() string

func (*FakeDriver) Open

func (f *FakeDriver) Open(ctx context.Context) error
func (f *FakeDriver) OpenLink(ctx context.Context, request device.OpenLinkRequest) error

func (*FakeDriver) PressKey

func (f *FakeDriver) PressKey(ctx context.Context, request device.PressKeyRequest) error

func (*FakeDriver) QueryOnDeviceElements

func (f *FakeDriver) QueryOnDeviceElements(ctx context.Context, request device.QueryRequest) ([]device.TreeNode, error)

func (*FakeDriver) ResetProxy

func (f *FakeDriver) ResetProxy(ctx context.Context) error

func (*FakeDriver) ScrollVertical

func (f *FakeDriver) ScrollVertical(ctx context.Context, request device.ScrollVerticalRequest) error

func (*FakeDriver) SetAirplaneMode

func (f *FakeDriver) SetAirplaneMode(ctx context.Context, request device.AirplaneModeRequest) error

func (*FakeDriver) SetAndroidChromeDevToolsEnabled

func (f *FakeDriver) SetAndroidChromeDevToolsEnabled(ctx context.Context, request device.ChromeDevToolsRequest) error

func (*FakeDriver) SetLocation

func (f *FakeDriver) SetLocation(ctx context.Context, request device.Location) error

func (*FakeDriver) SetOrientation

func (f *FakeDriver) SetOrientation(ctx context.Context, request device.Orientation) error

func (*FakeDriver) SetPermissions

func (f *FakeDriver) SetPermissions(ctx context.Context, request device.PermissionsRequest) error

func (*FakeDriver) SetProxy

func (f *FakeDriver) SetProxy(ctx context.Context, request device.Proxy) error

func (*FakeDriver) StartDeviceLogCapture

func (f *FakeDriver) StartDeviceLogCapture(ctx context.Context, request device.DeviceLogRequest) (device.CaptureID, error)

func (*FakeDriver) StartScreenRecording

func (f *FakeDriver) StartScreenRecording(ctx context.Context, request device.ScreenRecordingRequest) (device.CaptureID, error)

func (*FakeDriver) StopApp

func (f *FakeDriver) StopApp(ctx context.Context, request device.AppRequest) error

func (*FakeDriver) StopDeviceLogCapture

func (f *FakeDriver) StopDeviceLogCapture(ctx context.Context, request device.CaptureID) ([]device.Artifact, error)

func (*FakeDriver) Swipe

func (f *FakeDriver) Swipe(ctx context.Context, request device.SwipeRequest) error

func (*FakeDriver) TakeScreenshot

func (f *FakeDriver) TakeScreenshot(ctx context.Context, request device.ScreenshotRequest) ([]byte, error)

func (*FakeDriver) Tap

func (f *FakeDriver) Tap(ctx context.Context, request device.TapRequest) error

func (*FakeDriver) WaitForAppToSettle

func (f *FakeDriver) WaitForAppToSettle(ctx context.Context, request device.SettleRequest) (*device.ViewHierarchy, error)

func (*FakeDriver) WaitUntilScreenIsStatic

func (f *FakeDriver) WaitUntilScreenIsStatic(ctx context.Context, request device.ScreenStaticRequest) (bool, error)

type FakeTimer

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

FakeTimer is one deadline registered with a FakeClock.

func (*FakeTimer) Deadline

func (t *FakeTimer) Deadline() time.Time

Deadline returns the immutable fake deadline.

func (*FakeTimer) Done

func (t *FakeTimer) Done() <-chan struct{}

Done closes when the fake clock reaches the timer deadline.

func (*FakeTimer) Stop

func (t *FakeTimer) Stop() bool

Stop prevents a pending timer from firing and unblocks its waiters.

func (*FakeTimer) Wait

func (t *FakeTimer) Wait(ctx context.Context) error

Wait blocks without wall-clock sleeping until the timer fires or the context is cancelled.

type Method

type Method string

Method names one device.Driver operation in an action trace.

const (
	MethodName                            Method = "Name"
	MethodOpen                            Method = "Open"
	MethodClose                           Method = "Close"
	MethodDeviceInfo                      Method = "DeviceInfo"
	MethodLaunchApp                       Method = "LaunchApp"
	MethodStopApp                         Method = "StopApp"
	MethodKillApp                         Method = "KillApp"
	MethodClearAppState                   Method = "ClearAppState"
	MethodClearKeychain                   Method = "ClearKeychain"
	MethodTap                             Method = "Tap"
	MethodLongPress                       Method = "LongPress"
	MethodPressKey                        Method = "PressKey"
	MethodContentDescriptor               Method = "ContentDescriptor"
	MethodScrollVertical                  Method = "ScrollVertical"
	MethodIsKeyboardVisible               Method = "IsKeyboardVisible"
	MethodSwipe                           Method = "Swipe"
	MethodBackPress                       Method = "BackPress"
	MethodInputText                       Method = "InputText"
	MethodOpenLink                        Method = "OpenLink"
	MethodHideKeyboard                    Method = "HideKeyboard"
	MethodTakeScreenshot                  Method = "TakeScreenshot"
	MethodStartScreenRecording            Method = "StartScreenRecording"
	MethodSetLocation                     Method = "SetLocation"
	MethodSetOrientation                  Method = "SetOrientation"
	MethodEraseText                       Method = "EraseText"
	MethodSetProxy                        Method = "SetProxy"
	MethodResetProxy                      Method = "ResetProxy"
	MethodIsShutdown                      Method = "IsShutdown"
	MethodWaitUntilScreenIsStatic         Method = "WaitUntilScreenIsStatic"
	MethodWaitForAppToSettle              Method = "WaitForAppToSettle"
	MethodCapabilities                    Method = "Capabilities"
	MethodSetPermissions                  Method = "SetPermissions"
	MethodAddMedia                        Method = "AddMedia"
	MethodIsAirplaneModeEnabled           Method = "IsAirplaneModeEnabled"
	MethodSetAirplaneMode                 Method = "SetAirplaneMode"
	MethodSetAndroidChromeDevToolsEnabled Method = "SetAndroidChromeDevToolsEnabled"
	MethodQueryOnDeviceElements           Method = "QueryOnDeviceElements"
	MethodStartDeviceLogCapture           Method = "StartDeviceLogCapture"
	MethodStopDeviceLogCapture            Method = "StopDeviceLogCapture"
	MethodCollectCrashArtifacts           Method = "CollectCrashArtifacts"
)

type Result

type Result[T any] struct {
	Value T
	Err   error
}

Result is one scripted FIFO return from a fake operation.

Jump to

Keyboard shortcuts

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