1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

PM-4109 Vault Onboarding M2 (#7920)

Onboarding component now detects if extension is installed
This commit is contained in:
Jason Ng
2024-02-27 10:18:04 -05:00
committed by GitHub
parent d20caf479b
commit 4733f45eaf
8 changed files with 114 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ type ContentMessageWindowEventHandlers = {
authResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
webAuthnResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
duoResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
checkIfBWExtensionInstalled: () => void;
};
export {

View File

@@ -25,6 +25,17 @@ describe("ContentMessageHandler", () => {
jest.clearAllMocks();
});
describe("handled web vault extension response", () => {
it("sends a message 'hasBWInstalled'", () => {
const mockPostMessage = jest.fn();
window.postMessage = mockPostMessage;
postWindowMessage({ command: "checkIfBWExtensionInstalled" });
expect(mockPostMessage).toHaveBeenCalled();
});
});
describe("handled window messages", () => {
it("ignores messages from other sources", () => {
postWindowMessage({ command: "authResult" }, "https://localhost/", null);

View File

@@ -24,10 +24,18 @@ const windowMessageHandlers: ContentMessageWindowEventHandlers = {
handleAuthResultMessage(data, referrer),
webAuthnResult: ({ data, referrer }: { data: any; referrer: string }) =>
handleWebAuthnResultMessage(data, referrer),
checkIfBWExtensionInstalled: () => handleExtensionInstallCheck(),
duoResult: ({ data, referrer }: { data: any; referrer: string }) =>
handleDuoResultMessage(data, referrer),
};
/**
* Handles the post to the web vault showing the extension has been installed
*/
function handleExtensionInstallCheck() {
window.postMessage({ command: "hasBWInstalled" });
}
/**
* Handles the auth result message from the window.
*