1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[PM-5189] Refactoring implementation

This commit is contained in:
Cesar Gonzalez
2024-05-02 16:43:54 -05:00
parent 9a8d6d38da
commit b8ab84882d
10 changed files with 80 additions and 80 deletions

View File

@@ -92,8 +92,8 @@ type BackgroundOnMessageHandlerParams = BackgroundMessageParam & BackgroundSende
type OverlayBackgroundExtensionMessageHandlers = { type OverlayBackgroundExtensionMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
openAutofillOverlayMenu: () => void; openAutofillInlineMenu: () => void;
closeAutofillOverlayMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void; autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
getInlineMenuVisibilitySetting: () => void; getInlineMenuVisibilitySetting: () => void;
@@ -131,7 +131,7 @@ type PortOnMessageHandlerParams = PortMessageParam & PortConnectionParam;
type OverlayButtonPortMessageHandlers = { type OverlayButtonPortMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
overlayButtonClicked: ({ port }: PortConnectionParam) => void; overlayButtonClicked: ({ port }: PortConnectionParam) => void;
closeAutofillOverlayMenu: ({ port }: PortConnectionParam) => void; closeAutofillInlineMenu: ({ port }: PortConnectionParam) => void;
forceCloseAutofillOverlay: ({ port }: PortConnectionParam) => void; forceCloseAutofillOverlay: ({ port }: PortConnectionParam) => void;
overlayPageBlurred: () => void; overlayPageBlurred: () => void;
redirectOverlayFocusOut: ({ message, port }: PortOnMessageHandlerParams) => void; redirectOverlayFocusOut: ({ message, port }: PortOnMessageHandlerParams) => void;

View File

@@ -536,7 +536,7 @@ describe("OverlayBackground", () => {
it("will return a response if the message handler returns a response", async () => { it("will return a response if the message handler returns a response", async () => {
const message = { const message = {
command: "openAutofillOverlayMenu", command: "openAutofillInlineMenu",
}; };
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } }); const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
const sendResponse = jest.fn(); const sendResponse = jest.fn();
@@ -552,17 +552,17 @@ describe("OverlayBackground", () => {
}); });
describe("extension message handlers", () => { describe("extension message handlers", () => {
describe("openAutofillOverlayMenu message handler", () => { describe("openAutofillInlineMenu message handler", () => {
it("opens the autofill overlay by sending a message to the current tab", async () => { it("opens the autofill overlay by sending a message to the current tab", async () => {
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } }); const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab); jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
jest.spyOn(BrowserApi, "tabSendMessage").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessage").mockImplementation();
sendMockExtensionMessage({ command: "openAutofillOverlayMenu" }); sendMockExtensionMessage({ command: "openAutofillInlineMenu" });
await flushPromises(); await flushPromises();
expect(BrowserApi.tabSendMessage).not.toHaveBeenCalledWith(sender.tab, { expect(BrowserApi.tabSendMessage).not.toHaveBeenCalledWith(sender.tab, {
command: "openAutofillOverlayMenu", command: "openAutofillInlineMenu",
isFocusingFieldElement: false, isFocusingFieldElement: false,
isOpeningFullOverlay: false, isOpeningFullOverlay: false,
authStatus: AuthenticationStatus.Unlocked, authStatus: AuthenticationStatus.Unlocked,
@@ -984,7 +984,7 @@ describe("OverlayBackground", () => {
const message = { const message = {
command: "unlockCompleted", command: "unlockCompleted",
data: { data: {
commandToRetry: { message: { command: "openAutofillOverlayMenu" } }, commandToRetry: { message: { command: "openAutofillInlineMenu" } },
}, },
}; };
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab); jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
@@ -996,7 +996,7 @@ describe("OverlayBackground", () => {
expect(BrowserApi.tabSendMessage).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessage).toHaveBeenCalledWith(
sender.tab, sender.tab,
{ {
command: "openAutofillOverlayMenu", command: "openAutofillInlineMenu",
isFocusingFieldElement: true, isFocusingFieldElement: true,
isOpeningFullOverlay: false, isOpeningFullOverlay: false,
authStatus: AuthenticationStatus.Unlocked, authStatus: AuthenticationStatus.Unlocked,
@@ -1147,23 +1147,23 @@ describe("OverlayBackground", () => {
}); });
it("opens the autofill overlay if the auth status is unlocked", () => { it("opens the autofill overlay if the auth status is unlocked", () => {
jest.spyOn(overlayBackground as any, "openOverlayMenu").mockImplementation(); jest.spyOn(overlayBackground as any, "openInlineMenu").mockImplementation();
sendPortMessage(buttonMessageConnectorPortSpy, { sendPortMessage(buttonMessageConnectorPortSpy, {
command: "overlayButtonClicked", command: "overlayButtonClicked",
portKey, portKey,
}); });
expect(overlayBackground["openOverlayMenu"]).toHaveBeenCalled(); expect(overlayBackground["openInlineMenu"]).toHaveBeenCalled();
}); });
// TODO: The tests for `closeAutofillOverlayMenu` and `forceCloseAutofillOverlay` need to be fleshed out // TODO: The tests for `closeAutofillInlineMenu` and `forceCloseAutofillOverlay` need to be fleshed out
describe("closeAutofillOverlayMenu", () => { describe("closeAutofillInlineMenu", () => {
it("sends a `closeOverlay` message to the sender tab", () => { it("sends a `closeOverlay` message to the sender tab", () => {
jest.spyOn(BrowserApi, "tabSendMessage"); jest.spyOn(BrowserApi, "tabSendMessage");
sendPortMessage(buttonMessageConnectorPortSpy, { sendPortMessage(buttonMessageConnectorPortSpy, {
command: "closeAutofillOverlayMenu", command: "closeAutofillInlineMenu",
portKey, portKey,
}); });
@@ -1284,14 +1284,14 @@ describe("OverlayBackground", () => {
describe("unlockVault", () => { describe("unlockVault", () => {
it("closes the autofill overlay and opens the unlock popout", async () => { it("closes the autofill overlay and opens the unlock popout", async () => {
jest.spyOn(overlayBackground as any, "closeOverlayMenu").mockImplementation(); jest.spyOn(overlayBackground as any, "closeInlineMenu").mockImplementation();
jest.spyOn(overlayBackground as any, "openUnlockPopout").mockImplementation(); jest.spyOn(overlayBackground as any, "openUnlockPopout").mockImplementation();
jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation();
sendPortMessage(listMessageConnectorPortSpy, { command: "unlockVault", portKey }); sendPortMessage(listMessageConnectorPortSpy, { command: "unlockVault", portKey });
await flushPromises(); await flushPromises();
expect(overlayBackground["closeOverlayMenu"]).toHaveBeenCalledWith( expect(overlayBackground["closeInlineMenu"]).toHaveBeenCalledWith(
listMessageConnectorPortSpy.sender, listMessageConnectorPortSpy.sender,
); );
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith( expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
@@ -1299,7 +1299,7 @@ describe("OverlayBackground", () => {
"addToLockedVaultPendingNotifications", "addToLockedVaultPendingNotifications",
{ {
commandToRetry: { commandToRetry: {
message: { command: "openAutofillOverlayMenu" }, message: { command: "openAutofillInlineMenu" },
sender: listMessageConnectorPortSpy.sender, sender: listMessageConnectorPortSpy.sender,
}, },
target: "overlay.background", target: "overlay.background",

View File

@@ -64,8 +64,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
private overlayPageTranslations: Record<string, string>; private overlayPageTranslations: Record<string, string>;
private iconsServerUrl: string; private iconsServerUrl: string;
private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = { private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = {
openAutofillOverlayMenu: () => this.openOverlayMenu(false), openAutofillInlineMenu: () => this.openInlineMenu(false),
closeAutofillOverlayMenu: ({ message, sender }) => this.closeOverlayMenu(sender, message), closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message),
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message), autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender), autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender),
getInlineMenuVisibilitySetting: () => this.getInlineMenuVisibility(), getInlineMenuVisibilitySetting: () => this.getInlineMenuVisibility(),
@@ -93,9 +93,9 @@ class OverlayBackground implements OverlayBackgroundInterface {
}; };
private readonly overlayButtonPortMessageHandlers: OverlayButtonPortMessageHandlers = { private readonly overlayButtonPortMessageHandlers: OverlayButtonPortMessageHandlers = {
overlayButtonClicked: ({ port }) => this.handleOverlayButtonClicked(port), overlayButtonClicked: ({ port }) => this.handleOverlayButtonClicked(port),
closeAutofillOverlayMenu: ({ port }) => this.closeOverlayMenu(port.sender), closeAutofillInlineMenu: ({ port }) => this.closeInlineMenu(port.sender),
forceCloseAutofillOverlay: ({ port }) => forceCloseAutofillOverlay: ({ port }) =>
this.closeOverlayMenu(port.sender, { forceCloseOverlay: true }), this.closeInlineMenu(port.sender, { forceCloseOverlay: true }),
overlayPageBlurred: () => this.checkOverlayListFocused(), overlayPageBlurred: () => this.checkOverlayListFocused(),
redirectOverlayFocusOut: ({ message, port }) => this.redirectOverlayFocusOut(message, port), redirectOverlayFocusOut: ({ message, port }) => this.redirectOverlayFocusOut(message, port),
updateOverlayPageColorScheme: () => this.updateButtonPageColorScheme(), updateOverlayPageColorScheme: () => this.updateButtonPageColorScheme(),
@@ -103,7 +103,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
private readonly overlayListPortMessageHandlers: OverlayListPortMessageHandlers = { private readonly overlayListPortMessageHandlers: OverlayListPortMessageHandlers = {
checkAutofillOverlayButtonFocused: () => this.checkOverlayButtonFocused(), checkAutofillOverlayButtonFocused: () => this.checkOverlayButtonFocused(),
forceCloseAutofillOverlay: ({ port }) => forceCloseAutofillOverlay: ({ port }) =>
this.closeOverlayMenu(port.sender, { forceCloseOverlay: true }), this.closeInlineMenu(port.sender, { forceCloseOverlay: true }),
overlayPageBlurred: () => this.checkOverlayButtonFocused(), overlayPageBlurred: () => this.checkOverlayButtonFocused(),
unlockVault: ({ port }) => this.unlockVault(port), unlockVault: ({ port }) => this.unlockVault(port),
fillSelectedListItem: ({ message, port }) => this.fillSelectedOverlayListItem(message, port), fillSelectedListItem: ({ message, port }) => this.fillSelectedOverlayListItem(message, port),
@@ -416,7 +416,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
* @param forceCloseOverlay - Identifies whether the overlay should be forced closed * @param forceCloseOverlay - Identifies whether the overlay should be forced closed
* @param overlayElement - The overlay element to close, either the list or button * @param overlayElement - The overlay element to close, either the list or button
*/ */
private closeOverlayMenu( private closeInlineMenu(
sender: chrome.runtime.MessageSender, sender: chrome.runtime.MessageSender,
{ {
forceCloseOverlay, forceCloseOverlay,
@@ -621,13 +621,13 @@ class OverlayBackground implements OverlayBackgroundInterface {
* @param isFocusingFieldElement - Identifies whether the field element should be focused when the overlay is opened * @param isFocusingFieldElement - Identifies whether the field element should be focused when the overlay is opened
* @param isOpeningFullOverlay - Identifies whether the full overlay should be forced open regardless of other states * @param isOpeningFullOverlay - Identifies whether the full overlay should be forced open regardless of other states
*/ */
private async openOverlayMenu(isFocusingFieldElement = false, isOpeningFullOverlay = false) { private async openInlineMenu(isFocusingFieldElement = false, isOpeningFullOverlay = false) {
const currentTab = await BrowserApi.getTabFromCurrentWindowId(); const currentTab = await BrowserApi.getTabFromCurrentWindowId();
await BrowserApi.tabSendMessage( await BrowserApi.tabSendMessage(
currentTab, currentTab,
{ {
command: "openAutofillOverlayMenu", command: "openAutofillInlineMenu",
isFocusingFieldElement, isFocusingFieldElement,
isOpeningFullOverlay, isOpeningFullOverlay,
authStatus: await this.getAuthStatus(), authStatus: await this.getAuthStatus(),
@@ -688,7 +688,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
return; return;
} }
void this.openOverlayMenu(false, true); void this.openInlineMenu(false, true);
} }
/** /**
@@ -699,9 +699,9 @@ class OverlayBackground implements OverlayBackgroundInterface {
private async unlockVault(port: chrome.runtime.Port) { private async unlockVault(port: chrome.runtime.Port) {
const { sender } = port; const { sender } = port;
this.closeOverlayMenu(port.sender); this.closeInlineMenu(port.sender);
const retryMessage: LockedVaultPendingNotificationsData = { const retryMessage: LockedVaultPendingNotificationsData = {
commandToRetry: { message: { command: "openAutofillOverlayMenu" }, sender }, commandToRetry: { message: { command: "openAutofillInlineMenu" }, sender },
target: "overlay.background", target: "overlay.background",
}; };
await BrowserApi.tabSendMessageData( await BrowserApi.tabSendMessageData(
@@ -749,8 +749,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
private async unlockCompleted(message: OverlayBackgroundExtensionMessage) { private async unlockCompleted(message: OverlayBackgroundExtensionMessage) {
await this.getAuthStatus(); await this.getAuthStatus();
if (message.data?.commandToRetry?.message?.command === "openAutofillOverlayMenu") { if (message.data?.commandToRetry?.message?.command === "openAutofillInlineMenu") {
await this.openOverlayMenu(true); await this.openInlineMenu(true);
} }
} }

View File

@@ -459,7 +459,7 @@ describe("AutofillOverlayIframeService", () => {
autofillOverlayIframeService["iframe"].src = "http://malicious-site.com"; autofillOverlayIframeService["iframe"].src = "http://malicious-site.com";
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceClose: true, forceClose: true,
}); });
}); });
@@ -471,7 +471,7 @@ describe("AutofillOverlayIframeService", () => {
autofillOverlayIframeService["iframe"].src = "http://malicious-site.com"; autofillOverlayIframeService["iframe"].src = "http://malicious-site.com";
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceClose: true, forceClose: true,
}); });
}); });

View File

@@ -324,7 +324,7 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
* mutation observer is triggered excessively. * mutation observer is triggered excessively.
*/ */
private forceCloseAutofillOverlay() { private forceCloseAutofillOverlay() {
void this.sendExtensionMessage("closeAutofillOverlayMenu", { forceClose: true }); void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
} }
/** /**

View File

@@ -74,7 +74,7 @@ describe("AutofillOverlayButton", () => {
await flushPromises(); await flushPromises();
expect(globalThis.parent.postMessage).not.toHaveBeenCalledWith({ expect(globalThis.parent.postMessage).not.toHaveBeenCalledWith({
command: "closeAutofillOverlayMenu", command: "closeAutofillInlineMenu",
}); });
}); });
@@ -85,7 +85,7 @@ describe("AutofillOverlayButton", () => {
await flushPromises(); await flushPromises();
expect(globalThis.parent.postMessage).toHaveBeenCalledWith( expect(globalThis.parent.postMessage).toHaveBeenCalledWith(
{ command: "closeAutofillOverlayMenu", portKey }, { command: "closeAutofillInlineMenu", portKey },
"*", "*",
); );
}); });

View File

@@ -115,7 +115,7 @@ class AutofillOverlayButton extends AutofillOverlayPageElement {
return; return;
} }
this.postMessageToParent({ command: "closeAutofillOverlayMenu" }); this.postMessageToParent({ command: "closeAutofillInlineMenu" });
} }
} }

View File

@@ -13,7 +13,7 @@ export type OpenAutofillOverlayOptions = {
export type AutofillOverlayContentExtensionMessageHandlers = { export type AutofillOverlayContentExtensionMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
openAutofillOverlayMenu: ({ message }: AutofillExtensionMessageParam) => void; openAutofillInlineMenu: ({ message }: AutofillExtensionMessageParam) => void;
addNewVaultItemFromOverlay: () => void; addNewVaultItemFromOverlay: () => void;
blurMostRecentOverlayField: () => void; blurMostRecentOverlayField: () => void;
bgUnlockPopoutOpened: () => void; bgUnlockPopoutOpened: () => void;

View File

@@ -321,7 +321,7 @@ describe("AutofillOverlayContentService", () => {
it("closes the autofill overlay when the `Escape` key is pressed", () => { it("closes the autofill overlay when the `Escape` key is pressed", () => {
autofillFieldElement.dispatchEvent(new KeyboardEvent("keyup", { code: "Escape" })); autofillFieldElement.dispatchEvent(new KeyboardEvent("keyup", { code: "Escape" }));
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });
@@ -364,7 +364,7 @@ describe("AutofillOverlayContentService", () => {
); );
const openAutofillOverlaySpy = jest.spyOn( const openAutofillOverlaySpy = jest.spyOn(
autofillOverlayContentService as any, autofillOverlayContentService as any,
"openAutofillOverlayMenu", "openAutofillInlineMenu",
); );
jest jest
.spyOn(autofillOverlayContentService as any, "isInlineMenuListVisible") .spyOn(autofillOverlayContentService as any, "isInlineMenuListVisible")
@@ -454,7 +454,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("input")); autofillFieldElement.dispatchEvent(new Event("input"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
@@ -475,14 +475,14 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("input")); autofillFieldElement.dispatchEvent(new Event("input"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });
it("opens the autofill overlay if the form field is empty", async () => { it("opens the autofill overlay if the form field is empty", async () => {
jest.spyOn(autofillOverlayContentService as any, "openAutofillOverlayMenu"); jest.spyOn(autofillOverlayContentService as any, "openAutofillInlineMenu");
(autofillFieldElement as HTMLInputElement).value = ""; (autofillFieldElement as HTMLInputElement).value = "";
await autofillOverlayContentService.setupAutofillOverlayListenerOnField( await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
@@ -492,12 +492,12 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("input")); autofillFieldElement.dispatchEvent(new Event("input"));
await flushPromises(); await flushPromises();
expect(autofillOverlayContentService["openAutofillOverlayMenu"]).toHaveBeenCalled(); expect(autofillOverlayContentService["openAutofillInlineMenu"]).toHaveBeenCalled();
}); });
it("opens the autofill overlay if the form field is empty and the user is authed", async () => { it("opens the autofill overlay if the form field is empty and the user is authed", async () => {
jest.spyOn(autofillOverlayContentService as any, "isUserAuthed").mockReturnValue(true); jest.spyOn(autofillOverlayContentService as any, "isUserAuthed").mockReturnValue(true);
jest.spyOn(autofillOverlayContentService as any, "openAutofillOverlayMenu"); jest.spyOn(autofillOverlayContentService as any, "openAutofillInlineMenu");
(autofillFieldElement as HTMLInputElement).value = ""; (autofillFieldElement as HTMLInputElement).value = "";
await autofillOverlayContentService.setupAutofillOverlayListenerOnField( await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
@@ -507,7 +507,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("input")); autofillFieldElement.dispatchEvent(new Event("input"));
await flushPromises(); await flushPromises();
expect(autofillOverlayContentService["openAutofillOverlayMenu"]).toHaveBeenCalled(); expect(autofillOverlayContentService["openAutofillInlineMenu"]).toHaveBeenCalled();
}); });
it("opens the autofill overlay if the form field is empty and the overlay ciphers are not populated", async () => { it("opens the autofill overlay if the form field is empty and the overlay ciphers are not populated", async () => {
@@ -515,7 +515,7 @@ describe("AutofillOverlayContentService", () => {
jest jest
.spyOn(autofillOverlayContentService as any, "isInlineMenuCiphersPopulated") .spyOn(autofillOverlayContentService as any, "isInlineMenuCiphersPopulated")
.mockResolvedValue(false); .mockResolvedValue(false);
jest.spyOn(autofillOverlayContentService as any, "openAutofillOverlayMenu"); jest.spyOn(autofillOverlayContentService as any, "openAutofillInlineMenu");
(autofillFieldElement as HTMLInputElement).value = ""; (autofillFieldElement as HTMLInputElement).value = "";
await autofillOverlayContentService.setupAutofillOverlayListenerOnField( await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
@@ -525,7 +525,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("input")); autofillFieldElement.dispatchEvent(new Event("input"));
await flushPromises(); await flushPromises();
expect(autofillOverlayContentService["openAutofillOverlayMenu"]).toHaveBeenCalled(); expect(autofillOverlayContentService["openAutofillInlineMenu"]).toHaveBeenCalled();
}); });
}); });
@@ -633,7 +633,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("focus")); autofillFieldElement.dispatchEvent(new Event("focus"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
@@ -652,7 +652,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("focus")); autofillFieldElement.dispatchEvent(new Event("focus"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
@@ -670,7 +670,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("focus")); autofillFieldElement.dispatchEvent(new Event("focus"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillOverlayMenu"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillInlineMenu");
}); });
it("opens the autofill overlay if the overlay ciphers are not populated and the user is authed", async () => { it("opens the autofill overlay if the overlay ciphers are not populated and the user is authed", async () => {
@@ -686,7 +686,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("focus")); autofillFieldElement.dispatchEvent(new Event("focus"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillOverlayMenu"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillInlineMenu");
}); });
it("updates the overlay button position if the focus event is not opening the overlay", async () => { it("updates the overlay button position if the focus event is not opening the overlay", async () => {
@@ -726,7 +726,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldData, autofillFieldData,
); );
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillOverlayMenu"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillInlineMenu");
expect(autofillOverlayContentService["mostRecentlyFocusedField"]).toEqual( expect(autofillOverlayContentService["mostRecentlyFocusedField"]).toEqual(
autofillFieldElement, autofillFieldElement,
); );
@@ -746,7 +746,7 @@ describe("AutofillOverlayContentService", () => {
}); });
}); });
describe("openAutofillOverlayMenu", () => { describe("openAutofillInlineMenu", () => {
let autofillFieldElement: ElementWithOpId<FormFieldElement>; let autofillFieldElement: ElementWithOpId<FormFieldElement>;
beforeEach(() => { beforeEach(() => {
@@ -767,7 +767,7 @@ describe("AutofillOverlayContentService", () => {
it("skips opening the overlay if a field has not been recently focused", () => { it("skips opening the overlay if a field has not been recently focused", () => {
autofillOverlayContentService["mostRecentlyFocusedField"] = undefined; autofillOverlayContentService["mostRecentlyFocusedField"] = undefined;
autofillOverlayContentService["openAutofillOverlayMenu"](); autofillOverlayContentService["openAutofillInlineMenu"]();
expect(sendExtensionMessageSpy).not.toHaveBeenCalled(); expect(sendExtensionMessageSpy).not.toHaveBeenCalled();
}); });
@@ -783,7 +783,7 @@ describe("AutofillOverlayContentService", () => {
"focusMostRecentOverlayField", "focusMostRecentOverlayField",
); );
autofillOverlayContentService["openAutofillOverlayMenu"]({ isFocusingFieldElement: true }); autofillOverlayContentService["openAutofillInlineMenu"]({ isFocusingFieldElement: true });
expect(focusMostRecentOverlayFieldSpy).toHaveBeenCalled(); expect(focusMostRecentOverlayFieldSpy).toHaveBeenCalled();
}); });
@@ -799,7 +799,7 @@ describe("AutofillOverlayContentService", () => {
"focusMostRecentOverlayField", "focusMostRecentOverlayField",
); );
autofillOverlayContentService["openAutofillOverlayMenu"]({ isFocusingFieldElement: true }); autofillOverlayContentService["openAutofillInlineMenu"]({ isFocusingFieldElement: true });
expect(focusMostRecentOverlayFieldSpy).not.toHaveBeenCalled(); expect(focusMostRecentOverlayFieldSpy).not.toHaveBeenCalled();
}); });
@@ -807,7 +807,7 @@ describe("AutofillOverlayContentService", () => {
it("stores the user's auth status", () => { it("stores the user's auth status", () => {
autofillOverlayContentService["authStatus"] = undefined; autofillOverlayContentService["authStatus"] = undefined;
autofillOverlayContentService["openAutofillOverlayMenu"]({ autofillOverlayContentService["openAutofillInlineMenu"]({
authStatus: AuthenticationStatus.Unlocked, authStatus: AuthenticationStatus.Unlocked,
}); });
@@ -817,7 +817,7 @@ describe("AutofillOverlayContentService", () => {
it("opens both autofill overlay elements", () => { it("opens both autofill overlay elements", () => {
autofillOverlayContentService["mostRecentlyFocusedField"] = autofillFieldElement; autofillOverlayContentService["mostRecentlyFocusedField"] = autofillFieldElement;
autofillOverlayContentService["openAutofillOverlayMenu"](); autofillOverlayContentService["openAutofillInlineMenu"]();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
@@ -831,7 +831,7 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["inlineMenuVisibility"] = autofillOverlayContentService["inlineMenuVisibility"] =
AutofillOverlayVisibility.OnButtonClick; AutofillOverlayVisibility.OnButtonClick;
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: false }); autofillOverlayContentService["openAutofillInlineMenu"]({ isOpeningFullOverlay: false });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
@@ -848,7 +848,7 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["inlineMenuVisibility"] = autofillOverlayContentService["inlineMenuVisibility"] =
AutofillOverlayVisibility.OnButtonClick; AutofillOverlayVisibility.OnButtonClick;
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: true }); autofillOverlayContentService["openAutofillInlineMenu"]({ isOpeningFullOverlay: true });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
@@ -862,7 +862,7 @@ describe("AutofillOverlayContentService", () => {
jest.spyOn(autofillOverlayContentService as any, "sendExtensionMessage"); jest.spyOn(autofillOverlayContentService as any, "sendExtensionMessage");
autofillOverlayContentService.pageDetailsUpdateRequired = true; autofillOverlayContentService.pageDetailsUpdateRequired = true;
autofillOverlayContentService["openAutofillOverlayMenu"](); autofillOverlayContentService["openAutofillInlineMenu"]();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("bgCollectPageDetails", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("bgCollectPageDetails", {
sender: "autofillOverlayContentService", sender: "autofillOverlayContentService",
@@ -1028,7 +1028,7 @@ describe("AutofillOverlayContentService", () => {
await autofillOverlayContentService.redirectOverlayFocusOut(RedirectFocusDirection.Current); await autofillOverlayContentService.redirectOverlayFocusOut(RedirectFocusDirection.Current);
jest.advanceTimersByTime(150); jest.advanceTimersByTime(150);
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu");
}); });
it("finds all focusable tabs if the focusable elements array is not populated", async () => { it("finds all focusable tabs if the focusable elements array is not populated", async () => {
@@ -1136,7 +1136,7 @@ describe("AutofillOverlayContentService", () => {
isOverlayHidden: false, isOverlayHidden: false,
setTransparentOverlay: true, setTransparentOverlay: true,
}); });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });
@@ -1190,7 +1190,7 @@ describe("AutofillOverlayContentService", () => {
jest.advanceTimersByTime(800); jest.advanceTimersByTime(800);
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });
@@ -1200,7 +1200,7 @@ describe("AutofillOverlayContentService", () => {
it("skips removing the overlay if the document is visible", () => { it("skips removing the overlay if the document is visible", () => {
autofillOverlayContentService["handleVisibilityChangeEvent"](); autofillOverlayContentService["handleVisibilityChangeEvent"]();
expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });
@@ -1214,7 +1214,7 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["handleVisibilityChangeEvent"](); autofillOverlayContentService["handleVisibilityChangeEvent"]();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}); });

View File

@@ -41,7 +41,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
private autofillFieldKeywordsMap: WeakMap<AutofillField, string> = new WeakMap(); private autofillFieldKeywordsMap: WeakMap<AutofillField, string> = new WeakMap();
private eventHandlersMemo: { [key: string]: EventListener } = {}; private eventHandlersMemo: { [key: string]: EventListener } = {};
readonly extensionMessageHandlers: AutofillOverlayContentExtensionMessageHandlers = { readonly extensionMessageHandlers: AutofillOverlayContentExtensionMessageHandlers = {
openAutofillOverlayMenu: ({ message }) => this.openAutofillOverlayMenu(message), openAutofillInlineMenu: ({ message }) => this.openAutofillInlineMenu(message),
addNewVaultItemFromOverlay: () => this.addNewVaultItem(), addNewVaultItemFromOverlay: () => this.addNewVaultItem(),
blurMostRecentOverlayField: () => this.blurMostRecentOverlayField(), blurMostRecentOverlayField: () => this.blurMostRecentOverlayField(),
bgUnlockPopoutOpened: () => this.blurMostRecentOverlayField(true), bgUnlockPopoutOpened: () => this.blurMostRecentOverlayField(true),
@@ -111,7 +111,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* *
* @param options - Options for opening the autofill overlay. * @param options - Options for opening the autofill overlay.
*/ */
openAutofillOverlayMenu(options: OpenAutofillOverlayOptions = {}) { openAutofillInlineMenu(options: OpenAutofillOverlayOptions = {}) {
const { isFocusingFieldElement, isOpeningFullOverlay, authStatus } = options; const { isFocusingFieldElement, isOpeningFullOverlay, authStatus } = options;
if (!this.mostRecentlyFocusedField) { if (!this.mostRecentlyFocusedField) {
return; return;
@@ -157,7 +157,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.mostRecentlyFocusedField?.blur(); this.mostRecentlyFocusedField?.blur();
if (isRemovingOverlay) { if (isRemovingOverlay) {
void sendExtensionMessage("closeAutofillOverlayMenu"); void sendExtensionMessage("closeAutofillInlineMenu");
} }
} }
@@ -194,7 +194,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
if (direction === RedirectFocusDirection.Current) { if (direction === RedirectFocusDirection.Current) {
this.focusMostRecentOverlayField(); this.focusMostRecentOverlayField();
setTimeout(() => void this.sendExtensionMessage("closeAutofillOverlayMenu"), 100); setTimeout(() => void this.sendExtensionMessage("closeAutofillInlineMenu"), 100);
return; return;
} }
@@ -304,7 +304,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => { private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => {
const eventCode = event.code; const eventCode = event.code;
if (eventCode === "Escape") { if (eventCode === "Escape") {
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
return; return;
@@ -331,7 +331,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
private async focusOverlayMenuList() { private async focusOverlayMenuList() {
if (this.mostRecentlyFocusedField && !(await this.isInlineMenuListVisible())) { if (this.mostRecentlyFocusedField && !(await this.isInlineMenuListVisible())) {
await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField); await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField);
this.openAutofillOverlayMenu({ isOpeningFullOverlay: true }); this.openAutofillInlineMenu({ isOpeningFullOverlay: true });
setTimeout(() => this.sendExtensionMessage("focusAutofillOverlayMenuList"), 125); setTimeout(() => this.sendExtensionMessage("focusAutofillOverlayMenuList"), 125);
return; return;
} }
@@ -366,14 +366,14 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.storeModifiedFormElement(formFieldElement); this.storeModifiedFormElement(formFieldElement);
if (await this.hideOverlayListOnFilledField(formFieldElement)) { if (await this.hideOverlayListOnFilledField(formFieldElement)) {
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
return; return;
} }
this.openAutofillOverlayMenu(); this.openAutofillInlineMenu();
} }
/** /**
@@ -459,7 +459,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.inlineMenuVisibility === AutofillOverlayVisibility.OnButtonClick || this.inlineMenuVisibility === AutofillOverlayVisibility.OnButtonClick ||
(formElementHasValue && initiallyFocusedField !== this.mostRecentlyFocusedField) (formElementHasValue && initiallyFocusedField !== this.mostRecentlyFocusedField)
) { ) {
await this.sendExtensionMessage("closeAutofillOverlayMenu", { await this.sendExtensionMessage("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
@@ -470,7 +470,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
return; return;
} }
void this.sendExtensionMessage("openAutofillOverlayMenu"); void this.sendExtensionMessage("openAutofillInlineMenu");
} }
/** /**
@@ -780,7 +780,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
private triggerOverlayRepositionUpdates = async () => { private triggerOverlayRepositionUpdates = async () => {
if (!this.recentlyFocusedFieldIsCurrentlyFocused()) { if (!this.recentlyFocusedFieldIsCurrentlyFocused()) {
this.toggleOverlayHidden(false, true); this.toggleOverlayHidden(false, true);
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
return; return;
@@ -795,7 +795,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.mostRecentlyFocusedField as FillableFormFieldElement, this.mostRecentlyFocusedField as FillableFormFieldElement,
) )
) { ) {
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
@@ -807,7 +807,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
return; return;
} }
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}; };
@@ -868,7 +868,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
} }
this.mostRecentlyFocusedField = null; this.mostRecentlyFocusedField = null;
void this.sendExtensionMessage("closeAutofillOverlayMenu", { void this.sendExtensionMessage("closeAutofillInlineMenu", {
forceCloseOverlay: true, forceCloseOverlay: true,
}); });
}; };