cca

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: 34 Imported by: 0

Documentation

Overview

Package cca provides utilities to interact with Chrome Camera App.

Package cca provides utilities to interact with Chrome Camera App.

Package cca provides utilities to interact with Chrome Camera App.

Package cca provides utilities to interact with Chrome Camera App.

Package cca provides utilities to interact with Chrome Camera App.

Index

Constants

View Source
const (
	// ID is the app id of CCA.
	ID string = "hfhhnacclhffhdffklopdkcgdhifgngh"

	// Video is the mode used to record video.
	Video Mode = "video"
	// Photo is the mode used to take photo.
	Photo Mode = "photo"
	// Square is the mode used to take square photo.
	// TODO(b/215484798): Removed since there is no square mode in new UI.
	Square = "square"
	// Portrait is the mode used to take portrait photo.
	Portrait = "portrait"
	// Scan is the mode used to scan barcode/document.
	Scan = "scan"

	// Expert is the state used to indicate expert mode.
	Expert string = "expert"
	// SaveMetadata is the state used to indicate save metadata.
	SaveMetadata = "save-metadata"
)
View Source
const TimerDelay time.Duration = 3 * time.Second

TimerDelay is default timer delay of CCA.

Variables

View Source
var (
	// PhotoPattern is the filename format of photos taken by CCA.
	PhotoPattern = regexp.MustCompile(`^IMG_\d{8}_\d{6}[^.]*\.jpg$`)
	// VideoPattern is the filename format of videos recorded by CCA.
	VideoPattern = regexp.MustCompile(`^VID_\d{8}_\d{6}[^.]*\.mp4$`)

	// DocumentPDFPattern is the filename format of the document PDF file.
	DocumentPDFPattern = regexp.MustCompile(`^SCN_\d{8}_\d{6}[^.]*\.pdf$`)
	// DocumentPhotoPattern is the filename format of the document photo file.
	DocumentPhotoPattern = regexp.MustCompile(`^SCN_\d{8}_\d{6}[^.]*\.jpg$`)
	// ErrVideoNotActive indicates that video is not active.
	ErrVideoNotActive = "Video is not active within given time"
)
View Source
var (
	// ProfileH264Baseline is h264 baseline profile.
	ProfileH264Baseline = Profile{"baseline", 66}
	// ProfileH264Main is h264 main profile.
	ProfileH264Main = Profile{"main", 77}
	// ProfileH264High is h264 high profile.
	ProfileH264High = Profile{"high", 100}
)
View Source
var (
	// FirstBlack is the first black pixel met when scans frame pixels from first to last row.
	FirstBlack = PixelTarget{`function() {
		const {width, height} = this.canvas;
		const {data} = this.getImageData(0, 0, width, height);
		let idx = 0;
		for (let y = 0 ; y < height ; y ++) {
			for (let x = 0 ; x < width ; x ++) {
				if (data[idx] === 0) {
					return {x, y};
				}
				idx += 4;
			}
		}
		throw new Error('Cannot find point');
	}`}
	// LastBlack is the last black pixel met when scans frame pixels from first to last row.
	LastBlack = PixelTarget{`function() {
		const {width, height} = this.canvas;
		const {data} = this.getImageData(0, 0, width, height);
		let idx = data.length - 4;
		for (let y = height-1 ; y >= 0 ; y --) {
			for (let x = width-1 ; x >= 0 ; x --) {
				if (data[idx] === 0) {
					return {x, y};
				}
				idx -= 4;
			}
		}
		throw new Error('Cannot find point');
	}`}
)
View Source
var (
	// MainMenu is the main setting menu.
	MainMenu = &SettingMenu{"view-settings", &SettingsButton}
	// GridTypeMenu is the grid settings menu.
	GridTypeMenu = &SettingMenu{"view-grid-settings", &GridTypeSettingsButton}
	// TimerMenu is the timer settings menu.
	TimerMenu = &SettingMenu{"view-timer-settings", &TimerSettingsButton}
	// ResolutionMenu is the resolution settings menu.
	ResolutionMenu = &SettingMenu{"view-resolution-settings", &ResolutionSettingButton}
	// PhotoResolutionMenu is the photo resolution settings menu.
	PhotoResolutionMenu = &SettingMenu{"view-photo-resolution-settings", &PhotoResolutionSettingButton}
	// PhotoAspectRatioMenu is the photo aspect ratio settings menu.
	PhotoAspectRatioMenu = &SettingMenu{"view-photo-aspect-ratio-settings", &PhotoAspectRatioSettingButton}
	// VideoResolutionMenu is the video resolution settings menu.
	VideoResolutionMenu = &SettingMenu{"view-video-resolution-settings", &VideoResolutionSettingButton}
	// ExpertMenu is the expert settings menu.
	ExpertMenu = &SettingMenu{"view-expert-settings", &ExpertModeButton}
)
View Source
var (
	// CancelResultButton is button for canceling intent review result.
	CancelResultButton = UIComponent{"cancel result button", []string{"#cancel-result", "button[i18n-label=cancel_review_button]"}}
	// ConfirmResultButton is button for confirming intent review result.
	ConfirmResultButton = UIComponent{"confirm result button", []string{"#confirm-result", "button[i18n-label=confirm_review_button]"}}
	// MirrorButton is button used for toggling preview mirroring option.
	MirrorButton = UIComponent{"mirror button", []string{"#toggle-mirror"}}
	// ModeSelector is selection bar for different capture modes.
	ModeSelector = UIComponent{"mode selector", []string{"#modes-group"}}
	// SettingsButton is button for opening primary setting menu.
	SettingsButton = UIComponent{"settings", []string{"#open-settings"}}
	// SwitchDeviceButton is button for switching camera device.
	SwitchDeviceButton = UIComponent{"switch device button", []string{"#switch-device"}}
	// VideoSnapshotButton is button for taking video snapshot during recording.
	VideoSnapshotButton = UIComponent{"video snapshot button", []string{"#video-snapshot"}}
	// VideoPauseResumeButton is button for pausing or resuming video recording.
	VideoPauseResumeButton = UIComponent{"video pause/resume button", []string{"#pause-recordvideo"}}
	// GalleryButton is button for entering the Backlight app as a gallery for captured files.
	GalleryButton = UIComponent{"gallery button", []string{"#gallery-enter"}}
	// GalleryButtonCover is cover photo of gallery button.
	GalleryButtonCover = UIComponent{"gallery button cover", []string{"#gallery-enter>img"}}

	// PhotoResolutionSettingButton is button for opening photo resolution setting menu.
	PhotoResolutionSettingButton = UIComponent{"photo resolution setting button", []string{"#settings-photo-resolution"}}
	// PhotoAspectRatioSettingButton is button for opening photo aspect ratio setting menu.
	PhotoAspectRatioSettingButton = UIComponent{"photo aspect ratio setting button", []string{"#settings-photo-aspect-ratio"}}
	// VideoResolutionSettingButton is button for opening video resolution setting menu.
	VideoResolutionSettingButton = UIComponent{"video resolution setting button", []string{"#settings-video-resolution"}}

	// ResolutionSettingButton is button for opening resolution setting menu.
	ResolutionSettingButton = UIComponent{"resolution setting button", []string{"#settings-resolution"}}
	// ExpertModeButton is button used for opening expert mode setting menu.
	ExpertModeButton = UIComponent{"expert mode button", []string{"#settings-expert"}}
	// PhotoResolutionOption is option for each available photo capture resolution.
	PhotoResolutionOption = UIComponent{"photo resolution option", []string{
		"#view-photo-resolution-settings input"}}
	// VideoResolutionOption is option for each available video capture resolution.
	VideoResolutionOption = UIComponent{"video resolution option", []string{
		"#view-video-resolution-settings input"}}
	// FeedbackButton is the feedback button showing in the settings menu.
	FeedbackButton = UIComponent{"feedback button", []string{"#settings-feedback"}}
	// HelpButton is the help button showing in the settings menu.
	HelpButton = UIComponent{"help button", []string{"#settings-help"}}
	// GridTypeSettingsButton is the button showing in the settings menu which is used for entering the grid type settings menu.
	GridTypeSettingsButton = UIComponent{"grid type settings button", []string{"#settings-gridtype"}}
	// GoldenGridButton is the button to enable golden grid type.
	GoldenGridButton = UIComponent{"golden grid type button", []string{"#grid-golden"}}
	// TimerSettingsButton is the button showing in the settings menu which is used for entering the timer settings menu.
	TimerSettingsButton = UIComponent{"timer settings button", []string{"#settings-timerdur"}}
	// Timer10sButton is the button to enable 10s timer.
	Timer10sButton = UIComponent{"timer 10s button", []string{"#timer-10s"}}

	// BarcodeChipURL is chip for url detected from barcode.
	BarcodeChipURL = UIComponent{"barcode chip url", []string{".barcode-chip-url a"}}
	// BarcodeChipText is chip for text detected from barcode.
	BarcodeChipText = UIComponent{"barcode chip text", []string{".barcode-chip-text"}}
	// BarcodeCopyURLButton is button to copy url detected from barcode.
	BarcodeCopyURLButton = UIComponent{"barcode copy url button",
		[]string{"#barcode-chip-url-container .barcode-copy-button"}}
	// BarcodeCopyTextButton is button to copy text detected from barcode.
	BarcodeCopyTextButton = UIComponent{"barcode copy text button",
		[]string{"#barcode-chip-text-container .barcode-copy-button"}}

	// VideoProfileSelect is select-options for selecting video profile.
	VideoProfileSelect = UIComponent{"video profile select", []string{"#video-profile"}}
	// BitrateMultiplierRangeInput is range input for selecting bitrate multiplier.
	BitrateMultiplierRangeInput = UIComponent{"bitrate multiplier range input", []string{"#bitrate-slider input[type=range]"}}

	// OptionsContainer is the container for all options for opening option panel.
	OptionsContainer = UIComponent{"container of options", []string{"#options-container"}}
	// OpenMirrorPanelButton is the button which is used for opening the mirror state settings panel.
	OpenMirrorPanelButton = UIComponent{"mirror state option button", []string{"#open-mirror-panel"}}
	// OpenGridPanelButton is the button which is used for opening the grid type settings panel.
	OpenGridPanelButton = UIComponent{"grid type option button", []string{"#open-grid-panel"}}
	// OpenTimerPanelButton is the button which is used for opening the timer type settings panel.
	OpenTimerPanelButton = UIComponent{"timer type option button", []string{"#open-timer-panel"}}
	// OpenPTZPanelButton is the button for opening PTZ panel.
	OpenPTZPanelButton = UIComponent{"open ptz panel button", []string{"#open-ptz-panel"}}
	// PanLeftButton is the button for panning left preview.
	PanLeftButton = UIComponent{"pan left button", []string{"#pan-left"}}
	// PanRightButton is the button for panning right preview.
	PanRightButton = UIComponent{"pan right button", []string{"#pan-right"}}
	// TiltUpButton is the button for tilting up preview.
	TiltUpButton = UIComponent{"tilt up button", []string{"#tilt-up"}}
	// TiltDownButton is the button for tilting down preview.
	TiltDownButton = UIComponent{"tilt down button", []string{"#tilt-down"}}
	// ZoomInButton is the button for zoom in preview.
	ZoomInButton = UIComponent{"zoom in button", []string{"#zoom-in"}}
	// ZoomOutButton is the button for zoom out preview.
	ZoomOutButton = UIComponent{"zoom out button", []string{"#zoom-out"}}
	// PTZResetAllButton is the button for reset PTZ to default value.
	PTZResetAllButton = UIComponent{"ptz reset all button", []string{"#ptz-reset-all"}}

	// SquareModeButton is the button to enter square mode.
	SquareModeButton = UIComponent{"square mode button", []string{".mode-item>input[data-mode=\"square\"]"}}
	// ScanModeButton is the button to enter scan mode.
	ScanModeButton = UIComponent{"scan mode button", []string{".mode-item>input[data-mode=\"scan\"]"}}
	// ScanBarcodeOption is the option button to switch to QR code detection mode in scan mode.
	ScanBarcodeOption = UIComponent{"scan barcode option", []string{"#scan-barcode"}}
	// ScanDocumentModeOption is the document mode option of scan mode.
	ScanDocumentModeOption = UIComponent{"document mode button", []string{"#scan-document"}}
	// ReviewView is the review view after taking a photo under document mode.
	ReviewView = UIComponent{"document review view", []string{"#view-review"}}
	// ReviewImage is the image to be reviewed.
	ReviewImage = UIComponent{"reivew image", []string{"#view-review .review-image"}}
	// SaveAsPDFButton is the button to save document as PDF.
	SaveAsPDFButton = UIComponent{"save document as pdf button", []string{"#view-review button[i18n-text=label_save_pdf_document]"}}
	// SaveAsPhotoButton is the button to save document as photo.
	SaveAsPhotoButton = UIComponent{"save document as photo button", []string{"#view-review button[i18n-text=label_save_photo_document]"}}
	// RetakeButton is the button to retake the document photo.
	RetakeButton = UIComponent{"retake document photo button", []string{

		"#review-retake", "#view-review button[i18n-text=label_retake]"}}
	// FixCropButton is the button to fix document crop area.
	FixCropButton = UIComponent{"fix document crop area button", []string{"#view-review button[i18n-text=label_fix_document]"}}
	// CropDocumentView is the view for fix document crop area.
	CropDocumentView = UIComponent{"crop document view", []string{"#view-crop-document"}}
	// CropDocumentImage is the image to be cropped document from.
	CropDocumentImage = UIComponent{"crop document image", []string{"#view-crop-document .review-image"}}
	// CropDoneButton is the button clicked after fix document crop area.
	CropDoneButton = UIComponent{"crop document done button", []string{"#view-crop-document button[i18n-text=label_crop_done]"}}
	// DocumentCorner is the dragging point of document corner in crop area page.
	DocumentCorner = UIComponent{"document corner dragging point", []string{"#view-crop-document .dot"}}
	// DocumentCornerOverlay is the overlay that CCA used to draw document corners on.
	DocumentCornerOverlay = UIComponent{"document corner overlay", []string{
		"#preview-document-corner-overlay"}}

	// GifRecordingOption is the radio button to toggle gif recording option.
	GifRecordingOption = UIComponent{"gif recording button", []string{
		"input[type=radio][data-state=record-type-gif]"}}
	// GifReviewSaveButton is the save button in gif review page.
	GifReviewSaveButton = UIComponent{"save gif button", []string{
		"#view-review button[i18n-text=label_save]"}}
	// GifReviewRetakeButton is the retake button in gif review page.
	GifReviewRetakeButton = UIComponent{"retake gif button", []string{"#review-retake"}}

	// FrontAspectRatioOptions are the buttons of aspect ratio options for the front camera.
	FrontAspectRatioOptions = UIComponent{"front aspect ratio options", []string{"#view-photo-aspect-ratio-settings .menu-item>input[data-facing=\"user\"]"}}
	// BackAspectRatioOptions are the buttons of aspect ratio options for the back camera.
	BackAspectRatioOptions = UIComponent{"back aspect ratio options", []string{"#view-photo-aspect-ratio-settings .menu-item>input[data-facing=\"environment\"]"}}
	// FrontPhotoResolutionOptions are the buttons of photo resolution options for the front camera.
	FrontPhotoResolutionOptions = UIComponent{"front photo resolution options", []string{"#view-photo-resolution-settings .menu-item>input[data-facing=\"user\"]"}}
	// BackPhotoResolutionOptions are the buttons of photo resolution options for the back camera.
	BackPhotoResolutionOptions = UIComponent{"back photo resolution options", []string{"#view-photo-resolution-settings .menu-item>input[data-facing=\"environment\"]"}}
	// FrontVideoResolutionOptions are the buttons of video resolution options for the front camera.
	FrontVideoResolutionOptions = UIComponent{"front video resolution options", []string{"#view-video-resolution-settings .menu-item>input[data-facing=\"user\"]"}}
	// BackVideoResolutionOptions are the buttons of video resolution options for the back camera.
	BackVideoResolutionOptions = UIComponent{"back video resolution options", []string{"#view-video-resolution-settings .menu-item>input[data-facing=\"environment\"]"}}
)
View Source
var (
	// CustomVideoParametersOption is the option to enable custom video parameters.
	CustomVideoParametersOption = newOption("custom-video-parameters", "#custom-video-parameters")
	// ExpertModeOption is the option to enable expert mode.
	ExpertModeOption = newOption("expert", "#expert-enable-expert-mode")
	// GridOption is the option to show grid lines on preview.
	GridOption = newOption("grid", "#toggle-grid")
	// MirrorOption is the option to flip preview horizontally.
	MirrorOption = newOption("mirror", "#toggle-mirror")
	// SaveMetadataOption is the option to save metadata of capture result.
	SaveMetadataOption = newOption("save-metadata", "#expert-save-metadata")
	// ShowMetadataOption is the option to show preview metadata.
	ShowMetadataOption = newOption("show-metadata", "#expert-show-metadata")
	// EnableDocumentModeOnAllCamerasOption is the option to enable document scanning on all cameras.
	EnableDocumentModeOnAllCamerasOption = newOption("enable-document-mode-on-all-cameras", "#expert-enable-document-mode-on-all-cameras")
	// EnableMultistreamRecordingOption is the option to enable document scanning on all cameras.
	EnableMultistreamRecordingOption = newOption("enable-multistream-recording", "#expert-enable-multistream-recording")
	// ScanBarcodeOptionInPhotoMode is the option to enable barcode scanning in photo mode.
	ScanBarcodeOptionInPhotoMode = newOption("enable-scan-barcode", "#toggle-barcode")
	// ShowGifRecordingOption is the option to enable gif recording.
	ShowGifRecordingOption = newOption("show-gif-recording-option", "#expert-enable-gif-recording")
	// TimerOption is the option to enable countdown timer.
	TimerOption = newOption("timer", "#toggle-timer")
)

