a11y

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package a11y provides functions to assist with interacting with accessibility features and settings.

Index

Constants

View Source
const (
	ESpeakExtensionID    = "dakbfdmgjiabojdgbiljlhgjbokobjpg"
	GoogleTTSExtensionID = "gjjabgpgjpampikjhjpfhneeoapjbjaf"
)

List of extension IDs and URLs.

Variables

View Source
var ErrNodeDoesNotExist = errors.New("node does not exist")

ErrNodeDoesNotExist is returned when the node is not found.

Functions

func MaybeCloseDictationDialog

func MaybeCloseDictationDialog(ctx context.Context, ui *uiauto.Context) error

MaybeCloseDictationDialog closes the dialog that is shown when Dictation is first enabled, if it appears on the screen. The dialog warns the user that their voice is sent to Google. This function accepts the dialog so we can use the feature.

func NewTabWithHTML

func NewTabWithHTML(ctx context.Context, br *browser.Browser, html string) (*browser.Conn, error)

NewTabWithHTML creates a new tab with the specified HTML, waits for it to load, and returns a connection to the page. This works with either ash-chrome or lacros-chrome browser.

func PressKeysAndConsumeExpectations

func PressKeysAndConsumeExpectations(ctx context.Context, sm *SpeechMonitor, keySequence []string, expectations []SpeechExpectation) error

PressKeysAndConsumeExpectations presses keys and ensures that the expectations were spoken by the TTS engine.

func SetFeatureEnabled

func SetFeatureEnabled(ctx context.Context, tconn *chrome.TestConn, feature Feature, enable bool) error

SetFeatureEnabled sets the specified accessibility feature enabled/disabled using the provided connection to the extension.

func SetTTSRate

func SetTTSRate(ctx context.Context, tconn *chrome.TestConn, rate float64) error

SetTTSRate sets the speaking rate of the tts, relative to the default rate (1.0).

func ToggleDictation

func ToggleDictation(ctx context.Context) error

ToggleDictation presses Search + D on the keyboard to either turn Dictation on or off, depending on the current state.

Types

type ChromeVoxConn

type ChromeVoxConn struct {
	*chrome.Conn
}

ChromeVoxConn represents a connection to the ChromeVox background page.

func NewChromeVoxConn

func NewChromeVoxConn(ctx context.Context, c *chrome.Chrome) (*ChromeVoxConn, error)

NewChromeVoxConn returns a connection to the ChromeVox extension's background page. If the extension is not ready, the connection will be closed before returning. Otherwise the calling function will close the connection.

func (*ChromeVoxConn) SetVoice

func (cv *ChromeVoxConn) SetVoice(ctx context.Context, vd VoiceData) error

SetVoice sets the ChromeVox's voice, which is specified by using an extension ID and a locale.

func (*ChromeVoxConn) WaitForFocusedNode

func (cv *ChromeVoxConn) WaitForFocusedNode(ctx context.Context, tconn *chrome.TestConn, finder *nodewith.Finder) error

WaitForFocusedNode polls until the properties of the focused node matches the finder. timeout specifies the timeout to use when polling.

type Event

type Event struct {
	Target    *Node
	Type      event.Event `json:"type"`
	EventFrom string      `json:"eventFrom"`
	MouseX    int         `json:"mouseX"`
	MouseY    int         `json:"mouseY"`
}

Event represents a chrome.automation AutomationEvent. See https://chromium.googlesource.com/chromium/src/+/HEAD/extensions/common/api/automation.idl#492 Do not forget to release the Target node.

type EventSlice

type EventSlice []Event

EventSlice is a slice of Events. It is used for releaseing nodes in a group of events.

func (EventSlice) Release

func (es EventSlice) Release(ctx context.Context)

Release frees the reference to Javascript for this node.

type EventWatcher

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

EventWatcher registers the listener of AutomationEvent and watches the events.

func NewRootWatcher

func NewRootWatcher(ctx context.Context, tconn *chrome.TestConn, eventType event.Event) (*EventWatcher, error)

NewRootWatcher creates a new event watcher on the root node for the specified event type.

func NewWatcher

