Documentation
¶
Overview ¶
Package motioninput provides a representation of Android's MotionEvent, and allows communication with the test application ArcMotionInputTest.apk via a Tester. It also provides a test framework that allows tests to verify MotionEvents across various windowing modes, such as clamshell, tablet, fullscreen, maximized, etc.
Index ¶
- Constants
- func RunTestWithWMParams(ctx context.Context, s *testing.State, tconn *chrome.TestConn, d *ui.Device, ...)
- type Action
- type Axis
- type Matcher
- type MotionEvent
- type Source
- type Tester
- func (t *Tester) ClearMotionEvents(ctx context.Context) error
- func (t *Tester) ExpectEventsAndClear(ctx context.Context, matchers ...Matcher) error
- func (t *Tester) ExpectMotionEvents(ctx context.Context, matchers ...Matcher) error
- func (t *Tester) WaitForTestAppFocused(ctx context.Context, wantFocused bool) error
- func (t *Tester) WaitUntilEvent(ctx context.Context, matcher Matcher) error
- type WMEventToSend
- type WMTestFunc
- type WMTestParams
- type WMTestState
Constants ¶
const ( ActionDown Action = "ACTION_DOWN" ActionUp Action = "ACTION_UP" ActionMove Action = "ACTION_MOVE" ActionHoverMove Action = "ACTION_HOVER_MOVE" ActionHoverEnter Action = "ACTION_HOVER_ENTER" ActionHoverExit Action = "ACTION_HOVER_EXIT" ActionButtonPress Action = "ACTION_BUTTON_PRESS" ActionButtonRelease Action = "ACTION_BUTTON_RELEASE" AxisX Axis = "AXIS_X" AxisY Axis = "AXIS_Y" AxisPressure Axis = "AXIS_PRESSURE" SourceTouchscreen Source = "touchscreen" SourceMouse Source = "mouse" SourceMouseRelative Source = "mouse_relative" )
Constant definitions for MotionEvent that should be kept in sync with its respective sources.
const ( APK = "ArcMotionInputTest.apk" Package = "org.chromium.arc.testapp.motioninput" EventReportingActivity = ".MotionEventReportingActivity" AutoPointerCaptureActivity = ".AutoPointerCaptureActivity" )
Constants for the test application ArcMotionInputTest.apk.
Variables ¶
This section is empty.
Functions ¶
func RunTestWithWMParams ¶
func RunTestWithWMParams(ctx context.Context, s *testing.State, tconn *chrome.TestConn, d *ui.Device, a *arc.ARC, params *WMTestParams, testFunc WMTestFunc)
RunTestWithWMParams sets up the window management state of the test device to that specified in the given WMTestParams, and runs the WMTestFunc. The APK must be installed on the device before using this helper.
Types ¶
type Action ¶
type Action string
Action represents a MotionEvent's action key. The values are from Android's MotionEvent.java. See: https://cs.android.com/android/platform/superproject/+/HEAD:frameworks/base/core/java/android/view/MotionEvent.java
type Axis ¶
type Axis string
Axis represents a MotionEvent's axis key. The values are from Android's MotionEvent.java. See: https://cs.android.com/android/platform/superproject/+/HEAD:frameworks/base/core/java/android/view/MotionEvent.java
type Matcher ¶
type Matcher func(*MotionEvent) error
Matcher represents a matcher for motionEvent.
func ActionSourceMatcher ¶
ActionSourceMatcher returns a motionEventMatcher that matches a motionEvent with the provided action and source.
type MotionEvent ¶
type MotionEvent struct { Action Action `json:"action"` DeviceID int `json:"device_id"` Sources []Source `json:"sources"` PointerAxes []map[Axis]float64 `json:"pointer_axes"` // Batched is true if this event was included in the history of another MotionEvent in Android, // and false otherwise. See more information about batching at: // https://cs.android.com/android/platform/superproject/+/HEAD:frameworks/base/core/java/android/view/MotionEvent.java;l=93 Batched bool `json:"batched"` }
MotionEvent represents a MotionEvent that was received by the Android application. For all Axis values that represent an absolute location, the values are in the coordinate space of the Android window (i.e. 0,0 is the top left corner of the application window in Android).
type Source ¶
type Source string
Source represents an input device's source. The values should be kept in sync with ArcMotionInputTest.apk.
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
Tester holds resources associated with ArcMotionInputTest activity.
func NewTester ¶
NewTester creates a new instance of a Tester. The provided activity should be started before any of the Tester's methods are called. All provided arguments must outlive the Tester.
func (*Tester) ClearMotionEvents ¶
ClearMotionEvents tells the test application to clear the events that it is currently reporting, and verifies that no events are reported. This is done by sending an intent with the appropriate action to Android, which is subsequently picked up by the MotionInputTest application and handled appropriately.
func (*Tester) ExpectEventsAndClear ¶
ExpectEventsAndClear is a convenience function that verifies expected events and clears the events to be ready for the next assertions.
func (*Tester) ExpectMotionEvents ¶
ExpectMotionEvents polls readMotionEvents repeatedly until it receives motionEvents that successfully match all of the provided motionEventMatchers in order, or until it times out.
func (*Tester) WaitForTestAppFocused ¶
WaitForTestAppFocused polls the test app until its window reaches the wanted focused state.
type WMTestFunc ¶
type WMTestFunc func(ctx context.Context, s *testing.State, tconn *chrome.TestConn, t *WMTestState, tester *Tester)
WMTestFunc represents the sub-test function that verifies certain motion input functionality using the Tester and the provided WMTestState.
type WMTestParams ¶
type WMTestParams struct { Name string // A description of the subtest. TabletMode bool // If true, the device will be put in tablet mode. WmEventToSend WMEventToSend // This must be of type ash.WMEventType, and can be nil. }
WMTestParams holds the test parameters used to set up the WM environment in Chrome, and represents a single sub-test.
type WMTestState ¶
type WMTestState struct { VerifiedWindowState *ash.WindowStateType // The window state of the test Activity after it is confirmed by Chrome. This can be nil if the window state was not verified. VerifiedTabletMode bool // The state of tablet mode after it is confirmed by Chrome. DisplayInfo *display.Info // The info for the display the Activity is in. Scale float64 // The scale factor used to convert Chrome's DP to Android's pixels. Window *ash.Window // The state of the test Activity's window. }
WMTestState holds various values that represent the test state for each sub-test. It is created for convenience to reduce the number of function parameters.
func (*WMTestState) CenterOfWindow ¶
func (t *WMTestState) CenterOfWindow() coords.Point
CenterOfWindow locates the center of the Activity's window in DP in the display's coordinates.
func (*WMTestState) ExpectedPoint ¶
func (t *WMTestState) ExpectedPoint(p coords.Point) coords.Point
ExpectedPoint takes a coords.Point representing the coordinate where an input event is injected in DP in the display space, and returns a coords.Point representing where it is expected to be injected in the Android application window's coordinate space.