Functions

func CheckVideoProfile

func CheckVideoProfile(path string, profile Profile) error

CheckVideoProfile checks profile of video file recorded by CCA.

func ClearSavedDir

func ClearSavedDir(ctx context.Context, cr *chrome.Chrome) error

ClearSavedDir clears all files in the folder where captured files might be saved.

func InstanceExists

func InstanceExists(ctx context.Context, cr *chrome.Chrome) (bool, error)

InstanceExists checks if there is any running CCA instance.

func IsUINotExist

func IsUINotExist(err error) bool

IsUINotExist returns true if the given error is from errorUINotExist error type.

func MeasureGifRecordingPerformance

func MeasureGifRecordingPerformance(ctx context.Context, app *App) error

MeasureGifRecordingPerformance records a gif and measure the performance of UI operations.

func MeasurePreviewPerformance

func MeasurePreviewPerformance(ctx context.Context, app *App, perfData *PerfData, facing Facing) error

MeasurePreviewPerformance measures the performance of preview with QR code detection on and off.

func MeasureRecordingPerformance

func MeasureRecordingPerformance(ctx context.Context, app *App, perfData *PerfData, facing Facing) error

MeasureRecordingPerformance measures the performance of video recording.

func MeasureTakingPicturePerformance

func MeasureTakingPicturePerformance(ctx context.Context, app *App) error

