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:
@@ -92,8 +92,8 @@ type BackgroundOnMessageHandlerParams = BackgroundMessageParam & BackgroundSende
|
||||
|
||||
type OverlayBackgroundExtensionMessageHandlers = {
|
||||
[key: string]: CallableFunction;
|
||||
openAutofillOverlayMenu: () => void;
|
||||
closeAutofillOverlayMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||
openAutofillInlineMenu: () => void;
|
||||
closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
|
||||
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||
getInlineMenuVisibilitySetting: () => void;
|
||||
@@ -131,7 +131,7 @@ type PortOnMessageHandlerParams = PortMessageParam & PortConnectionParam;
|
||||
type OverlayButtonPortMessageHandlers = {
|
||||
[key: string]: CallableFunction;
|
||||
overlayButtonClicked: ({ port }: PortConnectionParam) => void;
|
||||
closeAutofillOverlayMenu: ({ port }: PortConnectionParam) => void;
|
||||
closeAutofillInlineMenu: ({ port }: PortConnectionParam) => void;
|
||||
forceCloseAutofillOverlay: ({ port }: PortConnectionParam) => void;
|
||||
overlayPageBlurred: () => void;
|
||||
redirectOverlayFocusOut: ({ message, port }: PortOnMessageHandlerParams) => void;
|
||||
|
||||
@@ -536,7 +536,7 @@ describe("OverlayBackground", () => {
|
||||
|
||||
it("will return a response if the message handler returns a response", async () => {
|
||||
const message = {
|
||||
command: "openAutofillOverlayMenu",
|
||||
command: "openAutofillInlineMenu",
|
||||
};
|
||||
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
|
||||
const sendResponse = jest.fn();
|
||||
@@ -552,17 +552,17 @@ describe("OverlayBackground", () => {
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
|
||||
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
|
||||
jest.spyOn(BrowserApi, "tabSendMessage").mockImplementation();
|
||||
|
||||
sendMockExtensionMessage({ command: "openAutofillOverlayMenu" });
|
||||
sendMockExtensionMessage({ command: "openAutofillInlineMenu" });
|
||||
await flushPromises();
|
||||
|
||||
expect(BrowserApi.tabSendMessage).not.toHaveBeenCalledWith(sender.tab, {
|
||||
command: "openAutofillOverlayMenu",
|
||||
command: "openAutofillInlineMenu",
|
||||
isFocusingFieldElement: false,
|
||||
isOpeningFullOverlay: false,
|
||||
authStatus: AuthenticationStatus.Unlocked,
|
||||
@@ -984,7 +984,7 @@ describe("OverlayBackground", () => {
|
||||
const message = {
|
||||
command: "unlockCompleted",
|
||||
data: {
|
||||
commandToRetry: { message: { command: "openAutofillOverlayMenu" } },
|
||||
commandToRetry: { message: { command: "openAutofillInlineMenu" } },
|
||||
},
|
||||
};
|
||||
jest.spyOn(BrowserApi, "getTabFromCurrentWindowId").mockResolvedValueOnce(sender.tab);
|
||||
@@ -996,7 +996,7 @@ describe("OverlayBackground", () => {
|
||||
expect(BrowserApi.tabSendMessage).toHaveBeenCalledWith(
|
||||
sender.tab,
|
||||
{
|
||||
command: "openAutofillOverlayMenu",
|
||||
command: "openAutofillInlineMenu",
|
||||
isFocusingFieldElement: true,
|
||||
isOpeningFullOverlay: false,
|
||||
authStatus: AuthenticationStatus.Unlocked,
|
||||
@@ -1147,23 +1147,23 @@ describe("OverlayBackground", () => {
|
||||
});
|
||||
|
||||
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, {
|
||||
command: "overlayButtonClicked",
|
||||
portKey,
|
||||
});
|
||||
|
||||
expect(overlayBackground["openOverlayMenu"]).toHaveBeenCalled();
|
||||
expect(overlayBackground["openInlineMenu"]).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// TODO: The tests for `closeAutofillOverlayMenu` and `forceCloseAutofillOverlay` need to be fleshed out
|
||||
describe("closeAutofillOverlayMenu", () => {
|
||||
// TODO: The tests for `closeAutofillInlineMenu` and `forceCloseAutofillOverlay` need to be fleshed out
|
||||
describe("closeAutofillInlineMenu", () => {
|
||||
it("sends a `closeOverlay` message to the sender tab", () => {
|
||||
jest.spyOn(BrowserApi, "tabSendMessage");
|
||||
|
||||
sendPortMessage(buttonMessageConnectorPortSpy, {
|
||||
command: "closeAutofillOverlayMenu",
|
||||
command: "closeAutofillInlineMenu",
|
||||
portKey,
|
||||
});
|
||||
|
||||
@@ -1284,14 +1284,14 @@ describe("OverlayBackground", () => {
|
||||
|
||||
describe("unlockVault", () => {
|
||||
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(BrowserApi, "tabSendMessageData").mockImplementation();
|
||||
|
||||
sendPortMessage(listMessageConnectorPortSpy, { command: "unlockVault", portKey });
|
||||
await flushPromises();
|
||||
|
||||
expect(overlayBackground["closeOverlayMenu"]).toHaveBeenCalledWith(
|
||||
expect(overlayBackground["closeInlineMenu"]).toHaveBeenCalledWith(
|
||||
listMessageConnectorPortSpy.sender,
|
||||
);
|
||||
expect(BrowserApi.tabSendMessageData).toHaveBeenCalledWith(
|
||||
@@ -1299,7 +1299,7 @@ describe("OverlayBackground", () => {
|
||||
"addToLockedVaultPendingNotifications",
|
||||
{
|
||||
commandToRetry: {
|
||||
message: { command: "openAutofillOverlayMenu" },
|
||||
message: { command: "openAutofillInlineMenu" },
|
||||
sender: listMessageConnectorPortSpy.sender,
|
||||
},
|
||||
target: "overlay.background",
|
||||
|
||||
@@ -64,8 +64,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
private overlayPageTranslations: Record<string, string>;
|
||||
private iconsServerUrl: string;
|
||||
private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = {
|
||||
openAutofillOverlayMenu: () => this.openOverlayMenu(false),
|
||||
closeAutofillOverlayMenu: ({ message, sender }) => this.closeOverlayMenu(sender, message),
|
||||
openAutofillInlineMenu: () => this.openInlineMenu(false),
|
||||
closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message),
|
||||
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
|
||||
autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender),
|
||||
getInlineMenuVisibilitySetting: () => this.getInlineMenuVisibility(),
|
||||
@@ -93,9 +93,9 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
};
|
||||
private readonly overlayButtonPortMessageHandlers: OverlayButtonPortMessageHandlers = {
|
||||
overlayButtonClicked: ({ port }) => this.handleOverlayButtonClicked(port),
|
||||
closeAutofillOverlayMenu: ({ port }) => this.closeOverlayMenu(port.sender),
|
||||
closeAutofillInlineMenu: ({ port }) => this.closeInlineMenu(port.sender),
|
||||
forceCloseAutofillOverlay: ({ port }) =>
|
||||
this.closeOverlayMenu(port.sender, { forceCloseOverlay: true }),
|
||||
this.closeInlineMenu(port.sender, { forceCloseOverlay: true }),
|
||||
overlayPageBlurred: () => this.checkOverlayListFocused(),
|
||||
redirectOverlayFocusOut: ({ message, port }) => this.redirectOverlayFocusOut(message, port),
|
||||
updateOverlayPageColorScheme: () => this.updateButtonPageColorScheme(),
|
||||
@@ -103,7 +103,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
private readonly overlayListPortMessageHandlers: OverlayListPortMessageHandlers = {
|
||||
checkAutofillOverlayButtonFocused: () => this.checkOverlayButtonFocused(),
|
||||
forceCloseAutofillOverlay: ({ port }) =>
|
||||
this.closeOverlayMenu(port.sender, { forceCloseOverlay: true }),
|
||||
this.closeInlineMenu(port.sender, { forceCloseOverlay: true }),
|
||||
overlayPageBlurred: () => this.checkOverlayButtonFocused(),
|
||||
unlockVault: ({ port }) => this.unlockVault(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 overlayElement - The overlay element to close, either the list or button
|
||||
*/
|
||||
private closeOverlayMenu(
|
||||
private closeInlineMenu(
|
||||
sender: chrome.runtime.MessageSender,
|
||||
{
|
||||
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 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();
|
||||
|
||||
await BrowserApi.tabSendMessage(
|
||||
currentTab,
|
||||
{
|
||||
command: "openAutofillOverlayMenu",
|
||||
command: "openAutofillInlineMenu",
|
||||
isFocusingFieldElement,
|
||||
isOpeningFullOverlay,
|
||||
authStatus: await this.getAuthStatus(),
|
||||
@@ -688,7 +688,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
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) {
|
||||
const { sender } = port;
|
||||
|
||||
this.closeOverlayMenu(port.sender);
|
||||
this.closeInlineMenu(port.sender);
|
||||
const retryMessage: LockedVaultPendingNotificationsData = {
|
||||
commandToRetry: { message: { command: "openAutofillOverlayMenu" }, sender },
|
||||
commandToRetry: { message: { command: "openAutofillInlineMenu" }, sender },
|
||||
target: "overlay.background",
|
||||
};
|
||||
await BrowserApi.tabSendMessageData(
|
||||
@@ -749,8 +749,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
private async unlockCompleted(message: OverlayBackgroundExtensionMessage) {
|
||||
await this.getAuthStatus();
|
||||
|
||||
if (message.data?.commandToRetry?.message?.command === "openAutofillOverlayMenu") {
|
||||
await this.openOverlayMenu(true);
|
||||
if (message.data?.commandToRetry?.message?.command === "openAutofillInlineMenu") {
|
||||
await this.openInlineMenu(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ describe("AutofillOverlayIframeService", () => {
|
||||
autofillOverlayIframeService["iframe"].src = "http://malicious-site.com";
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceClose: true,
|
||||
});
|
||||
});
|
||||
@@ -471,7 +471,7 @@ describe("AutofillOverlayIframeService", () => {
|
||||
autofillOverlayIframeService["iframe"].src = "http://malicious-site.com";
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceClose: true,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -324,7 +324,7 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
|
||||
* mutation observer is triggered excessively.
|
||||
*/
|
||||
private forceCloseAutofillOverlay() {
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", { forceClose: true });
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ describe("AutofillOverlayButton", () => {
|
||||
await flushPromises();
|
||||
|
||||
expect(globalThis.parent.postMessage).not.toHaveBeenCalledWith({
|
||||
command: "closeAutofillOverlayMenu",
|
||||
command: "closeAutofillInlineMenu",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ describe("AutofillOverlayButton", () => {
|
||||
await flushPromises();
|
||||
|
||||
expect(globalThis.parent.postMessage).toHaveBeenCalledWith(
|
||||
{ command: "closeAutofillOverlayMenu", portKey },
|
||||
{ command: "closeAutofillInlineMenu", portKey },
|
||||
"*",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -115,7 +115,7 @@ class AutofillOverlayButton extends AutofillOverlayPageElement {
|
||||
return;
|
||||
}
|
||||
|
||||
this.postMessageToParent({ command: "closeAutofillOverlayMenu" });
|
||||
this.postMessageToParent({ command: "closeAutofillInlineMenu" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export type OpenAutofillOverlayOptions = {
|
||||
|
||||
export type AutofillOverlayContentExtensionMessageHandlers = {
|
||||
[key: string]: CallableFunction;
|
||||
openAutofillOverlayMenu: ({ message }: AutofillExtensionMessageParam) => void;
|
||||
openAutofillInlineMenu: ({ message }: AutofillExtensionMessageParam) => void;
|
||||
addNewVaultItemFromOverlay: () => void;
|
||||
blurMostRecentOverlayField: () => void;
|
||||
bgUnlockPopoutOpened: () => void;
|
||||
|
||||
@@ -321,7 +321,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
it("closes the autofill overlay when the `Escape` key is pressed", () => {
|
||||
autofillFieldElement.dispatchEvent(new KeyboardEvent("keyup", { code: "Escape" }));
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
@@ -364,7 +364,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
);
|
||||
const openAutofillOverlaySpy = jest.spyOn(
|
||||
autofillOverlayContentService as any,
|
||||
"openAutofillOverlayMenu",
|
||||
"openAutofillInlineMenu",
|
||||
);
|
||||
jest
|
||||
.spyOn(autofillOverlayContentService as any, "isInlineMenuListVisible")
|
||||
@@ -454,7 +454,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("input"));
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
@@ -475,14 +475,14 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("input"));
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
|
||||
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 = "";
|
||||
|
||||
await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
|
||||
@@ -492,12 +492,12 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("input"));
|
||||
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 () => {
|
||||
jest.spyOn(autofillOverlayContentService as any, "isUserAuthed").mockReturnValue(true);
|
||||
jest.spyOn(autofillOverlayContentService as any, "openAutofillOverlayMenu");
|
||||
jest.spyOn(autofillOverlayContentService as any, "openAutofillInlineMenu");
|
||||
(autofillFieldElement as HTMLInputElement).value = "";
|
||||
|
||||
await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
|
||||
@@ -507,7 +507,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("input"));
|
||||
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 () => {
|
||||
@@ -515,7 +515,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
jest
|
||||
.spyOn(autofillOverlayContentService as any, "isInlineMenuCiphersPopulated")
|
||||
.mockResolvedValue(false);
|
||||
jest.spyOn(autofillOverlayContentService as any, "openAutofillOverlayMenu");
|
||||
jest.spyOn(autofillOverlayContentService as any, "openAutofillInlineMenu");
|
||||
(autofillFieldElement as HTMLInputElement).value = "";
|
||||
|
||||
await autofillOverlayContentService.setupAutofillOverlayListenerOnField(
|
||||
@@ -525,7 +525,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("input"));
|
||||
await flushPromises();
|
||||
|
||||
expect(autofillOverlayContentService["openAutofillOverlayMenu"]).toHaveBeenCalled();
|
||||
expect(autofillOverlayContentService["openAutofillInlineMenu"]).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -633,7 +633,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("focus"));
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
@@ -652,7 +652,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("focus"));
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
@@ -670,7 +670,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("focus"));
|
||||
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 () => {
|
||||
@@ -686,7 +686,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldElement.dispatchEvent(new Event("focus"));
|
||||
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 () => {
|
||||
@@ -726,7 +726,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillFieldData,
|
||||
);
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillOverlayMenu");
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("openAutofillInlineMenu");
|
||||
expect(autofillOverlayContentService["mostRecentlyFocusedField"]).toEqual(
|
||||
autofillFieldElement,
|
||||
);
|
||||
@@ -746,7 +746,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("openAutofillOverlayMenu", () => {
|
||||
describe("openAutofillInlineMenu", () => {
|
||||
let autofillFieldElement: ElementWithOpId<FormFieldElement>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -767,7 +767,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
it("skips opening the overlay if a field has not been recently focused", () => {
|
||||
autofillOverlayContentService["mostRecentlyFocusedField"] = undefined;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]();
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]();
|
||||
|
||||
expect(sendExtensionMessageSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -783,7 +783,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
"focusMostRecentOverlayField",
|
||||
);
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]({ isFocusingFieldElement: true });
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]({ isFocusingFieldElement: true });
|
||||
|
||||
expect(focusMostRecentOverlayFieldSpy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -799,7 +799,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
"focusMostRecentOverlayField",
|
||||
);
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]({ isFocusingFieldElement: true });
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]({ isFocusingFieldElement: true });
|
||||
|
||||
expect(focusMostRecentOverlayFieldSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -807,7 +807,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
it("stores the user's auth status", () => {
|
||||
autofillOverlayContentService["authStatus"] = undefined;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]({
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]({
|
||||
authStatus: AuthenticationStatus.Unlocked,
|
||||
});
|
||||
|
||||
@@ -817,7 +817,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
it("opens both autofill overlay elements", () => {
|
||||
autofillOverlayContentService["mostRecentlyFocusedField"] = autofillFieldElement;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]();
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
|
||||
overlayElement: AutofillOverlayElement.Button,
|
||||
@@ -831,7 +831,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillOverlayContentService["inlineMenuVisibility"] =
|
||||
AutofillOverlayVisibility.OnButtonClick;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: false });
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]({ isOpeningFullOverlay: false });
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
|
||||
overlayElement: AutofillOverlayElement.Button,
|
||||
@@ -848,7 +848,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillOverlayContentService["inlineMenuVisibility"] =
|
||||
AutofillOverlayVisibility.OnButtonClick;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: true });
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]({ isOpeningFullOverlay: true });
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
|
||||
overlayElement: AutofillOverlayElement.Button,
|
||||
@@ -862,7 +862,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
jest.spyOn(autofillOverlayContentService as any, "sendExtensionMessage");
|
||||
autofillOverlayContentService.pageDetailsUpdateRequired = true;
|
||||
|
||||
autofillOverlayContentService["openAutofillOverlayMenu"]();
|
||||
autofillOverlayContentService["openAutofillInlineMenu"]();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("bgCollectPageDetails", {
|
||||
sender: "autofillOverlayContentService",
|
||||
@@ -1028,7 +1028,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
await autofillOverlayContentService.redirectOverlayFocusOut(RedirectFocusDirection.Current);
|
||||
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 () => {
|
||||
@@ -1136,7 +1136,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
isOverlayHidden: false,
|
||||
setTransparentOverlay: true,
|
||||
});
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
@@ -1190,7 +1190,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
jest.advanceTimersByTime(800);
|
||||
await flushPromises();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
@@ -1200,7 +1200,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
it("skips removing the overlay if the document is visible", () => {
|
||||
autofillOverlayContentService["handleVisibilityChangeEvent"]();
|
||||
|
||||
expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
@@ -1214,7 +1214,7 @@ describe("AutofillOverlayContentService", () => {
|
||||
|
||||
autofillOverlayContentService["handleVisibilityChangeEvent"]();
|
||||
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillOverlayMenu", {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
private autofillFieldKeywordsMap: WeakMap<AutofillField, string> = new WeakMap();
|
||||
private eventHandlersMemo: { [key: string]: EventListener } = {};
|
||||
readonly extensionMessageHandlers: AutofillOverlayContentExtensionMessageHandlers = {
|
||||
openAutofillOverlayMenu: ({ message }) => this.openAutofillOverlayMenu(message),
|
||||
openAutofillInlineMenu: ({ message }) => this.openAutofillInlineMenu(message),
|
||||
addNewVaultItemFromOverlay: () => this.addNewVaultItem(),
|
||||
blurMostRecentOverlayField: () => this.blurMostRecentOverlayField(),
|
||||
bgUnlockPopoutOpened: () => this.blurMostRecentOverlayField(true),
|
||||
@@ -111,7 +111,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
*
|
||||
* @param options - Options for opening the autofill overlay.
|
||||
*/
|
||||
openAutofillOverlayMenu(options: OpenAutofillOverlayOptions = {}) {
|
||||
openAutofillInlineMenu(options: OpenAutofillOverlayOptions = {}) {
|
||||
const { isFocusingFieldElement, isOpeningFullOverlay, authStatus } = options;
|
||||
if (!this.mostRecentlyFocusedField) {
|
||||
return;
|
||||
@@ -157,7 +157,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
this.mostRecentlyFocusedField?.blur();
|
||||
|
||||
if (isRemovingOverlay) {
|
||||
void sendExtensionMessage("closeAutofillOverlayMenu");
|
||||
void sendExtensionMessage("closeAutofillInlineMenu");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
|
||||
if (direction === RedirectFocusDirection.Current) {
|
||||
this.focusMostRecentOverlayField();
|
||||
setTimeout(() => void this.sendExtensionMessage("closeAutofillOverlayMenu"), 100);
|
||||
setTimeout(() => void this.sendExtensionMessage("closeAutofillInlineMenu"), 100);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => {
|
||||
const eventCode = event.code;
|
||||
if (eventCode === "Escape") {
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
return;
|
||||
@@ -331,7 +331,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
private async focusOverlayMenuList() {
|
||||
if (this.mostRecentlyFocusedField && !(await this.isInlineMenuListVisible())) {
|
||||
await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField);
|
||||
this.openAutofillOverlayMenu({ isOpeningFullOverlay: true });
|
||||
this.openAutofillInlineMenu({ isOpeningFullOverlay: true });
|
||||
setTimeout(() => this.sendExtensionMessage("focusAutofillOverlayMenuList"), 125);
|
||||
return;
|
||||
}
|
||||
@@ -366,14 +366,14 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
this.storeModifiedFormElement(formFieldElement);
|
||||
|
||||
if (await this.hideOverlayListOnFilledField(formFieldElement)) {
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.openAutofillOverlayMenu();
|
||||
this.openAutofillInlineMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,7 +459,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
this.inlineMenuVisibility === AutofillOverlayVisibility.OnButtonClick ||
|
||||
(formElementHasValue && initiallyFocusedField !== this.mostRecentlyFocusedField)
|
||||
) {
|
||||
await this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
await this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
@@ -470,7 +470,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
return;
|
||||
}
|
||||
|
||||
void this.sendExtensionMessage("openAutofillOverlayMenu");
|
||||
void this.sendExtensionMessage("openAutofillInlineMenu");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -780,7 +780,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
private triggerOverlayRepositionUpdates = async () => {
|
||||
if (!this.recentlyFocusedFieldIsCurrentlyFocused()) {
|
||||
this.toggleOverlayHidden(false, true);
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
return;
|
||||
@@ -795,7 +795,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
this.mostRecentlyFocusedField as FillableFormFieldElement,
|
||||
)
|
||||
) {
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
overlayElement: AutofillOverlayElement.List,
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
@@ -807,7 +807,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
return;
|
||||
}
|
||||
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
};
|
||||
@@ -868,7 +868,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
}
|
||||
|
||||
this.mostRecentlyFocusedField = null;
|
||||
void this.sendExtensionMessage("closeAutofillOverlayMenu", {
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", {
|
||||
forceCloseOverlay: true,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user