mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
24c240d0d4
* Allow for update logic in state update callbacks * Prefer reading updates to sending in stream * Inform state providers when they must deserialize * Update DefaultGlobalState to act more like DefaultUserState * Fully Implement AbstractStorageService * Add KeyDefinitionOptions * Address PR feedback * Prefer testing interactions for ports * Synced memory storage for browser * Fix port handling * Do not stringify port message data * Use messaging storage * Initialize new foreground memory storage services This will need to be rethought for short-lived background pages, but for now the background is the source of truth for memory storage * Use global state for account service * Use BrowserApi listener to avoid safari memory leaks * Fix build errors: debugging and missed impls * Prefer bound arrow functions * JSON Stringify Messages * Prefer `useClass` * Use noop services * extract storage observable to new interface This also reverts changes for the existing services to use foreground/background services. Those are now used only in state providers * Fix web DI * Prefer initializing observable in constructor * Do not use jsonify as equality operator * Remove port listener to avoid memory leaks * Fix logic and type issues --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
101 lines
1.6 KiB
TypeScript
101 lines
1.6 KiB
TypeScript
// Add chrome storage api
|
|
const QUOTA_BYTES = 10;
|
|
const storage = {
|
|
local: {
|
|
set: jest.fn(),
|
|
get: jest.fn(),
|
|
remove: jest.fn(),
|
|
QUOTA_BYTES,
|
|
getBytesInUse: jest.fn(),
|
|
clear: jest.fn(),
|
|
},
|
|
session: {
|
|
set: jest.fn(),
|
|
get: jest.fn(),
|
|
has: jest.fn(),
|
|
remove: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const runtime = {
|
|
onMessage: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
sendMessage: jest.fn(),
|
|
getManifest: jest.fn(),
|
|
getURL: jest.fn((path) => `chrome-extension://id/${path}`),
|
|
connect: jest.fn(),
|
|
onConnect: {
|
|
addListener: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const contextMenus = {
|
|
create: jest.fn(),
|
|
removeAll: jest.fn(),
|
|
};
|
|
|
|
const i18n = {
|
|
getMessage: jest.fn(),
|
|
getUILanguage: jest.fn(),
|
|
};
|
|
|
|
const tabs = {
|
|
executeScript: jest.fn(),
|
|
sendMessage: jest.fn(),
|
|
query: jest.fn(),
|
|
onActivated: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
onReplaced: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
onUpdated: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
onRemoved: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const scripting = {
|
|
executeScript: jest.fn(),
|
|
};
|
|
|
|
const windows = {
|
|
create: jest.fn(),
|
|
get: jest.fn(),
|
|
getCurrent: jest.fn(),
|
|
update: jest.fn(),
|
|
remove: jest.fn(),
|
|
onFocusChanged: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const port = {
|
|
onMessage: {
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
},
|
|
postMessage: jest.fn(),
|
|
};
|
|
|
|
// set chrome
|
|
global.chrome = {
|
|
i18n,
|
|
storage,
|
|
runtime,
|
|
contextMenus,
|
|
tabs,
|
|
scripting,
|
|
windows,
|
|
port,
|
|
} as any;
|