MeasureTakingPicturePerformance takes a picture and measure the performance of UI operations.

func RunPortraitModeTesting

func RunPortraitModeTesting(ctx context.Context, scriptPaths []string, outDir string, facing Facing) (retErr error)

RunPortraitModeTesting tests that portrait mode works expectedly.

Types

type App

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

App represents a CCA (Chrome Camera App) instance.

func Init

func Init(ctx context.Context, cr *chrome.Chrome, scriptPaths []string, outDir string, appLauncher testutil.AppLauncher, tb *testutil.TestBridge) (_ *App, retErr error)

Init launches a CCA instance, evaluates the helper script within it and waits until its AppWindow interactable. The scriptPath should be the data path to the helper script cca_ui.js. The returned App instance must be closed when the test is finished.

func New

func New(ctx context.Context, cr *chrome.Chrome, scriptPaths []string, outDir string, tb *testutil.TestBridge) (*App, error)

New launches a CCA instance. The returned App instance must be closed when the test is finished.

func (*App) AttributeWithIndex

func (a *App) AttributeWithIndex(ctx context.Context, ui UIComponent, index int, attr string) (string, error)

AttributeWithIndex returns the attr attribute of the index th ui.

func (*App) CheckCameraFacing

func (a *App) CheckCameraFacing(ctx context.Context, facing Facing) error