func NewWatcher(ctx context.Context, n *Node, eventType event.Event) (*EventWatcher, error)

NewWatcher creates a new event watcher on a node for the specified event type.

func (*EventWatcher) Release

func (ew *EventWatcher) Release(ctx context.Context) error

Release frees the resources and the reference to Javascript for this watcher.

func (*EventWatcher) WaitForEvent

func (ew *EventWatcher) WaitForEvent(ctx context.Context, timeout time.Duration) (EventSlice, error)

WaitForEvent waits for at least one event to occur on the event watcher and returns the list of the events. The caller is responsible to release EventSlice.

type Feature

type Feature string

Feature represents an accessibility feature in Chrome OS.

const (
	Autoclick       Feature = "autoclick"
	Dictation       Feature = "dictation"
	DockedMagnifier Feature = "dockedMagnifier"
	FocusHighlight  Feature = "focusHighlight"
	ScreenMagnifier Feature = "screenMagnifier"
	SelectToSpeak   Feature = "selectToSpeak"
	SpokenFeedback  Feature = "spokenFeedback"
	SwitchAccess    Feature = "switchAccess"
)

List of accessibility features.

type FindParams

type FindParams struct {
	Name       string
	Role       role.Role
	Attributes map[string]interface{}
	State      map[state.State]bool
}

FindParams is a mapping of chrome.automation.FindParams to Golang. As defined in chromium/src/extensions/common/api/automation.idl

type Node

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

Node is a reference to chrome.automation API AutomationNode. Node intentionally leaves out many properties. If they become needed, add them to the Node struct and to the Update function. As defined in chromium/src/extensions/common/api/automation.idl Exported fields are sorted in alphabetical order.

func FindWithTimeout

func FindWithTimeout(ctx context.Context, tconn *chrome.TestConn, params FindParams, timeout time.Duration) (*Node, error)

FindWithTimeout finds a descendant of the root node using params and returns it. If the JavaScript fails to execute, an error is returned.

func NewNode

func NewNode(ctx context.Context, tconn *chrome.TestConn, obj *chrome.JSObject) (*Node, error)

NewNode creates a new node struct and initializes its fields. NewNode takes ownership of obj and will release it if the node fails to initialize.

func Root

func Root(ctx context.Context, tconn *chrome.TestConn) (*Node, error)

Root returns the chrome.automation root as a Node. If the JavaScript fails to execute, an error is returned.

func (*Node) Children

func (n *Node) Children(ctx context.Context) (NodeSlice, error)

Children returns the children of the node. If the JavaScript fails to execute, an error is returned.

func (*Node) Descendant

func (n *Node) Descendant(ctx context.Context, params FindParams) (*Node, error)

Descendant finds the first descendant of this node matching the params and returns it. If the JavaScript fails to execute, an error is returned.

func (*Node) DescendantExists

func (n *Node) DescendantExists(ctx context.Context, params FindParams) (bool, error)

DescendantExists checks if a descendant of this node can be found. If the JavaScript fails to execute, an error is returned.

func (*Node) DescendantWithTimeout

func (n *Node) DescendantWithTimeout(ctx context.Context, params FindParams, timeout time.Duration) (*Node, error)

DescendantWithTimeout finds a descendant of this node using params and returns it. If the timeout is hit or the JavaScript fails to execute, an error is returned.

func (*Node) Descendants

func (n *Node) Descendants(ctx context.Context, params FindParams) (NodeSlice, error)

Descendants finds all descendant of this node matching the params and returns them. If the JavaScript fails to execute, an error is returned.

func (*Node) Matches

func (n *Node) Matches(ctx context.Context, params FindParams) (bool, error)

Matches returns whether this node matches the given params.

func (*Node) Release

func (n *Node) Release(ctx context.Context)

Release frees the reference to Javascript for this node.

func (*Node) ToString

func (n *Node) ToString(ctx context.Context) (string, error)

ToString returns string representation of node. If the JavaScript fails to execute, an error is returned.

func (*Node) WaitUntilDescendantExists

func (n *Node) WaitUntilDescendantExists(ctx context.Context, params FindParams, timeout time.Duration) error

