browser

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

Documentation

Overview

Package browser implements a layer of abstraction over Ash and Lacros Chrome instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearNotification

func ClearNotification(ctx context.Context, tconn *TestConn, id string) error

ClearNotification clear a notification with the given id.

func CreateTestNotification

func CreateTestNotification(ctx context.Context, tconn *TestConn, notificationType NotificationType, title, message string) (string, error)

CreateTestNotification creates a notification with a custom title and message. iconUrl is a required field to the chrome.notifiations.create() call so a 1px transparent data-url is hardcoded. tconn is an arg to be passed in from active browser under test (either ash-chrome or lacros-chrome).

Types

type Browser

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

Browser consists of just a Chrome session.

func New

func New(sess *driver.Session) *Browser

New creates a new Browser instance from an existing Chrome session.

func (*Browser) CloseTarget

func (b *Browser) CloseTarget(ctx context.Context, id TargetID) error

CloseTarget closes the target identified by the given id.

func (*Browser) CloseWithURL

func (b *Browser) CloseWithURL(ctx context.Context, url string) error

CloseWithURL finds all targets with the given url, closes them, and waits until they are closed. Note that if this closes all lacros pages, lacros will exit, and we won't be able to verify closing was done successfully. If this turns out to cause flakes, we can additionally poll to see if the lacros process still exists, and if it does then poll each target to see if it closed.

func (*Browser) FindTargets

func (b *Browser) FindTargets(ctx context.Context, tm TargetMatcher) ([]*Target, error)

FindTargets returns the info about Targets, which satisfies the given cond condition. This must not be called after Close().

func (*Browser) IsTargetAvailable

func (b *Browser) IsTargetAvailable(ctx context.Context, tm TargetMatcher) (bool, error)

IsTargetAvailable checks if there is any matched target.

func (*Browser) NewConn

func (b *Browser) NewConn(ctx context.Context, url string, opts ...CreateTargetOption) (*Conn, error)

NewConn creates a new Chrome renderer and returns a connection to it. If url is empty, an empty page (about:blank) is opened. Otherwise, the page from the specified URL is opened. You can assume that the page loading has been finished when this function returns.

func (*Browser) NewConnForTarget

func (b *Browser) NewConnForTarget(ctx context.Context, tm TargetMatcher) (*Conn, error)

NewConnForTarget iterates through all available targets and returns a connection to the first one that is matched by tm.

func (*Browser) ReloadActiveTab

func (b *Browser) ReloadActiveTab(ctx context.Context) error

ReloadActiveTab reloads the active tab.

func (*Browser) StartTracing

func (b *Browser) StartTracing(ctx context.Context, categories []string, opts ...TraceOption) error

StartTracing starts trace events collection for the selected categories. Android categories must be prefixed with "disabled-by-default-android ", e.g. for the gfx category, use "disabled-by-default-android gfx", including the space.

func (*Browser) StopTracing

func (b *Browser) StopTracing(ctx context.Context) (*perfetto_proto.Trace, error)

StopTracing stops trace collection and returns the collected trace events.

func (*Browser) TestAPIConn

func (b *Browser) TestAPIConn(ctx context.Context) (*TestConn, error)

TestAPIConn returns a new TestConn instance.

type Conn

type Conn = driver.Conn

Conn is chrome.Conn

type CreateTargetOption

type CreateTargetOption = cdputil.CreateTargetOption

CreateTargetOption is cpdutil.CreateTargetOption.

func WithNewWindow

func WithNewWindow() CreateTargetOption

WithNewWindow behaves like cpdutil.WithNewWindow.

type NotificationItem

type NotificationItem struct {
	Message string `json:"message"`
	Title   string `json:"title"`
}

NotificationItem describes an individual item in a list notification. As defined in https://developer.chrome.com/docs/extensions/reference/notifications/#type-NotificationItem

type NotificationType

type NotificationType string

NotificationType describes the types of notifications you can create with chrome.notifications.create()

const (
	NotificationTypeBasic    NotificationType = "basic"
	NotificationTypeImage    NotificationType = "image"
	NotificationTypeList     NotificationType = "list"
	NotificationTypeProgress NotificationType = "progress"
)

As defined in https://developer.chrome.com/apps/notifications#type-TemplateType

type Target

type Target = driver.Target

Target is chrome.Target.

type TargetID

type TargetID = driver.TargetID

TargetID is chrome.TargetID.

type TargetMatcher

type TargetMatcher = driver.TargetMatcher

TargetMatcher is chrome.TargetMatcher.

type TestConn

type TestConn = driver.TestConn

TestConn is chrome.TestConn.

type TraceOption

type TraceOption = cdputil.TraceOption

TraceOption is cpdutil.TraceOption.

func DisableSystrace

func DisableSystrace() TraceOption

DisableSystrace behaves like cpdutil.DisableSystrace.

type Type

type Type string

Type indicates the type of Chrome browser to be used.

const (
	// TypeAsh refers to Ash Chrome (the system browser).
	TypeAsh Type = "ash"
	// TypeLacros refers to Lacros Chrome (the user browser).
	TypeLacros Type = "lacros"
)

Directories

Path Synopsis
Package browserfixt provides a function for obtaining a Browser instance for a given tast fixture and browser type.
Package browserfixt provides a function for obtaining a Browser instance for a given tast fixture and browser type.

Jump to

Keyboard shortcuts

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