CheckCameraFacing checks whether CCA is in correct facing if there's a camera with that facing.

func (*App) CheckConfirmUIExists

func (a *App) CheckConfirmUIExists(ctx context.Context, mode Mode) error

CheckConfirmUIExists returns whether the confirm UI exists.

func (*App) CheckFacing

func (a *App) CheckFacing(ctx context.Context, expected Facing) error

CheckFacing returns an error if the active camera facing is not expected.

func (*App) CheckGridOption

func (a *App) CheckGridOption(ctx context.Context, expected bool) error

CheckGridOption checks whether grid option enable state is as expected.

func (*App) CheckMetadataVisibility

func (a *App) CheckMetadataVisibility(ctx context.Context, enabled bool) error

CheckMetadataVisibility checks if metadata is shown/hidden on screen given enabled.

func (*App) CheckMode

func (a *App) CheckMode(ctx context.Context, mode Mode) error

CheckMode checks whether CCA window is in correct capture mode.

func (*App) CheckMojoConnection

func (a *App) CheckMojoConnection(ctx context.Context) error

CheckMojoConnection checks if mojo connection works.

func (*App) CheckVideoInactive

func (a *App) CheckVideoInactive(ctx context.Context) error

CheckVideoInactive checks the video is inactive for 1 second.

func (*App) CheckVisible

