fakes

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package fakes implements fake implementations of Chrome's extension APIs to ease unit testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errs

type Errs struct {
	// Get is the error that should be returned by Storage.Get().
	Get error
	// Set is the error that should be returned by Storage.Set().
	Set error
	// Delete is the error that should be returned by Storage.Delete().
	Delete error
}

Errs contains errors that should be returned by the fake implementation.

type MemStorage

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

MemStorage is a fake implementation of Chrome's storage API.

func NewMemStorage

func NewMemStorage() *MemStorage

NewMemStorage returns a fake implementation of Chrome's storage API.

func (*MemStorage) Delete

func (m *MemStorage) Delete(keys []string, callback func(err error))

Delete is a fake implmentation of chrome.Storage.Delete().

func (*MemStorage) Get

func (m *MemStorage) Get(callback func(data map[string]js.Value, err error))

Get is a fake implmentation of chrome.Storage.Get().

func (*MemStorage) Set

func (m *MemStorage) Set(data map[string]js.Value, callback func(err error))

Set is a fake implmentation of chrome.Storage.Set().

func (*MemStorage) SetError

func (m *MemStorage) SetError(err Errs)

SetError specifies the errors that should be returned from various operations. Forcing the fake implementation to return errors is useful to test error conditions in unit tests.

type MessageHub

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

MessageHub is a fake implementation of Chrome's messaging APIs.

func NewMessageHub

func NewMessageHub() *MessageHub

NewMessageHub returns a fake implementation of Chrome's messaging APIs.

func (*MessageHub) AddReceiver added in v0.0.20

func (m *MessageHub) AddReceiver(r MessageReceiver)

AddReceiver adds a receiver to which messages should be delivered.

func (*MessageHub) Error

func (m *MessageHub) Error() error

Error is a fake implementation of chrome.C.Error. This fake implementation does not simulate errors, so Error() always returns nil.

func (*MessageHub) SendMessage

func (m *MessageHub) SendMessage(msg js.Value, callback func(rsp js.Value))

SendMessage is a fake implementation of chrome.C.SendMessage.

type MessageReceiver added in v0.0.20

type MessageReceiver interface {
	OnMessage(header js.Value, sender js.Value, sendResponse func(js.Value))
}

MessageReceiver defines methods sufficient to receive messages and send responses.

Jump to

Keyboard shortcuts

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