1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

[PM-8480] Rename ambiguous Jest testing method (#9417)

This commit is contained in:
Cesar Gonzalez
2024-05-30 08:39:19 -05:00
committed by GitHub
parent a4dd1f4544
commit f79d1dac92
7 changed files with 127 additions and 127 deletions

View File

@@ -22,7 +22,7 @@ import { NotificationQueueMessageType } from "../enums/notification-queue-messag
import { FormData } from "../services/abstractions/autofill.service"; import { FormData } from "../services/abstractions/autofill.service";
import AutofillService from "../services/autofill.service"; import AutofillService from "../services/autofill.service";
import { createAutofillPageDetailsMock, createChromeTabMock } from "../spec/autofill-mocks"; import { createAutofillPageDetailsMock, createChromeTabMock } from "../spec/autofill-mocks";
import { flushPromises, sendExtensionRuntimeMessage } from "../spec/testing-utils"; import { flushPromises, sendMockExtensionMessage } from "../spec/testing-utils";
import { import {
AddChangePasswordQueueMessage, AddChangePasswordQueueMessage,
@@ -143,7 +143,7 @@ describe("NotificationBackground", () => {
const message: NotificationBackgroundExtensionMessage = { command: "unknown" }; const message: NotificationBackgroundExtensionMessage = { command: "unknown" };
jest.spyOn(notificationBackground as any, "handleSaveCipherMessage"); jest.spyOn(notificationBackground as any, "handleSaveCipherMessage");
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(notificationBackground["handleSaveCipherMessage"]).not.toHaveBeenCalled(); expect(notificationBackground["handleSaveCipherMessage"]).not.toHaveBeenCalled();
}); });
@@ -159,7 +159,7 @@ describe("NotificationBackground", () => {
}; };
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
@@ -178,7 +178,7 @@ describe("NotificationBackground", () => {
}; };
jest.spyOn(notificationBackground as any, "handleSaveCipherMessage").mockImplementation(); jest.spyOn(notificationBackground as any, "handleSaveCipherMessage").mockImplementation();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(notificationBackground["handleSaveCipherMessage"]).toHaveBeenCalledWith( expect(notificationBackground["handleSaveCipherMessage"]).toHaveBeenCalledWith(
@@ -198,7 +198,7 @@ describe("NotificationBackground", () => {
jest.spyOn(notificationBackground as any, "getFolderData"); jest.spyOn(notificationBackground as any, "getFolderData");
(firstValueFrom as jest.Mock).mockResolvedValueOnce(folderViews); (firstValueFrom as jest.Mock).mockResolvedValueOnce(folderViews);
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(notificationBackground["getFolderData"]).toHaveBeenCalled(); expect(notificationBackground["getFolderData"]).toHaveBeenCalled();
@@ -214,7 +214,7 @@ describe("NotificationBackground", () => {
}; };
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
@@ -233,7 +233,7 @@ describe("NotificationBackground", () => {
}; };
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
@@ -281,7 +281,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.LoggedOut); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.LoggedOut);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -296,7 +296,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -312,7 +312,7 @@ describe("NotificationBackground", () => {
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
getEnableAddedLoginPromptSpy.mockReturnValueOnce(false); getEnableAddedLoginPromptSpy.mockReturnValueOnce(false);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -331,7 +331,7 @@ describe("NotificationBackground", () => {
getEnableAddedLoginPromptSpy.mockReturnValueOnce(false); getEnableAddedLoginPromptSpy.mockReturnValueOnce(false);
getAllDecryptedForUrlSpy.mockResolvedValueOnce([]); getAllDecryptedForUrlSpy.mockResolvedValueOnce([]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -353,7 +353,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "test", password: "oldPassword" } }), mock<CipherView>({ login: { username: "test", password: "oldPassword" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -375,7 +375,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "test", password: "password" } }), mock<CipherView>({ login: { username: "test", password: "password" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -391,7 +391,7 @@ describe("NotificationBackground", () => {
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
getEnableAddedLoginPromptSpy.mockReturnValueOnce(true); getEnableAddedLoginPromptSpy.mockReturnValueOnce(true);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -411,7 +411,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "anotherTestUsername", password: "password" } }), mock<CipherView>({ login: { username: "anotherTestUsername", password: "password" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -431,7 +431,7 @@ describe("NotificationBackground", () => {
}), }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith( expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith(
@@ -467,7 +467,7 @@ describe("NotificationBackground", () => {
data: { newPassword: "newPassword", currentPassword: "currentPassword", url: "" }, data: { newPassword: "newPassword", currentPassword: "currentPassword", url: "" },
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled(); expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
@@ -484,7 +484,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -511,7 +511,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "test", password: "password" } }), mock<CipherView>({ login: { username: "test", password: "password" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -534,7 +534,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "test2", password: "password" } }), mock<CipherView>({ login: { username: "test2", password: "password" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -559,7 +559,7 @@ describe("NotificationBackground", () => {
}), }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith( expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith(
@@ -584,7 +584,7 @@ describe("NotificationBackground", () => {
mock<CipherView>({ login: { username: "test2", password: "password" } }), mock<CipherView>({ login: { username: "test2", password: "password" } }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -608,7 +608,7 @@ describe("NotificationBackground", () => {
}), }),
]); ]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith( expect(pushChangePasswordToQueueSpy).toHaveBeenCalledWith(
@@ -644,7 +644,7 @@ describe("NotificationBackground", () => {
thirdQueueMessage, thirdQueueMessage,
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(removeTabFromNotificationQueueSpy).toHaveBeenCalledWith(tab); expect(removeTabFromNotificationQueueSpy).toHaveBeenCalledWith(tab);
@@ -677,7 +677,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -744,7 +744,7 @@ describe("NotificationBackground", () => {
}), }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updatePasswordSpy).not.toHaveBeenCalled(); expect(updatePasswordSpy).not.toHaveBeenCalled();
@@ -767,7 +767,7 @@ describe("NotificationBackground", () => {
}), }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updatePasswordSpy).not.toHaveBeenCalled(); expect(updatePasswordSpy).not.toHaveBeenCalled();
@@ -791,7 +791,7 @@ describe("NotificationBackground", () => {
}), }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
expect(updatePasswordSpy).not.toHaveBeenCalled(); expect(updatePasswordSpy).not.toHaveBeenCalled();
expect(editItemSpy).not.toHaveBeenCalled(); expect(editItemSpy).not.toHaveBeenCalled();
expect(createWithServerSpy).not.toHaveBeenCalled(); expect(createWithServerSpy).not.toHaveBeenCalled();
@@ -815,7 +815,7 @@ describe("NotificationBackground", () => {
const cipherView = mock<CipherView>(); const cipherView = mock<CipherView>();
getDecryptedCipherByIdSpy.mockResolvedValueOnce(cipherView); getDecryptedCipherByIdSpy.mockResolvedValueOnce(cipherView);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(editItemSpy).not.toHaveBeenCalled(); expect(editItemSpy).not.toHaveBeenCalled();
@@ -854,7 +854,7 @@ describe("NotificationBackground", () => {
}); });
getAllDecryptedForUrlSpy.mockResolvedValueOnce([cipherView]); getAllDecryptedForUrlSpy.mockResolvedValueOnce([cipherView]);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updatePasswordSpy).toHaveBeenCalledWith( expect(updatePasswordSpy).toHaveBeenCalledWith(
@@ -887,7 +887,7 @@ describe("NotificationBackground", () => {
setAddEditCipherInfoSpy.mockResolvedValue(undefined); setAddEditCipherInfoSpy.mockResolvedValue(undefined);
openAddEditVaultItemPopoutSpy.mockResolvedValue(undefined); openAddEditVaultItemPopoutSpy.mockResolvedValue(undefined);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updatePasswordSpy).toHaveBeenCalledWith( expect(updatePasswordSpy).toHaveBeenCalledWith(
@@ -937,7 +937,7 @@ describe("NotificationBackground", () => {
convertAddLoginQueueMessageToCipherViewSpy.mockReturnValueOnce(cipherView); convertAddLoginQueueMessageToCipherViewSpy.mockReturnValueOnce(cipherView);
editItemSpy.mockResolvedValueOnce(undefined); editItemSpy.mockResolvedValueOnce(undefined);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updatePasswordSpy).not.toHaveBeenCalled(); expect(updatePasswordSpy).not.toHaveBeenCalled();
@@ -976,7 +976,7 @@ describe("NotificationBackground", () => {
convertAddLoginQueueMessageToCipherViewSpy.mockReturnValueOnce(cipherView); convertAddLoginQueueMessageToCipherViewSpy.mockReturnValueOnce(cipherView);
editItemSpy.mockResolvedValueOnce(undefined); editItemSpy.mockResolvedValueOnce(undefined);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(convertAddLoginQueueMessageToCipherViewSpy).toHaveBeenCalledWith( expect(convertAddLoginQueueMessageToCipherViewSpy).toHaveBeenCalledWith(
@@ -1019,7 +1019,7 @@ describe("NotificationBackground", () => {
throw new Error(errorMessage); throw new Error(errorMessage);
}); });
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(cipherEncryptSpy).toHaveBeenCalledWith(cipherView); expect(cipherEncryptSpy).toHaveBeenCalledWith(cipherView);
@@ -1058,7 +1058,7 @@ describe("NotificationBackground", () => {
throw new Error(errorMessage); throw new Error(errorMessage);
}); });
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(updateWithServerSpy).toThrow(errorMessage); expect(updateWithServerSpy).toThrow(errorMessage);
@@ -1093,7 +1093,7 @@ describe("NotificationBackground", () => {
}), }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).not.toHaveBeenCalled(); expect(tabSendMessageDataSpy).not.toHaveBeenCalled();
@@ -1107,7 +1107,7 @@ describe("NotificationBackground", () => {
mock<AddUnlockVaultQueueMessage>({ type: NotificationQueueMessageType.UnlockVault, tab }), mock<AddUnlockVaultQueueMessage>({ type: NotificationQueueMessageType.UnlockVault, tab }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).not.toHaveBeenCalled(); expect(tabSendMessageDataSpy).not.toHaveBeenCalled();
@@ -1125,7 +1125,7 @@ describe("NotificationBackground", () => {
}), }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).not.toHaveBeenCalled(); expect(tabSendMessageDataSpy).not.toHaveBeenCalled();
@@ -1149,7 +1149,7 @@ describe("NotificationBackground", () => {
jest.spyOn(cipherService, "saveNeverDomain").mockImplementation(); jest.spyOn(cipherService, "saveNeverDomain").mockImplementation();
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).toHaveBeenCalledWith(tab, "closeNotificationBar"); expect(tabSendMessageDataSpy).toHaveBeenCalledWith(tab, "closeNotificationBar");
@@ -1171,7 +1171,7 @@ describe("NotificationBackground", () => {
sender: "not-notificationBar", sender: "not-notificationBar",
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).not.toHaveBeenCalled(); expect(tabSendMessageDataSpy).not.toHaveBeenCalled();
@@ -1188,7 +1188,7 @@ describe("NotificationBackground", () => {
const formData = [mock<FormData>()]; const formData = [mock<FormData>()];
jest.spyOn(autofillService, "getFormsWithPasswordFields").mockReturnValueOnce(formData); jest.spyOn(autofillService, "getFormsWithPasswordFields").mockReturnValueOnce(formData);
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(tabSendMessageDataSpy).toHaveBeenCalledWith( expect(tabSendMessageDataSpy).toHaveBeenCalledWith(
@@ -1222,7 +1222,7 @@ describe("NotificationBackground", () => {
data: { skipNotification: true }, data: { skipNotification: true },
}; };
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).not.toHaveBeenCalled(); expect(getAuthStatusSpy).not.toHaveBeenCalled();
@@ -1237,7 +1237,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.LoggedOut); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.LoggedOut);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -1253,7 +1253,7 @@ describe("NotificationBackground", () => {
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
notificationBackground["notificationQueue"] = [mock<AddLoginQueueMessage>()]; notificationBackground["notificationQueue"] = [mock<AddLoginQueueMessage>()];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(pushUnlockVaultToQueueSpy).not.toHaveBeenCalled(); expect(pushUnlockVaultToQueueSpy).not.toHaveBeenCalled();
@@ -1267,7 +1267,7 @@ describe("NotificationBackground", () => {
}; };
getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked); getAuthStatusSpy.mockResolvedValueOnce(AuthenticationStatus.Locked);
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(pushUnlockVaultToQueueSpy).toHaveBeenCalledWith("example.com", sender.tab); expect(pushUnlockVaultToQueueSpy).toHaveBeenCalledWith("example.com", sender.tab);
@@ -1292,7 +1292,7 @@ describe("NotificationBackground", () => {
}; };
notificationBackground["notificationQueue"] = []; notificationBackground["notificationQueue"] = [];
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(doNotificationQueueCheckSpy).not.toHaveBeenCalled(); expect(doNotificationQueueCheckSpy).not.toHaveBeenCalled();
@@ -1309,7 +1309,7 @@ describe("NotificationBackground", () => {
mock<AddLoginQueueMessage>({ tab: createChromeTabMock({ id: 2 }) }), mock<AddLoginQueueMessage>({ tab: createChromeTabMock({ id: 2 }) }),
]; ];
sendExtensionRuntimeMessage(message, sender); sendMockExtensionMessage(message, sender);
await flushPromises(); await flushPromises();
expect(doNotificationQueueCheckSpy).toHaveBeenCalledWith(tab); expect(doNotificationQueueCheckSpy).toHaveBeenCalledWith(tab);
@@ -1325,7 +1325,7 @@ describe("NotificationBackground", () => {
]; ];
getTabFromCurrentWindowSpy.mockResolvedValueOnce(currenTab); getTabFromCurrentWindowSpy.mockResolvedValueOnce(currenTab);
sendExtensionRuntimeMessage(message, mock<chrome.runtime.MessageSender>({ tab: null })); sendMockExtensionMessage(message, mock<chrome.runtime.MessageSender>({ tab: null }));
await flushPromises(); await flushPromises();
expect(getTabFromCurrentWindowSpy).toHaveBeenCalledWith(); expect(getTabFromCurrentWindowSpy).toHaveBeenCalledWith();
@@ -1340,7 +1340,7 @@ describe("NotificationBackground", () => {
}; };
const openUnlockWindowSpy = jest.spyOn(notificationBackground as any, "openUnlockPopout"); const openUnlockWindowSpy = jest.spyOn(notificationBackground as any, "openUnlockPopout");
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(openUnlockWindowSpy).toHaveBeenCalled(); expect(openUnlockWindowSpy).toHaveBeenCalled();
@@ -1363,7 +1363,7 @@ describe("NotificationBackground", () => {
.spyOn(environmentService as any, "environment$", "get") .spyOn(environmentService as any, "environment$", "get")
.mockReturnValue(new BehaviorSubject(env).asObservable()); .mockReturnValue(new BehaviorSubject(env).asObservable());
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(environmentServiceSpy).toHaveBeenCalled(); expect(environmentServiceSpy).toHaveBeenCalled();

View File

@@ -43,7 +43,7 @@ import {
createPageDetailMock, createPageDetailMock,
createPortSpyMock, createPortSpyMock,
} from "../spec/autofill-mocks"; } from "../spec/autofill-mocks";
import { flushPromises, sendExtensionRuntimeMessage, sendPortMessage } from "../spec/testing-utils"; import { flushPromises, sendMockExtensionMessage, sendPortMessage } from "../spec/testing-utils";
import { import {
AutofillOverlayElement, AutofillOverlayElement,
AutofillOverlayPort, AutofillOverlayPort,
@@ -550,7 +550,7 @@ describe("OverlayBackground", () => {
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab); jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendExtensionRuntimeMessage({ command: "openAutofillOverlay" }); sendMockExtensionMessage({ command: "openAutofillOverlay" });
await flushPromises(); await flushPromises();
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
@@ -576,9 +576,9 @@ describe("OverlayBackground", () => {
overlayBackground["expiredPorts"] = [port1, port2]; overlayBackground["expiredPorts"] = [port1, port2];
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } }); const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
const focusedFieldData = createFocusedFieldDataMock({ tabId: 2 }); const focusedFieldData = createFocusedFieldDataMock({ tabId: 2 });
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ {
command: "autofillOverlayElementClosed", command: "autofillOverlayElementClosed",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
@@ -591,7 +591,7 @@ describe("OverlayBackground", () => {
}); });
it("disconnects the button element port", () => { it("disconnects the button element port", () => {
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "autofillOverlayElementClosed", command: "autofillOverlayElementClosed",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
@@ -601,7 +601,7 @@ describe("OverlayBackground", () => {
}); });
it("disconnects the list element port", () => { it("disconnects the list element port", () => {
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "autofillOverlayElementClosed", command: "autofillOverlayElementClosed",
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
@@ -622,7 +622,7 @@ describe("OverlayBackground", () => {
}); });
it("will not open the add edit popout window if the message does not have a login cipher provided", () => { it("will not open the add edit popout window if the message does not have a login cipher provided", () => {
sendExtensionRuntimeMessage({ command: "autofillOverlayAddNewVaultItem" }, sender); sendMockExtensionMessage({ command: "autofillOverlayAddNewVaultItem" }, sender);
expect(overlayBackground["cipherService"].setAddEditCipherInfo).not.toHaveBeenCalled(); expect(overlayBackground["cipherService"].setAddEditCipherInfo).not.toHaveBeenCalled();
expect(overlayBackground["openAddEditVaultItemPopout"]).not.toHaveBeenCalled(); expect(overlayBackground["openAddEditVaultItemPopout"]).not.toHaveBeenCalled();
@@ -631,7 +631,7 @@ describe("OverlayBackground", () => {
it("will open the add edit popout window after creating a new cipher", async () => { it("will open the add edit popout window after creating a new cipher", async () => {
jest.spyOn(BrowserApi, "sendMessage"); jest.spyOn(BrowserApi, "sendMessage");
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ {
command: "autofillOverlayAddNewVaultItem", command: "autofillOverlayAddNewVaultItem",
login: { login: {
@@ -661,7 +661,7 @@ describe("OverlayBackground", () => {
}); });
it("will set the overlayVisibility property", async () => { it("will set the overlayVisibility property", async () => {
sendExtensionRuntimeMessage({ command: "getAutofillOverlayVisibility" }); sendMockExtensionMessage({ command: "getAutofillOverlayVisibility" });
await flushPromises(); await flushPromises();
expect(await overlayBackground["getOverlayVisibility"]()).toBe( expect(await overlayBackground["getOverlayVisibility"]()).toBe(
@@ -672,7 +672,7 @@ describe("OverlayBackground", () => {
it("returns the overlayVisibility property", async () => { it("returns the overlayVisibility property", async () => {
const sendMessageSpy = jest.fn(); const sendMessageSpy = jest.fn();
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ command: "getAutofillOverlayVisibility" }, { command: "getAutofillOverlayVisibility" },
undefined, undefined,
sendMessageSpy, sendMessageSpy,
@@ -689,7 +689,7 @@ describe("OverlayBackground", () => {
}); });
it("will check if the overlay list is focused if the list port is open", () => { it("will check if the overlay list is focused if the list port is open", () => {
sendExtensionRuntimeMessage({ command: "checkAutofillOverlayFocused" }); sendMockExtensionMessage({ command: "checkAutofillOverlayFocused" });
expect(listPortSpy.postMessage).toHaveBeenCalledWith({ expect(listPortSpy.postMessage).toHaveBeenCalledWith({
command: "checkAutofillOverlayListFocused", command: "checkAutofillOverlayListFocused",
@@ -702,7 +702,7 @@ describe("OverlayBackground", () => {
it("will check if the overlay button is focused if the list port is not open", () => { it("will check if the overlay button is focused if the list port is not open", () => {
overlayBackground["overlayListPort"] = undefined; overlayBackground["overlayListPort"] = undefined;
sendExtensionRuntimeMessage({ command: "checkAutofillOverlayFocused" }); sendMockExtensionMessage({ command: "checkAutofillOverlayFocused" });
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({ expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
command: "checkAutofillOverlayButtonFocused", command: "checkAutofillOverlayButtonFocused",
@@ -717,7 +717,7 @@ describe("OverlayBackground", () => {
it("will send a `focusOverlayList` message to the overlay list port", async () => { it("will send a `focusOverlayList` message to the overlay list port", async () => {
await initOverlayElementPorts({ initList: true, initButton: false }); await initOverlayElementPorts({ initList: true, initButton: false });
sendExtensionRuntimeMessage({ command: "focusAutofillOverlayList" }); sendMockExtensionMessage({ command: "focusAutofillOverlayList" });
expect(listPortSpy.postMessage).toHaveBeenCalledWith({ command: "focusOverlayList" }); expect(listPortSpy.postMessage).toHaveBeenCalledWith({ command: "focusOverlayList" });
}); });
@@ -737,7 +737,7 @@ describe("OverlayBackground", () => {
}); });
it("ignores updating the position if the overlay element type is not provided", () => { it("ignores updating the position if the overlay element type is not provided", () => {
sendExtensionRuntimeMessage({ command: "updateAutofillOverlayPosition" }); sendMockExtensionMessage({ command: "updateAutofillOverlayPosition" });
expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({ expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({
command: "updateIframePosition", command: "updateIframePosition",
@@ -752,9 +752,9 @@ describe("OverlayBackground", () => {
it("skips updating the position if the most recently focused field is different than the message sender", () => { it("skips updating the position if the most recently focused field is different than the message sender", () => {
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } }); const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
const focusedFieldData = createFocusedFieldDataMock({ tabId: 2 }); const focusedFieldData = createFocusedFieldDataMock({ tabId: 2 });
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage({ command: "updateAutofillOverlayPosition" }, sender); sendMockExtensionMessage({ command: "updateAutofillOverlayPosition" }, sender);
expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({ expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({
command: "updateIframePosition", command: "updateIframePosition",
@@ -768,9 +768,9 @@ describe("OverlayBackground", () => {
it("updates the overlay button's position", () => { it("updates the overlay button's position", () => {
const focusedFieldData = createFocusedFieldDataMock(); const focusedFieldData = createFocusedFieldDataMock();
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
@@ -785,9 +785,9 @@ describe("OverlayBackground", () => {
const focusedFieldData = createFocusedFieldDataMock({ const focusedFieldData = createFocusedFieldDataMock({
focusedFieldRects: { top: 1, left: 2, height: 35, width: 4 }, focusedFieldRects: { top: 1, left: 2, height: 35, width: 4 },
}); });
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
@@ -802,9 +802,9 @@ describe("OverlayBackground", () => {
const focusedFieldData = createFocusedFieldDataMock({ const focusedFieldData = createFocusedFieldDataMock({
focusedFieldRects: { top: 1, left: 2, height: 50, width: 4 }, focusedFieldRects: { top: 1, left: 2, height: 50, width: 4 },
}); });
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
@@ -819,9 +819,9 @@ describe("OverlayBackground", () => {
const focusedFieldData = createFocusedFieldDataMock({ const focusedFieldData = createFocusedFieldDataMock({
focusedFieldStyles: { paddingRight: "20px", paddingLeft: "6px" }, focusedFieldStyles: { paddingRight: "20px", paddingLeft: "6px" },
}); });
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
@@ -835,13 +835,13 @@ describe("OverlayBackground", () => {
it("will post a message to the overlay list facilitating an update of the list's position", () => { it("will post a message to the overlay list facilitating an update of the list's position", () => {
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } }); const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
const focusedFieldData = createFocusedFieldDataMock(); const focusedFieldData = createFocusedFieldDataMock();
sendExtensionRuntimeMessage({ command: "updateFocusedFieldData", focusedFieldData }); sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
overlayBackground["updateOverlayPosition"]( overlayBackground["updateOverlayPosition"](
{ overlayElement: AutofillOverlayElement.List }, { overlayElement: AutofillOverlayElement.List },
sender, sender,
); );
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayPosition",
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
@@ -863,7 +863,7 @@ describe("OverlayBackground", () => {
command: "updateAutofillOverlayHidden", command: "updateAutofillOverlayHidden",
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(buttonPortSpy.postMessage).not.toHaveBeenCalledWith(message); expect(buttonPortSpy.postMessage).not.toHaveBeenCalledWith(message);
expect(listPortSpy.postMessage).not.toHaveBeenCalledWith(message); expect(listPortSpy.postMessage).not.toHaveBeenCalledWith(message);
@@ -872,7 +872,7 @@ describe("OverlayBackground", () => {
it("posts a message to the overlay button and list with the display value", () => { it("posts a message to the overlay button and list with the display value", () => {
const message = { command: "updateAutofillOverlayHidden", display: "none" }; const message = { command: "updateAutofillOverlayHidden", display: "none" };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(overlayBackground["overlayButtonPort"].postMessage).toHaveBeenCalledWith({ expect(overlayBackground["overlayButtonPort"].postMessage).toHaveBeenCalledWith({
command: "updateOverlayHidden", command: "updateOverlayHidden",
@@ -903,7 +903,7 @@ describe("OverlayBackground", () => {
}); });
it("stores the page details provided by the message by the tab id of the sender", () => { it("stores the page details provided by the message by the tab id of the sender", () => {
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ command: "collectPageDetailsResponse", details: pageDetails1 }, { command: "collectPageDetailsResponse", details: pageDetails1 },
sender, sender,
); );
@@ -924,7 +924,7 @@ describe("OverlayBackground", () => {
[sender.frameId, { frameId: sender.frameId, tab: sender.tab, details: pageDetails1 }], [sender.frameId, { frameId: sender.frameId, tab: sender.tab, details: pageDetails1 }],
]); ]);
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ command: "collectPageDetailsResponse", details: pageDetails2 }, { command: "collectPageDetailsResponse", details: pageDetails2 },
secondFrameSender, secondFrameSender,
); );
@@ -967,7 +967,7 @@ describe("OverlayBackground", () => {
}, },
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -984,7 +984,7 @@ describe("OverlayBackground", () => {
}; };
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab); jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(getAuthStatusSpy).toHaveBeenCalled(); expect(getAuthStatusSpy).toHaveBeenCalled();
@@ -1007,7 +1007,7 @@ describe("OverlayBackground", () => {
}; };
jest.spyOn(overlayBackground as any, "updateOverlayCiphers").mockImplementation(); jest.spyOn(overlayBackground as any, "updateOverlayCiphers").mockImplementation();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(overlayBackground["updateOverlayCiphers"]).toHaveBeenCalled(); expect(overlayBackground["updateOverlayCiphers"]).toHaveBeenCalled();
}); });
@@ -1020,7 +1020,7 @@ describe("OverlayBackground", () => {
}; };
jest.spyOn(overlayBackground as any, "updateOverlayCiphers").mockImplementation(); jest.spyOn(overlayBackground as any, "updateOverlayCiphers").mockImplementation();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(overlayBackground["updateOverlayCiphers"]).toHaveBeenCalled(); expect(overlayBackground["updateOverlayCiphers"]).toHaveBeenCalled();
}); });

View File

@@ -9,7 +9,7 @@ import AutofillOverlayContentService from "../services/autofill-overlay-content.
import { import {
flushPromises, flushPromises,
mockQuerySelectorAllDefinedCall, mockQuerySelectorAllDefinedCall,
sendExtensionRuntimeMessage, sendMockExtensionMessage,
} from "../spec/testing-utils"; } from "../spec/testing-utils";
import { RedirectFocusDirection } from "../utils/autofill-overlay.enum"; import { RedirectFocusDirection } from "../utils/autofill-overlay.enum";
@@ -174,7 +174,7 @@ describe("AutofillInit", () => {
.spyOn(autofillInit["collectAutofillContentService"], "getPageDetails") .spyOn(autofillInit["collectAutofillContentService"], "getPageDetails")
.mockResolvedValue(pageDetails); .mockResolvedValue(pageDetails);
sendExtensionRuntimeMessage(message, sender, sendResponse); sendMockExtensionMessage(message, sender, sendResponse);
await flushPromises(); await flushPromises();
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith({ expect(chrome.runtime.sendMessage).toHaveBeenCalledWith({
@@ -200,7 +200,7 @@ describe("AutofillInit", () => {
.spyOn(autofillInit["collectAutofillContentService"], "getPageDetails") .spyOn(autofillInit["collectAutofillContentService"], "getPageDetails")
.mockResolvedValue(pageDetails); .mockResolvedValue(pageDetails);
sendExtensionRuntimeMessage( sendMockExtensionMessage(
{ command: "collectPageDetailsImmediately" }, { command: "collectPageDetailsImmediately" },
sender, sender,
sendResponse, sendResponse,
@@ -233,7 +233,7 @@ describe("AutofillInit", () => {
pageDetailsUrl: "https://a-different-url.com", pageDetailsUrl: "https://a-different-url.com",
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(autofillInit["insertAutofillContentService"].fillForm).not.toHaveBeenCalledWith( expect(autofillInit["insertAutofillContentService"].fillForm).not.toHaveBeenCalledWith(
@@ -242,7 +242,7 @@ describe("AutofillInit", () => {
}); });
it("calls the InsertAutofillContentService to fill the form", async () => { it("calls the InsertAutofillContentService to fill the form", async () => {
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "fillForm", command: "fillForm",
fillScript, fillScript,
pageDetailsUrl: window.location.href, pageDetailsUrl: window.location.href,
@@ -256,7 +256,7 @@ describe("AutofillInit", () => {
it("removes the overlay when filling the form", async () => { it("removes the overlay when filling the form", async () => {
const blurAndRemoveOverlaySpy = jest.spyOn(autofillInit as any, "blurAndRemoveOverlay"); const blurAndRemoveOverlaySpy = jest.spyOn(autofillInit as any, "blurAndRemoveOverlay");
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "fillForm", command: "fillForm",
fillScript, fillScript,
pageDetailsUrl: window.location.href, pageDetailsUrl: window.location.href,
@@ -273,7 +273,7 @@ describe("AutofillInit", () => {
.spyOn(autofillInit["autofillOverlayContentService"], "focusMostRecentOverlayField") .spyOn(autofillInit["autofillOverlayContentService"], "focusMostRecentOverlayField")
.mockImplementation(); .mockImplementation();
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "fillForm", command: "fillForm",
fillScript, fillScript,
pageDetailsUrl: window.location.href, pageDetailsUrl: window.location.href,
@@ -297,7 +297,7 @@ describe("AutofillInit", () => {
.spyOn(newAutofillInit["insertAutofillContentService"], "fillForm") .spyOn(newAutofillInit["insertAutofillContentService"], "fillForm")
.mockImplementation(); .mockImplementation();
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "fillForm", command: "fillForm",
fillScript, fillScript,
pageDetailsUrl: window.location.href, pageDetailsUrl: window.location.href,
@@ -333,13 +333,13 @@ describe("AutofillInit", () => {
const newAutofillInit = new AutofillInit(undefined); const newAutofillInit = new AutofillInit(undefined);
newAutofillInit.init(); newAutofillInit.init();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
}); });
it("opens the autofill overlay", () => { it("opens the autofill overlay", () => {
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect( expect(
autofillInit["autofillOverlayContentService"].openAutofillOverlay, autofillInit["autofillOverlayContentService"].openAutofillOverlay,
@@ -362,7 +362,7 @@ describe("AutofillInit", () => {
newAutofillInit.init(); newAutofillInit.init();
jest.spyOn(newAutofillInit as any, "removeAutofillOverlay"); jest.spyOn(newAutofillInit as any, "removeAutofillOverlay");
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "closeAutofillOverlay", command: "closeAutofillOverlay",
data: { forceCloseOverlay: false }, data: { forceCloseOverlay: false },
}); });
@@ -371,7 +371,7 @@ describe("AutofillInit", () => {
}); });
it("removes the autofill overlay if the message flags a forced closure", () => { it("removes the autofill overlay if the message flags a forced closure", () => {
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "closeAutofillOverlay", command: "closeAutofillOverlay",
data: { forceCloseOverlay: true }, data: { forceCloseOverlay: true },
}); });
@@ -384,7 +384,7 @@ describe("AutofillInit", () => {
it("ignores the message if a field is currently focused", () => { it("ignores the message if a field is currently focused", () => {
autofillInit["autofillOverlayContentService"].isFieldCurrentlyFocused = true; autofillInit["autofillOverlayContentService"].isFieldCurrentlyFocused = true;
sendExtensionRuntimeMessage({ command: "closeAutofillOverlay" }); sendMockExtensionMessage({ command: "closeAutofillOverlay" });
expect( expect(
autofillInit["autofillOverlayContentService"].removeAutofillOverlayList, autofillInit["autofillOverlayContentService"].removeAutofillOverlayList,
@@ -397,7 +397,7 @@ describe("AutofillInit", () => {
it("removes the autofill overlay list if the overlay is currently filling", () => { it("removes the autofill overlay list if the overlay is currently filling", () => {
autofillInit["autofillOverlayContentService"].isCurrentlyFilling = true; autofillInit["autofillOverlayContentService"].isCurrentlyFilling = true;
sendExtensionRuntimeMessage({ command: "closeAutofillOverlay" }); sendMockExtensionMessage({ command: "closeAutofillOverlay" });
expect( expect(
autofillInit["autofillOverlayContentService"].removeAutofillOverlayList, autofillInit["autofillOverlayContentService"].removeAutofillOverlayList,
@@ -408,7 +408,7 @@ describe("AutofillInit", () => {
}); });
it("removes the entire overlay if the overlay is not currently filling", () => { it("removes the entire overlay if the overlay is not currently filling", () => {
sendExtensionRuntimeMessage({ command: "closeAutofillOverlay" }); sendMockExtensionMessage({ command: "closeAutofillOverlay" });
expect( expect(
autofillInit["autofillOverlayContentService"].removeAutofillOverlayList, autofillInit["autofillOverlayContentService"].removeAutofillOverlayList,
@@ -424,13 +424,13 @@ describe("AutofillInit", () => {
const newAutofillInit = new AutofillInit(undefined); const newAutofillInit = new AutofillInit(undefined);
newAutofillInit.init(); newAutofillInit.init();
sendExtensionRuntimeMessage({ command: "addNewVaultItemFromOverlay" }); sendMockExtensionMessage({ command: "addNewVaultItemFromOverlay" });
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
}); });
it("will add a new vault item", () => { it("will add a new vault item", () => {
sendExtensionRuntimeMessage({ command: "addNewVaultItemFromOverlay" }); sendMockExtensionMessage({ command: "addNewVaultItemFromOverlay" });
expect(autofillInit["autofillOverlayContentService"].addNewVaultItem).toHaveBeenCalled(); expect(autofillInit["autofillOverlayContentService"].addNewVaultItem).toHaveBeenCalled();
}); });
@@ -448,13 +448,13 @@ describe("AutofillInit", () => {
const newAutofillInit = new AutofillInit(undefined); const newAutofillInit = new AutofillInit(undefined);
newAutofillInit.init(); newAutofillInit.init();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
}); });
it("redirects the overlay focus", () => { it("redirects the overlay focus", () => {
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect( expect(
autofillInit["autofillOverlayContentService"].redirectOverlayFocusOut, autofillInit["autofillOverlayContentService"].redirectOverlayFocusOut,
@@ -474,13 +474,13 @@ describe("AutofillInit", () => {
const newAutofillInit = new AutofillInit(undefined); const newAutofillInit = new AutofillInit(undefined);
newAutofillInit.init(); newAutofillInit.init();
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
}); });
it("updates whether the overlay ciphers are populated", () => { it("updates whether the overlay ciphers are populated", () => {
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(autofillInit["autofillOverlayContentService"].isOverlayCiphersPopulated).toEqual( expect(autofillInit["autofillOverlayContentService"].isOverlayCiphersPopulated).toEqual(
message.data.isOverlayCiphersPopulated, message.data.isOverlayCiphersPopulated,
@@ -494,7 +494,7 @@ describe("AutofillInit", () => {
newAutofillInit.init(); newAutofillInit.init();
jest.spyOn(newAutofillInit as any, "removeAutofillOverlay"); jest.spyOn(newAutofillInit as any, "removeAutofillOverlay");
sendExtensionRuntimeMessage({ command: "bgUnlockPopoutOpened" }); sendMockExtensionMessage({ command: "bgUnlockPopoutOpened" });
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
expect(newAutofillInit["removeAutofillOverlay"]).not.toHaveBeenCalled(); expect(newAutofillInit["removeAutofillOverlay"]).not.toHaveBeenCalled();
@@ -504,7 +504,7 @@ describe("AutofillInit", () => {
jest.spyOn(autofillInit["autofillOverlayContentService"], "blurMostRecentOverlayField"); jest.spyOn(autofillInit["autofillOverlayContentService"], "blurMostRecentOverlayField");
jest.spyOn(autofillInit as any, "removeAutofillOverlay"); jest.spyOn(autofillInit as any, "removeAutofillOverlay");
sendExtensionRuntimeMessage({ command: "bgUnlockPopoutOpened" }); sendMockExtensionMessage({ command: "bgUnlockPopoutOpened" });
expect( expect(
autofillInit["autofillOverlayContentService"].blurMostRecentOverlayField, autofillInit["autofillOverlayContentService"].blurMostRecentOverlayField,
@@ -519,7 +519,7 @@ describe("AutofillInit", () => {
newAutofillInit.init(); newAutofillInit.init();
jest.spyOn(newAutofillInit as any, "removeAutofillOverlay"); jest.spyOn(newAutofillInit as any, "removeAutofillOverlay");
sendExtensionRuntimeMessage({ command: "bgVaultItemRepromptPopoutOpened" }); sendMockExtensionMessage({ command: "bgVaultItemRepromptPopoutOpened" });
expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined); expect(newAutofillInit["autofillOverlayContentService"]).toBe(undefined);
expect(newAutofillInit["removeAutofillOverlay"]).not.toHaveBeenCalled(); expect(newAutofillInit["removeAutofillOverlay"]).not.toHaveBeenCalled();
@@ -529,7 +529,7 @@ describe("AutofillInit", () => {
jest.spyOn(autofillInit["autofillOverlayContentService"], "blurMostRecentOverlayField"); jest.spyOn(autofillInit["autofillOverlayContentService"], "blurMostRecentOverlayField");
jest.spyOn(autofillInit as any, "removeAutofillOverlay"); jest.spyOn(autofillInit as any, "removeAutofillOverlay");
sendExtensionRuntimeMessage({ command: "bgVaultItemRepromptPopoutOpened" }); sendMockExtensionMessage({ command: "bgVaultItemRepromptPopoutOpened" });
expect( expect(
autofillInit["autofillOverlayContentService"].blurMostRecentOverlayField, autofillInit["autofillOverlayContentService"].blurMostRecentOverlayField,
@@ -545,7 +545,7 @@ describe("AutofillInit", () => {
}); });
it("skips attempting to update the overlay visibility if the autofillOverlayVisibility data value is not present", () => { it("skips attempting to update the overlay visibility if the autofillOverlayVisibility data value is not present", () => {
sendExtensionRuntimeMessage({ sendMockExtensionMessage({
command: "updateAutofillOverlayVisibility", command: "updateAutofillOverlayVisibility",
data: {}, data: {},
}); });
@@ -563,7 +563,7 @@ describe("AutofillInit", () => {
}, },
}; };
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(autofillInit["autofillOverlayContentService"].autofillOverlayVisibility).toEqual( expect(autofillInit["autofillOverlayContentService"].autofillOverlayVisibility).toEqual(
message.data.autofillOverlayVisibility, message.data.autofillOverlayVisibility,

View File

@@ -2,7 +2,7 @@ import { mock } from "jest-mock-extended";
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum"; import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
import { postWindowMessage, sendExtensionRuntimeMessage } from "../spec/testing-utils"; import { postWindowMessage, sendMockExtensionMessage } from "../spec/testing-utils";
describe("ContentMessageHandler", () => { describe("ContentMessageHandler", () => {
const sendMessageSpy = jest.spyOn(chrome.runtime, "sendMessage"); const sendMessageSpy = jest.spyOn(chrome.runtime, "sendMessage");
@@ -92,13 +92,13 @@ describe("ContentMessageHandler", () => {
describe("handled extension messages", () => { describe("handled extension messages", () => {
it("ignores the message to the extension background if it is not present in the forwardCommands list", () => { it("ignores the message to the extension background if it is not present in the forwardCommands list", () => {
sendExtensionRuntimeMessage({ command: "someOtherCommand" }); sendMockExtensionMessage({ command: "someOtherCommand" });
expect(sendMessageSpy).not.toHaveBeenCalled(); expect(sendMessageSpy).not.toHaveBeenCalled();
}); });
it("forwards the message to the extension background if it is present in the forwardCommands list", () => { it("forwards the message to the extension background if it is present in the forwardCommands list", () => {
sendExtensionRuntimeMessage({ command: "bgUnlockPopoutOpened" }); sendMockExtensionMessage({ command: "bgUnlockPopoutOpened" });
expect(sendMessageSpy).toHaveBeenCalledTimes(1); expect(sendMessageSpy).toHaveBeenCalledTimes(1);
expect(sendMessageSpy).toHaveBeenCalledWith({ command: "bgUnlockPopoutOpened" }); expect(sendMessageSpy).toHaveBeenCalledWith({ command: "bgUnlockPopoutOpened" });

View File

@@ -15,7 +15,7 @@ function postWindowMessage(data: any, origin = "https://localhost/", source = wi
globalThis.dispatchEvent(new MessageEvent("message", { data, origin, source })); globalThis.dispatchEvent(new MessageEvent("message", { data, origin, source }));
} }
function sendExtensionRuntimeMessage( function sendMockExtensionMessage(
message: any, message: any,
sender?: chrome.runtime.MessageSender, sender?: chrome.runtime.MessageSender,
sendResponse?: CallableFunction, sendResponse?: CallableFunction,
@@ -130,7 +130,7 @@ export {
triggerTestFailure, triggerTestFailure,
flushPromises, flushPromises,
postWindowMessage, postWindowMessage,
sendExtensionRuntimeMessage, sendMockExtensionMessage,
triggerRuntimeOnConnectEvent, triggerRuntimeOnConnectEvent,
sendPortMessage, sendPortMessage,
triggerPortOnDisconnectEvent, triggerPortOnDisconnectEvent,

View File

@@ -1,4 +1,4 @@
import { flushPromises, sendExtensionRuntimeMessage } from "../../autofill/spec/testing-utils"; import { flushPromises, sendMockExtensionMessage } from "../../autofill/spec/testing-utils";
import { BrowserApi } from "../browser/browser-api"; import { BrowserApi } from "../browser/browser-api";
import BrowserClipboardService from "../services/browser-clipboard.service"; import BrowserClipboardService from "../services/browser-clipboard.service";
@@ -21,7 +21,7 @@ describe("OffscreenDocument", () => {
describe("extension message handlers", () => { describe("extension message handlers", () => {
it("ignores messages that do not have a handler registered with the corresponding command", () => { it("ignores messages that do not have a handler registered with the corresponding command", () => {
sendExtensionRuntimeMessage({ command: "notAValidCommand" }); sendMockExtensionMessage({ command: "notAValidCommand" });
expect(browserClipboardServiceCopySpy).not.toHaveBeenCalled(); expect(browserClipboardServiceCopySpy).not.toHaveBeenCalled();
expect(browserClipboardServiceReadSpy).not.toHaveBeenCalled(); expect(browserClipboardServiceReadSpy).not.toHaveBeenCalled();
@@ -31,7 +31,7 @@ describe("OffscreenDocument", () => {
const error = new Error("test error"); const error = new Error("test error");
browserClipboardServiceCopySpy.mockRejectedValueOnce(new Error("test error")); browserClipboardServiceCopySpy.mockRejectedValueOnce(new Error("test error"));
sendExtensionRuntimeMessage({ command: "offscreenCopyToClipboard", text: "test" }); sendMockExtensionMessage({ command: "offscreenCopyToClipboard", text: "test" });
await flushPromises(); await flushPromises();
expect(browserClipboardServiceCopySpy).toHaveBeenCalled(); expect(browserClipboardServiceCopySpy).toHaveBeenCalled();
@@ -45,7 +45,7 @@ describe("OffscreenDocument", () => {
it("copies the message text", async () => { it("copies the message text", async () => {
const text = "test"; const text = "test";
sendExtensionRuntimeMessage({ command: "offscreenCopyToClipboard", text }); sendMockExtensionMessage({ command: "offscreenCopyToClipboard", text });
await flushPromises(); await flushPromises();
expect(browserClipboardServiceCopySpy).toHaveBeenCalledWith(window, text); expect(browserClipboardServiceCopySpy).toHaveBeenCalledWith(window, text);
@@ -54,7 +54,7 @@ describe("OffscreenDocument", () => {
describe("handleOffscreenReadFromClipboard", () => { describe("handleOffscreenReadFromClipboard", () => {
it("reads the value from the clipboard service", async () => { it("reads the value from the clipboard service", async () => {
sendExtensionRuntimeMessage({ command: "offscreenReadFromClipboard" }); sendMockExtensionMessage({ command: "offscreenReadFromClipboard" });
await flushPromises(); await flushPromises();
expect(browserClipboardServiceReadSpy).toHaveBeenCalledWith(window); expect(browserClipboardServiceReadSpy).toHaveBeenCalledWith(window);

View File

@@ -12,7 +12,7 @@ import { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault
import { createPortSpyMock } from "../../../autofill/spec/autofill-mocks"; import { createPortSpyMock } from "../../../autofill/spec/autofill-mocks";
import { import {
flushPromises, flushPromises,
sendExtensionRuntimeMessage, sendMockExtensionMessage,
triggerPortOnDisconnectEvent, triggerPortOnDisconnectEvent,
triggerRuntimeOnConnectEvent, triggerRuntimeOnConnectEvent,
} from "../../../autofill/spec/testing-utils"; } from "../../../autofill/spec/testing-utils";
@@ -263,7 +263,7 @@ describe("Fido2Background", () => {
it("ignores messages that do not have a handler associated with a command within the message", () => { it("ignores messages that do not have a handler associated with a command within the message", () => {
const message = mock<Fido2ExtensionMessage>({ command: "nonexistentCommand" }); const message = mock<Fido2ExtensionMessage>({ command: "nonexistentCommand" });
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(abortManagerMock.abort).not.toHaveBeenCalled(); expect(abortManagerMock.abort).not.toHaveBeenCalled();
}); });
@@ -274,7 +274,7 @@ describe("Fido2Background", () => {
const sendResponse = jest.fn(); const sendResponse = jest.fn();
fido2ClientService.createCredential.mockRejectedValue(new Error("error")); fido2ClientService.createCredential.mockRejectedValue(new Error("error"));
sendExtensionRuntimeMessage(message, sender, sendResponse); sendMockExtensionMessage(message, sender, sendResponse);
await flushPromises(); await flushPromises();
expect(sendResponse).toHaveBeenCalledWith({ error: { message: "error" } }); expect(sendResponse).toHaveBeenCalledWith({ error: { message: "error" } });
@@ -287,7 +287,7 @@ describe("Fido2Background", () => {
abortedRequestId: "123", abortedRequestId: "123",
}); });
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(abortManagerMock.abort).toHaveBeenCalledWith(message.abortedRequestId); expect(abortManagerMock.abort).toHaveBeenCalledWith(message.abortedRequestId);
@@ -302,7 +302,7 @@ describe("Fido2Background", () => {
data: mock<CreateCredentialParams>(), data: mock<CreateCredentialParams>(),
}); });
sendExtensionRuntimeMessage(message, senderMock); sendMockExtensionMessage(message, senderMock);
await flushPromises(); await flushPromises();
expect(fido2ClientService.createCredential).toHaveBeenCalledWith( expect(fido2ClientService.createCredential).toHaveBeenCalledWith(
@@ -323,7 +323,7 @@ describe("Fido2Background", () => {
data: mock<AssertCredentialParams>(), data: mock<AssertCredentialParams>(),
}); });
sendExtensionRuntimeMessage(message, senderMock); sendMockExtensionMessage(message, senderMock);
await flushPromises(); await flushPromises();
expect(fido2ClientService.assertCredential).toHaveBeenCalledWith( expect(fido2ClientService.assertCredential).toHaveBeenCalledWith(