func (a *App) CheckVisible(ctx context.Context, ui UIComponent, expected bool) error

CheckVisible returns an error if visibility state of ui is not expected.

func (*App) Click

func (a *App) Click(ctx context.Context, ui UIComponent) error

Click clicks on ui.

func (*App) ClickChildIfContain

func (a *App) ClickChildIfContain(ctx context.Context, ui UIComponent, text string) error

ClickChildIfContain clicks the child which contains the given string in its text content.

func (*App) ClickPTZButton

func (a *App) ClickPTZButton(ctx context.Context, ui UIComponent) error

ClickPTZButton clicks on PTZ Button.

func (*App) ClickShutter

func (a *App) ClickShutter(ctx context.Context) error

ClickShutter clicks the shutter button.

func (*App) ClickWithIndex

func (a *App) ClickWithIndex(ctx context.Context, ui UIComponent, index int) error

ClickWithIndex clicks nth ui.

func (*App) ClickWithSelector

func (a *App) ClickWithSelector(ctx context.Context, selector string) error

ClickWithSelector clicks an element with given selector.

func (*App) Close

func (a *App) Close(ctx context.Context) error

Close closes the App and the associated connection.

func (*App) CloseWithDebugParams

func (a *App) CloseWithDebugParams(ctx context.Context, params DebugParams) (retErr error)

CloseWithDebugParams closes the App and the associated connection with the debug parameters.

func (*App) ClosingItself

func (a *App) ClosingItself(ctx context.Context) (bool, error)

ClosingItself checks if CCA intends to close itself.

func (*App) CollectPerfEvents

func (a *App) CollectPerfEvents(ctx context.Context, perfData *PerfData) error

CollectPerfEvents returns a map containing all perf events collected since app launch. The returned map maps from event name to a list of durations for each time that event happened.

func (*App) ConfirmResult

func (a *App) ConfirmResult(ctx context.Context, isConfirmed bool, mode Mode) error

ConfirmResult clicks the confirm button or the cancel button according to the given isConfirmed.

func (*App) CountUI

func (a *App) CountUI(ctx context.Context, ui UIComponent) (int, error)

CountUI returns the number of ui element.

func (*App) DisableQRCodeDetection

func (a *App) DisableQRCodeDetection(ctx context.Context) error

DisableQRCodeDetection disables the QR code detection.

func (*App) Disabled

func (a *App) Disabled(ctx context.Context, ui UIComponent) (bool, error)

Disabled returns disabled attribute of HTMLElement of |ui|.

func (*App) EnableDocumentMode

func (a *App) EnableDocumentMode(ctx context.Context) error

EnableDocumentMode enables the document mode via expert mode.

func (*App) EnableExpertMode

func (a *App) EnableExpertMode(ctx context.Context) error

EnableExpertMode enables expert mode.

func (*App) EnableQRCodeDetection

func (a *App) EnableQRCodeDetection(ctx context.Context) error

EnableQRCodeDetection enables the QR code detection.

func (*App) EnsureTabletModeEnabled

func (a *App) EnsureTabletModeEnabled(ctx context.Context, enabled bool) (func(ctx context.Context) error, error)

EnsureTabletModeEnabled makes sure that the tablet mode states of both device and app are enabled, and returns a function which reverts back to the original state.

func (*App) Exist

func (a *App) Exist(ctx context.Context, ui UIComponent) (bool, error)

Exist returns whether a UI component exists.

func (*App) FilePathInSavedDir

func (a *App) FilePathInSavedDir(ctx context.Context, name string) (string, error)

FilePathInSavedDir finds and returns the path of the target file in saved directory.

func (*App) Focus

func (a *App) Focus(ctx context.Context) error

Focus sets focus on CCA App window.

func (*App) FullscreenWindow

func (a *App) FullscreenWindow(ctx context.Context) error

FullscreenWindow fullscreens the window.

func (*App) GetDeviceID

func (a *App) GetDeviceID(ctx context.Context) (DeviceID, error)

GetDeviceID returns the active camera device id.

func (*App) GetFacing

