import { Action, Alarms, Browser, Notifications, Runtime, Storage, Tabs, WebNavigation, Windows } from "webextension-polyfill"; //#region src/types.d.ts interface EventForTesting { /** Trigger all listeners for an event and return all their responses. */ trigger(...args: TParams): Promise; /** Remove all listeners for the event. */ removeAllListeners(): void; } interface BrowserOverrides { /** * Reset the fake browser. Remove all listeners and clear all in-memort state, like storage, * windows, and tabs. * * This is often called before each test. */ reset(): void; alarms: Alarms.Static & { resetState(): void; onAlarm: EventForTesting<[name: Alarms.Alarm]>; }; notifications: Notifications.Static & { resetState(): void; onClosed: EventForTesting<[notificationId: string, byUser: boolean]>; onClicked: EventForTesting<[notificationId: string]>; onButtonClicked: EventForTesting<[notificationId: string, buttonIndex: number]>; onShown: EventForTesting<[notificationId: string]>; }; runtime: Pick & { resetState(): void; onSuspend: EventForTesting<[]>; onSuspendCanceled: EventForTesting<[]>; onStartup: EventForTesting<[]>; onInstalled: EventForTesting<[details: Runtime.OnInstalledDetailsType]>; onUpdateAvailable: EventForTesting<[details: Runtime.OnUpdateAvailableDetailsType]>; onMessage: EventForTesting<[message: any, sender: Runtime.MessageSender], void | Promise>; }; storage: { /** Remove all listeners and clear in-memory storages. */resetState(): void; local: { onChanged: EventForTesting<[changes: Storage.StorageAreaOnChangedChangesType]>; }; session: { onChanged: EventForTesting<[changes: Storage.StorageAreaOnChangedChangesType]>; }; sync: { onChanged: EventForTesting<[changes: Storage.StorageAreaOnChangedChangesType]>; }; managed: { onChanged: EventForTesting<[changes: Storage.StorageAreaOnChangedChangesType]>; }; onChanged: EventForTesting<[changes: Record, areaName: string]>; }; tabs: Pick & { resetState(): void; onCreated: EventForTesting<[tab: Tabs.Tab]>; onUpdated: EventForTesting<[tabId: number, changeInfo: Tabs.OnUpdatedChangeInfoType, tab: Tabs.Tab]>; onHighlighted: EventForTesting<[highlightInfo: Tabs.OnHighlightedHighlightInfoType]>; onActivated: EventForTesting<[activeInfo: Tabs.OnActivatedActiveInfoType]>; onRemoved: EventForTesting<[tabId: number, removeInfo: Tabs.OnRemovedRemoveInfoType]>; }; webNavigation: { onBeforeNavigate: EventForTesting<[details: WebNavigation.OnBeforeNavigateDetailsType]>; onCommitted: EventForTesting<[details: WebNavigation.OnCommittedDetailsType]>; onDOMContentLoaded: EventForTesting<[details: WebNavigation.OnDOMContentLoadedDetailsType]>; onCompleted: EventForTesting<[details: WebNavigation.OnCompletedDetailsType]>; onErrorOccurred: EventForTesting<[details: WebNavigation.OnErrorOccurredDetailsType]>; onCreatedNavigationTarget: EventForTesting<[details: WebNavigation.OnCreatedNavigationTargetDetailsType]>; onReferenceFragmentUpdated: EventForTesting<[details: WebNavigation.OnReferenceFragmentUpdatedDetailsType]>; onTabReplaced: EventForTesting<[details: WebNavigation.OnTabReplacedDetailsType]>; onHistoryStateUpdated: EventForTesting<[details: WebNavigation.OnHistoryStateUpdatedDetailsType]>; }; windows: Pick & { resetState(): void; onCreated: EventForTesting<[window: Windows.Window]>; onRemoved: EventForTesting<[windowId: number]>; onFocusChanged: EventForTesting<[windowId: number]>; }; action: Pick & { resetState(): void; onClicked: EventForTesting<[tab: Tabs.Tab, info: Action.OnClickData | undefined]>; }; } /** * The standard `Browser` interface from `webextension-polyfill`, but with additional functions for * triggering events and reseting state. */ type FakeBrowser = BrowserOverrides & Browser; //#endregion //#region src/index.d.ts /** An in-memory implementation of the `browser` global. */ declare const fakeBrowser: FakeBrowser; //#endregion export { type FakeBrowser, fakeBrowser };