WaitUntilDescendantExists checks if a descendant node exists repeatedly until the timeout. If the timeout is hit or the JavaScript fails to execute, an error is returned.

type NodeSlice

type NodeSlice []*Node

NodeSlice is a slice of pointers to nodes. It is used for releaseing a group of nodes.

func (NodeSlice) Release

func (nodes NodeSlice) Release(ctx context.Context)

Release frees the reference to Javascript for this node.

type OptionsExpectation

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

OptionsExpectation represents data for a speech expectation, where |expectation| is a string and expectedOptions is a SpeakOptions object with pitch, rate and lang.

func NewOptionsExpectation

func NewOptionsExpectation(utterance, lang string, pitch, rate float32) OptionsExpectation

NewOptionsExpectation is a convenience method for creating an OptionsExpectation object.

func (OptionsExpectation) String

func (oe OptionsExpectation) String() string

type RegexExpectation

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

RegexExpectation represents data for a speech expectation, where |expectation| is a regular expression.

func NewRegexExpectation

func NewRegexExpectation(expectation string) RegexExpectation

NewRegexExpectation is a convenience method for creating a RegexExpectation object.

type SpeakOptions

type SpeakOptions struct {
	Lang  string  `json:"lang"`
	Pitch float32 `json:"pitch"`
	Rate  float32 `json:"rate"`
}

SpeakOptions represents a chrome.tts.SpeakOptions. See: https://developer.chrome.com/docs/extensions/reference/ttsEngine/#type-SpeakOptions

type SpeechExpectation

type SpeechExpectation interface {
	// contains filtered or unexported methods
}

SpeechExpectation defines an interface for a speech expectation.

type SpeechMonitor

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

SpeechMonitor represents a connection to a TTS extension background page and is used to verify spoken utterances.

func RelevantSpeechMonitor

func RelevantSpeechMonitor(ctx context.Context, c *chrome.Chrome, tconn *chrome.TestConn, engineData TTSEngineData) (*SpeechMonitor, error)

RelevantSpeechMonitor searches through all possible connections to TTS background pages and returns a SpeechMonitor for the one that matches engineData. If no TTS background pages can be found, then all test connections will be closed before returning. Otherwise the calling function will close the connection.

func (*SpeechMonitor) Close

func (sm *SpeechMonitor) Close()

Close closes the connection to the TTS extension's background page.

func (*SpeechMonitor) Consume

func (sm *SpeechMonitor) Consume(ctx context.Context, expectations []SpeechExpectation) error

Consume ensures that the expectations were spoken by the TTS engine. It also consumes all utterances accumulated in TTS extension's background page. For each expectation we: 1. Shift the next spoken utterance off of testUtterances. This ensures that we never compare against stale utterances; a spoken utterance is either matched or discarded. 2. Check if the utterance matches the expectation.

type StringExpectation

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

StringExpectation represents data for a speech expectation, where |expectation| is a string.

func NewStringExpectation

func NewStringExpectation(expectation string) StringExpectation

NewStringExpectation is a convenience method for creating a StringExpectation object.

type TTSEngineData

type TTSEngineData struct {
	ExtID                     string
	UseOnSpeakWithAudioStream bool
}

TTSEngineData represents data for a TTS background page. ExtensionID specifies the ID of the background page. If |UseOnSpeakWithAudioStream| is true, we listen to onSpeakWithAudioStream when accumulating utterances. Otherwise, we listen to onSpeak.

type UtteranceData

type UtteranceData struct {
	Utterance string       `json:"utterance"`
	Options   SpeakOptions `json:"options"`
}

UtteranceData defines the data included in a Text to Speech utterance.

func (UtteranceData) String

func (ud UtteranceData) String() string

type VoiceData

type VoiceData struct {
	ExtID  string `json:"extensionId"`
	Locale string `json:"lang"`
	Name   string `json:"voiceName"`
}

VoiceData stores information necessary to identify TTS voices.

func Voices

func Voices(ctx context.Context, conn *chrome.TestConn) ([]VoiceData, error)

Voices returns the current TTS voices which are available.

Jump to

Keyboard shortcuts

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