func (a *App) GetFacing(ctx context.Context) (Facing, error)

GetFacing returns the active camera facing.

func (*App) GetNumOfCameras

func (a *App) GetNumOfCameras(ctx context.Context) (int, error)

GetNumOfCameras returns number of camera devices.

func (*App) GetPhotoResolutions

func (a *App) GetPhotoResolutions(ctx context.Context) ([]Resolution, error)

GetPhotoResolutions returns available photo resolutions of active camera on HALv3 device.

func (*App) GetPreviewResolution

func (a *App) GetPreviewResolution(ctx context.Context) (Resolution, error)

GetPreviewResolution returns resolution of preview video.

func (*App) GetPreviewViewportSize

func (a *App) GetPreviewViewportSize(ctx context.Context) (Resolution, error)

GetPreviewViewportSize returns resolution of the preview view port.

func (*App) GetScreenOrientation

func (a *App) GetScreenOrientation(ctx context.Context) (Orientation, error)

GetScreenOrientation returns screen orientation.

func (*App) GetVideoResolutions

func (a *App) GetVideoResolutions(ctx context.Context) ([]Resolution, error)

GetVideoResolutions returns available video resolutions of active camera on HALv3 device.

func (*App) HasClass

func (a *App) HasClass(ctx context.Context, ui UIComponent, className string) (bool, error)

HasClass returns true if the given HTML element has the given class name.

func (*App) Hold

func (a *App) Hold(ctx context.Context, ui UIComponent, d time.Duration) error

Hold holds on |ui| by sending pointerdown and pointerup for |d| duration.

func (*App) InnerResolutionSetting

func (a *App) InnerResolutionSetting(ctx context.Context, facing Facing, rt ResolutionType) (*SettingMenu, error)

InnerResolutionSetting returns setting menu for toggle |rt| resolution of |facing| camera.

func (*App) InputRange

func (a *App) InputRange(ctx context.Context, ui UIComponent) (*Range, error)

InputRange returns the range of valid value for range type input element.

func (*App) IsCheckedWithIndex

func (a *App) IsCheckedWithIndex(ctx context.Context, ui UIComponent, index int) (bool, error)

IsCheckedWithIndex gets checked state of nth ui.

func (*App) IsWindowMinimized

func (a *App) IsWindowMinimized(ctx context.Context) (bool, error)

IsWindowMinimized returns true if the current app window is minimized.

func (*App) MaximizeWindow

func (a *App) MaximizeWindow(ctx context.Context) error

MaximizeWindow maximizes the window.

func (*App) MinimizeWindow

func (a *App) MinimizeWindow(ctx context.Context) error

MinimizeWindow minimizes the window.

func (*App) Mirrored

func (a *App) Mirrored(ctx context.Context) (bool, error)

Mirrored returns whether mirroring is on.

func (*App) OptionExist

func (a *App) OptionExist(ctx context.Context, option Option) (bool, error)

OptionExist returns if the option exists.

func (*App) OutputCodeCoverage

func (a *App) OutputCodeCoverage(ctx context.Context) error

OutputCodeCoverage stops the profiling and output the code coverage information to the output directory.

func (*App) PortraitModeSupported

func (a *App) PortraitModeSupported(ctx context.Context) (bool, error)

PortraitModeSupported returns whether portrait mode is supported by the current active video device.

func (*App) PreviewFrame

func (a *App) PreviewFrame(ctx context.Context) (*Frame, error)

PreviewFrame grabs a frame from preview. The caller should be responsible for releasing the frame.

func (*App) RecordGif

func (a *App) RecordGif(ctx context.Context, save bool) (os.FileInfo, error)

RecordGif records a gif with maximal duration and |save| specify whether to save result gif in review page.

func (*App) RecordVideo

func (a *App) RecordVideo(ctx context.Context, timerState TimerState, duration time.Duration) (os.FileInfo, error)

RecordVideo records a video with duration length and save to default location.

func (*App) Refresh

func (a *App) Refresh(ctx context.Context, tb *testutil.TestBridge) error

Refresh refreshes CCA.

func (*App) Restart

func (a *App) Restart(ctx context.Context, tb *testutil.TestBridge) error

Restart restarts the App and resets the associated connection.

func (*App) RestoreWindow

func (a *App) RestoreWindow(ctx context.Context) error

RestoreWindow restores the window, exiting a maximized, minimized, or fullscreen state.

func (*App) RunThroughCameras

func (a *App) RunThroughCameras(ctx context.Context, f func(Facing) error) error

RunThroughCameras runs function f in app after switching to each available camera. The f is called with paramter of the switched camera facing. The error returned by f is passed to caller of this function.

func (*App) SaveCameraFolder

func (a *App) SaveCameraFolder(ctx context.Context) error

SaveCameraFolder saves the camera folder to the output directory to make debug easier.

func (*App) SaveScreenshot

func (a *App) SaveScreenshot(ctx context.Context) error

SaveScreenshot saves a screenshot in the outDir.

func (*App) SavedDir

func (a *App) SavedDir(ctx context.Context) (string, error)

SavedDir returns the path to the folder where captured files are saved.

func (*App) ScreenXYWithIndex

func (a *App) ScreenXYWithIndex(ctx context.Context, ui UIComponent, index int) (*coords.Point, error)

