wpr

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

Documentation

Overview

Package wpr manages a Web Page Replay (aka WPR) process and provides chrome.Options to configure Chrome to send all web traffic through the WPR process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFixture

func NewFixture(wprAchiveName string, mode Mode) testing.FixtureImpl

NewFixture creates a new fixture that can launch Lacros chrome with the given wpr archive and mode.

func NewLacrosFixture

func NewLacrosFixture(selection lacros.Selection, fOpt chrome.OptionsCallback) testing.FixtureImpl

NewLacrosFixture creates a new fixture that can launch Lacros chrome with the given selection, Chrome options, and WPR archive. This should be the child of a WPR fixture.

func RecordMode

func RecordMode(archive string) testing.Precondition

RecordMode returns a precondition similar to the ReplayMode above except WPR runs in record mode and all sites accessed by Chrome are recorded in the given archive path on the device.

Example usage:

	func init() {
		testing.AddTest(&testing.Test{
			Func: DoSomething
			...
			Pre: wpr.RecordMode("/tmp/example_wpr_archive.wprgo"),
		})
	}

	func DoSomething(ctx context.Context, s *testing.State) {
		// cr is a logged-in Chrome with net traffic redirected through WPR
   // and recorded.
		cr := s.PreValue().(*chrome.Chrome)
		...
	}

func RemoteReplayMode

func RemoteReplayMode() testing.Precondition

RemoteReplayMode returns a precondition that Chrome is logged in, preserving the state and redirects its traffic through a remote WPR.

Example usage:

func init() {
	testing.AddTest(&testing.Test{
		Func: DoSomething
		...
		Pre: wpr.RemoteReplayMode(),
	})
}

func DoSomething(ctx context.Context, s *testing.State) {
	// cr is a logged-in Chrome with net traffic redirected through WPR
	// and recorded.
	cr := s.PreValue().(*chrome.Chrome)
	...
}

func ReplayMode

func ReplayMode(archive string) testing.Precondition

ReplayMode returns a precondition that WPR is started in replay mode using the given archive as data file of the package and Chrome is logged in and redirects its traffic through WPR.

The precondition is keyed by pkg and archive. Tests of the same package and the same archive would use the same precondition instance and save the time to start WPR and Chrome. Pkg is determined by caller.Get(). Test must supply the name of the archive.

Example usage:

func init() {
	testing.AddTest(&testing.Test{
		Func: DoSomething
		...
		Data: []string{
			...,
			"example_wpr_archive.wprgo"
		},
		Pre: wpr.ReplayMode("example_wpr_archive.wprgo"),
	})
}

func DoSomething(ctx context.Context, s *testing.State) {
	// cr is a logged-in Chrome with net traffic redirected to WPR.
	cr := s.PreValue().(*chrome.Chrome)
	...
}

Types

type FixtValue

type FixtValue interface {
	FOpt() chrome.OptionsCallback
}

FixtValue is an interface for accessing WPR FixtValue members.

type Mode

type Mode int

Mode represents the mode to use in WPR

const (
	Replay Mode = iota
	Record
	RemoteReplay
)

the mode to use in WPR

Replay is the mode to use when running WPR on local side, and WPR is set to replay all recorded web traffic.
Record is the mode to use when running WPR on local side, and WPR is set to record web traffic.
RemoteReplay is the mode to use when WPR is running on remote side, and WPR is set to replay all recorded web traffic.

func (Mode) String

func (m Mode) String() string

type WPR

type WPR struct {
	HTTPPort      int
	HTTPSPort     int
	ChromeOptions []chrome.Option
	// contains filtered or unexported fields
}

WPR holds information about WPR process and chrome.Options to configure Chrome to send traffic through the WPR process.

func New

func New(ctx context.Context, mode Mode, archive string) (*WPR, error)

New starts a WPR process and prepares chrome.Options to configure Chrome to send all web traffic through the WPR process.

func (*WPR) Close

func (w *WPR) Close(ctx context.Context) error

Close sends SIGINT to the WPR process.

Jump to

Keyboard shortcuts

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