ScreenXYWithIndex returns the screen coordinates of the left-top corner of the |index|'th |ui|.

func (*App) SelectOption

func (a *App) SelectOption(ctx context.Context, ui UIComponent, value string) error

SelectOption selects the target option in HTMLSelectElement.

func (*App) SetEnableMultiStreamRecording

func (a *App) SetEnableMultiStreamRecording(ctx context.Context, enabled bool) error

SetEnableMultiStreamRecording enables/disables recording videos with multiple streams via expert mode.

func (*App) SetRangeInput

func (a *App) SetRangeInput(ctx context.Context, ui UIComponent, value int) error

SetRangeInput set value of range input.

func (*App) SetTimerOption

func (a *App) SetTimerOption(ctx context.Context, state TimerState) error

SetTimerOption sets the timer option to on/off.

func (*App) Size

func (a *App) Size(ctx context.Context, ui UIComponent) (*Resolution, error)

Size returns size of the |ui|.

func (*App) StartRecording

func (a *App) StartRecording(ctx context.Context, timerState TimerState) (time.Time, error)

StartRecording starts recording a video.

func (*App) State

func (a *App) State(ctx context.Context, state string) (bool, error)

State returns whether a state is active in CCA.

func (*App) StopRecording

func (a *App) StopRecording(ctx context.Context, timerState TimerState, startTime time.Time) (os.FileInfo, time.Time, error)

StopRecording stops recording a video.

func (*App) Style

func (a *App) Style(ctx context.Context, ui UIComponent, attribute string) (string, error)

Style returns the value of an CSS attribute of an UI component.

func (*App) SwitchCamera

func (a *App) SwitchCamera(ctx context.Context) error

SwitchCamera switches to next camera device.

func (*App) SwitchMode

func (a *App) SwitchMode(ctx context.Context, mode Mode) error

SwitchMode switches to specified capture mode.

func (*App) TakeSinglePhoto

func (a *App) TakeSinglePhoto(ctx context.Context, timerState TimerState) ([]os.FileInfo, error)

TakeSinglePhoto takes a photo and save to default location.

func (*App) ToggleExpertMode

func (a *App) ToggleExpertMode(ctx context.Context) (bool, error)

ToggleExpertMode toggles expert mode and returns whether it's enabled after toggling.

func (*App) ToggleOption

func (a *App) ToggleOption(ctx context.Context, option Option) (bool, error)

ToggleOption toggles on/off of the |option|.

func (*App) TriggerConfiguration

func (a *App) TriggerConfiguration(ctx context.Context, trigger func() error) error

TriggerConfiguration triggers configuration by calling trigger() and waits for camera configuration finishing.

func (*App) TriggerStateChange

func (a *App) TriggerStateChange(ctx context.Context, state string, expected bool, trigger func() error) (time.Time, error)

TriggerStateChange triggers |state| change by calling |trigger()|, waits for its value changing from |!expected| to |expected| and returns when the change happens.

func (*App) Visible

func (a *App) Visible(ctx context.Context, ui UIComponent) (bool, error)

Visible returns whether a UI component is visible on the screen.

func (*App) WaitForDisabled

func (a *App) WaitForDisabled(ctx context.Context, ui UIComponent, expected bool) error

WaitForDisabled waits until the disabled state of ui becomes |expected|.

func (*App) WaitForFileSaved

func (a *App) WaitForFileSaved(ctx context.Context, dir string, pat *regexp.Regexp, ts time.Time) (os.FileInfo, error)

WaitForFileSaved waits for the presence of the captured file with file name matching the specified pattern, size larger than zero, and modified time after the specified timestamp.

func (*App) WaitForMinimized

func (a *App) WaitForMinimized(ctx context.Context, minimized bool) error

WaitForMinimized waits for app window to be minimized/restored.

func (*App) WaitForState

func (a *App) WaitForState(ctx context.Context, state string, active bool) error

WaitForState waits until state become active/inactive.

func (*App) WaitForVideoActive

func (a *App) WaitForVideoActive(ctx context.Context) error

WaitForVideoActive waits for the video to become active for 1 second.

func (*App) WaitForVisibleState

func (a *App) WaitForVisibleState(ctx context.Context, ui UIComponent, expected bool) error

WaitForVisibleState waits until the visibility of ui becomes expected.

type DebugParams

type DebugParams struct {
	SaveScreenshotWhenFail   bool
	SaveCameraFolderWhenFail bool
}

DebugParams defines some useful flags for debug CCA tests.

type DeviceID

type DeviceID string

DeviceID is video device id from JavaScript navigator.mediaDevices.enumerateDevices.

type ErrJS

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

ErrJS represents an error occurs when executing JavaScript.

func (*ErrJS) Error

func (e *ErrJS) Error() string

Error returns the wrapped message of a ErrJS.

type Facing

type Facing string

Facing is camera facing from JavaScript VideoFacingModeEnum.

const (
	// FacingBack is the constant string from JavaScript VideoFacingModeEnum.
	FacingBack Facing = "environment"
	// FacingFront is the constant string from JavaScript VideoFacingModeEnum.
	FacingFront Facing = "user"
	// FacingExternal is the constant string indicating external camera facing.
	FacingExternal Facing = "external"
)

type FixtureData

type FixtureData struct {
	Chrome     *chrome.Chrome
	ARC        *arc.ARC
	TestBridge func() *testutil.TestBridge
	// App returns the CCA instance which lives through the test.
	App func() *App
	// ResetChrome resets chrome used by this fixture.
	ResetChrome ResetChromeFunc
	// StartApp starts CCA which can be used between subtests.
	StartApp StartAppFunc
	// StopApp stops CCA which can be used between subtests.
	StopApp StopAppFunc
	// ResetTestBridgeFunc resets the test bridge. Usually we don't need to call
	// it explicitly unless the sub test launch/tear-down the app itself.
	ResetTestBridge ResetTestBridgeFunc
	// SwitchScene switches the camera scene to the given scene. This only works
	// for fixtures using fake camera stream.
	SwitchScene func(string) error
	// RunTestWithApp runs the given function with the handling of the app
	// start/stop.
	RunTestWithApp func(context.Context, TestWithAppFunc, TestWithAppParams) error
	// PrepareChart prepares chart by loading the given scene. It only works for
	// CameraBox.
	PrepareChart func(ctx context.Context, addr, keyFile, contentPath string) error
	// SetDebugParams sets the debug parameters for current test.
	SetDebugParams func(params DebugParams)
}

FixtureData is the struct exposed to tests.

type Frame

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

Frame is the frame grabbed from preview.

func (*Frame) Find

func (f *Frame) Find(ctx context.Context, t *PixelTarget) (*image.Point, error)

Find finds pixel location in the frame.

func (*Frame) Release

func (f *Frame) Release(ctx context.Context) error

Release releases the JSObject within the frame.

type Mode

type Mode string

Mode is capture mode in CCA.

type Option

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

Option is the option for toggling state.

type Orientation

type Orientation string

Orientation is the screen orientation from JavaScript window.screen.orientation.type.

const (
	// PortraitPrimary is the primary portrait orientation.
	PortraitPrimary Orientation = "portrait-primary"
	// PortraitSecondary is the secondary portrait orientation.
	PortraitSecondary Orientation = "portrait-secondary"
	// LandscapePrimary is the primary landscape orientation.
	LandscapePrimary Orientation = "landscape-primary"
	// LandscapeSecondary is the secondary landscape orientation.
	LandscapeSecondary Orientation = "landscape-secondary"
)

type PerfData

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

PerfData saves performance record collected by performance test.

func NewPerfData

func NewPerfData() *PerfData

NewPerfData creates new PerfData instance.

func (*PerfData) Save

func (p *PerfData) Save(outDir string) error

Save saves perf data into output directory.

func (*PerfData) SetDuration

func (p *PerfData) SetDuration(name string, duration float64)

SetDuration sets perf event name and the duration that event takes.

func (*PerfData) SetMetricValue

func (p *PerfData) SetMetricValue(m perf.Metric, value float64)

SetMetricValue sets the metric and the corresponding value.

type PixelTarget

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

PixelTarget specifies the target pixel to be found in frame.

type Profile

type Profile struct {
	Name  string
	Value int
}

Profile is type of encoder profile.

func (Profile) Option

func (p Profile) Option() string

Option returns the value of corresponding select-option.

type Range

type Range struct {
	Max int `json:"max"`
	Min int `json:"min"`
}

Range represents valid range of range type input element.

type ResetChromeFunc

type ResetChromeFunc func(context.Context) error

ResetChromeFunc reset chrome used in this fixture.

type ResetTestBridgeFunc

type ResetTestBridgeFunc func(context.Context) error

ResetTestBridgeFunc resets the test bridge.

type Resolution

type Resolution struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Resolution represents dimension of video or photo.

func (*Resolution) AspectRatio

func (r *Resolution) AspectRatio() float64

AspectRatio returns width divided by height as the aspect ratio of the resolution.

type ResolutionType

type ResolutionType string

ResolutionType is different capture resolution type.

const (
	// PhotoResolution represents photo resolution type.
	PhotoResolution ResolutionType = "photo"
	// VideoResolution represents video resolution type.
	VideoResolution = "video"
)

type SettingMenu

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

SettingMenu is the setting menu in CCA.

func (*SettingMenu) Close

func (menu *SettingMenu) Close(ctx context.Context, app *App) error

Close closes the menu.

func (*SettingMenu) Open

func (menu *SettingMenu) Open(ctx context.Context, app *App) error

Open opens the menu.

type StartAppFunc

type StartAppFunc func(context.Context) (*App, error)

StartAppFunc starts CCA.

type StopAppFunc

type StopAppFunc func(context.Context, bool) error

StopAppFunc stops CCA.

type TestWithAppFunc

type TestWithAppFunc func(context.Context, *App) error

TestWithAppFunc is the function to run with app.

type TestWithAppParams

type TestWithAppParams struct {
	StopAppOnlyIfExist bool
}

TestWithAppParams defines parameters to control behaviors of running test with app.

type TimerState

type TimerState bool

TimerState is the information of whether shutter timer is on.

const (
	// TimerOn means shutter timer is on.
	TimerOn TimerState = true
	// TimerOff means shutter timer is off.
	TimerOff = false
)

type UIComponent

type UIComponent struct {
	Name      string
	Selectors []string
}

UIComponent represents a CCA UI component.

Jump to

Keyboard shortcuts

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