1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PM-5189] Refactoring implementation

This commit is contained in:
Cesar Gonzalez
2024-04-16 14:58:09 -05:00
parent 96dadbfb4b
commit 43ba6256dc
9 changed files with 87 additions and 71 deletions

View File

@@ -97,13 +97,13 @@ type OverlayBackgroundExtensionMessageHandlers = {
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void; autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
getAutofillOverlayVisibility: () => void; getAutofillOverlayVisibility: () => void;
checkAutofillOverlayFocused: () => void; checkAutofillOverlayMenuFocused: () => void;
focusAutofillOverlayList: () => void; focusAutofillOverlayList: () => void;
updateAutofillOverlayPosition: ({ updateAutofillOverlayMenuPosition: ({
message, message,
sender, sender,
}: BackgroundOnMessageHandlerParams) => Promise<void>; }: BackgroundOnMessageHandlerParams) => Promise<void>;
updateAutofillOverlayHidden: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; updateAutofillOverlayMenuHidden: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
updateFocusedFieldData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; updateFocusedFieldData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
updateIsFieldCurrentlyFocused: ({ message }: BackgroundMessageParam) => void; updateIsFieldCurrentlyFocused: ({ message }: BackgroundMessageParam) => void;
checkIsFieldCurrentlyFocused: () => boolean; checkIsFieldCurrentlyFocused: () => boolean;
@@ -111,7 +111,7 @@ type OverlayBackgroundExtensionMessageHandlers = {
checkIsFieldCurrentlyFilling: () => boolean; checkIsFieldCurrentlyFilling: () => boolean;
checkIsInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void; checkIsInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void;
checkIsInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void; checkIsInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void;
checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; checkIsOverlayLoginCiphersPopulated: ({ sender }: BackgroundSenderParam) => void;
updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void; rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void;
collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;

View File

@@ -668,13 +668,13 @@ describe("OverlayBackground", () => {
}); });
}); });
describe("checkAutofillOverlayFocused message handler", () => { describe("checkAutofillOverlayMenuFocused message handler", () => {
beforeEach(async () => { beforeEach(async () => {
await initOverlayElementPorts(); await initOverlayElementPorts();
}); });
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", () => {
sendMockExtensionMessage({ command: "checkAutofillOverlayFocused" }); sendMockExtensionMessage({ command: "checkAutofillOverlayMenuFocused" });
expect(listPortSpy.postMessage).toHaveBeenCalledWith({ expect(listPortSpy.postMessage).toHaveBeenCalledWith({
command: "checkAutofillOverlayListFocused", command: "checkAutofillOverlayListFocused",
@@ -687,7 +687,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;
sendMockExtensionMessage({ command: "checkAutofillOverlayFocused" }); sendMockExtensionMessage({ command: "checkAutofillOverlayMenuFocused" });
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({ expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
command: "checkAutofillOverlayButtonFocused", command: "checkAutofillOverlayButtonFocused",
@@ -713,7 +713,7 @@ describe("OverlayBackground", () => {
}); });
}); });
describe("updateAutofillOverlayPosition message handler", () => { describe("updateAutofillOverlayMenuPosition message handler", () => {
let sender: MockProxy<chrome.runtime.MessageSender>; let sender: MockProxy<chrome.runtime.MessageSender>;
beforeEach(async () => { beforeEach(async () => {
@@ -731,7 +731,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", () => {
sendMockExtensionMessage({ command: "updateAutofillOverlayPosition" }, sender); sendMockExtensionMessage({ command: "updateAutofillOverlayMenuPosition" }, sender);
expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({ expect(listPortSpy.postMessage).not.toHaveBeenCalledWith({
command: "updateIframePosition", command: "updateIframePosition",
@@ -749,7 +749,7 @@ describe("OverlayBackground", () => {
sendMockExtensionMessage( sendMockExtensionMessage(
{ {
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayMenuPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}, },
sender, sender,
@@ -770,7 +770,7 @@ describe("OverlayBackground", () => {
sendMockExtensionMessage( sendMockExtensionMessage(
{ {
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayMenuPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}, },
sender, sender,
@@ -791,7 +791,7 @@ describe("OverlayBackground", () => {
sendMockExtensionMessage( sendMockExtensionMessage(
{ {
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayMenuPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}, },
sender, sender,
@@ -812,7 +812,7 @@ describe("OverlayBackground", () => {
sendMockExtensionMessage( sendMockExtensionMessage(
{ {
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayMenuPosition",
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}, },
sender, sender,
@@ -831,7 +831,7 @@ describe("OverlayBackground", () => {
sendMockExtensionMessage( sendMockExtensionMessage(
{ {
command: "updateAutofillOverlayPosition", command: "updateAutofillOverlayMenuPosition",
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}, },
sender, sender,
@@ -845,24 +845,24 @@ describe("OverlayBackground", () => {
}); });
}); });
describe("updateOverlayHidden", () => { describe("updateOverlayMenuHidden", () => {
beforeEach(async () => { beforeEach(async () => {
await initOverlayElementPorts(); await initOverlayElementPorts();
}); });
it("sets the `display` CSS value on the overlay button and list", () => { it("sets the `display` CSS value on the overlay button and list", () => {
const message = { command: "updateAutofillOverlayHidden", isOverlayHidden: true }; const message = { command: "updateAutofillOverlayMenuHidden", isOverlayHidden: true };
sendMockExtensionMessage(message); sendMockExtensionMessage(message);
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({ expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
command: "updateOverlayHidden", command: "updateOverlayMenuHidden",
styles: { styles: {
display: "none", display: "none",
}, },
}); });
expect(listPortSpy.postMessage).toHaveBeenCalledWith({ expect(listPortSpy.postMessage).toHaveBeenCalledWith({
command: "updateOverlayHidden", command: "updateOverlayMenuHidden",
styles: { styles: {
display: "none", display: "none",
}, },
@@ -870,19 +870,22 @@ describe("OverlayBackground", () => {
}); });
it("sets the `opacity` CSS value on the overlay button and list", () => { it("sets the `opacity` CSS value on the overlay button and list", () => {
const message = { command: "updateAutofillOverlayHidden", setTransparentOverlay: true }; const message = {
command: "updateAutofillOverlayMenuHidden",
setTransparentOverlay: true,
};
sendMockExtensionMessage(message); sendMockExtensionMessage(message);
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({ expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
command: "updateOverlayHidden", command: "updateOverlayMenuHidden",
styles: { styles: {
display: "block", display: "block",
opacity: 0, opacity: 0,
}, },
}); });
expect(listPortSpy.postMessage).toHaveBeenCalledWith({ expect(listPortSpy.postMessage).toHaveBeenCalledWith({
command: "updateOverlayHidden", command: "updateOverlayMenuHidden",
styles: { styles: {
display: "block", display: "block",
opacity: 0, opacity: 0,
@@ -1033,7 +1036,7 @@ describe("OverlayBackground", () => {
describe("handlePortOnConnect", () => { describe("handlePortOnConnect", () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(overlayBackground as any, "updateOverlayPosition").mockImplementation(); jest.spyOn(overlayBackground as any, "updateOverlayMenuPosition").mockImplementation();
jest.spyOn(overlayBackground as any, "getAuthStatus").mockImplementation(); jest.spyOn(overlayBackground as any, "getAuthStatus").mockImplementation();
jest.spyOn(overlayBackground as any, "getTranslations").mockImplementation(); jest.spyOn(overlayBackground as any, "getTranslations").mockImplementation();
jest.spyOn(overlayBackground as any, "getOverlayCipherData").mockImplementation(); jest.spyOn(overlayBackground as any, "getOverlayCipherData").mockImplementation();
@@ -1063,7 +1066,7 @@ describe("OverlayBackground", () => {
expect(chrome.runtime.getURL).toHaveBeenCalledWith("overlay/list.css"); expect(chrome.runtime.getURL).toHaveBeenCalledWith("overlay/list.css");
expect(overlayBackground["getTranslations"]).toHaveBeenCalled(); expect(overlayBackground["getTranslations"]).toHaveBeenCalled();
expect(overlayBackground["getOverlayCipherData"]).toHaveBeenCalled(); expect(overlayBackground["getOverlayCipherData"]).toHaveBeenCalled();
expect(overlayBackground["updateOverlayPosition"]).toHaveBeenCalledWith( expect(overlayBackground["updateOverlayMenuPosition"]).toHaveBeenCalledWith(
{ overlayElement: AutofillOverlayElement.List }, { overlayElement: AutofillOverlayElement.List },
listPortSpy.sender, listPortSpy.sender,
); );
@@ -1083,7 +1086,7 @@ describe("OverlayBackground", () => {
expect(overlayBackground["getAuthStatus"]).toHaveBeenCalled(); expect(overlayBackground["getAuthStatus"]).toHaveBeenCalled();
expect(chrome.runtime.getURL).toHaveBeenCalledWith("overlay/button.css"); expect(chrome.runtime.getURL).toHaveBeenCalledWith("overlay/button.css");
expect(overlayBackground["getTranslations"]).toHaveBeenCalled(); expect(overlayBackground["getTranslations"]).toHaveBeenCalled();
expect(overlayBackground["updateOverlayPosition"]).toHaveBeenCalledWith( expect(overlayBackground["updateOverlayMenuPosition"]).toHaveBeenCalledWith(
{ overlayElement: AutofillOverlayElement.Button }, { overlayElement: AutofillOverlayElement.Button },
buttonPortSpy.sender, buttonPortSpy.sender,
); );

View File

@@ -53,7 +53,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
private overlayLoginCiphers: Map<string, CipherView> = new Map(); private overlayLoginCiphers: Map<string, CipherView> = new Map();
private pageDetailsForTab: PageDetailsForTab = {}; private pageDetailsForTab: PageDetailsForTab = {};
private subFrameOffsetsForTab: SubFrameOffsetsForTab = {}; private subFrameOffsetsForTab: SubFrameOffsetsForTab = {};
private updateOverlayPositionAfterSubFrameRebuildTimeout: number | NodeJS.Timeout; private updateOverlayMenuPositionTimeout: number | NodeJS.Timeout;
private userAuthStatus: AuthenticationStatus = AuthenticationStatus.LoggedOut; private userAuthStatus: AuthenticationStatus = AuthenticationStatus.LoggedOut;
private overlayButtonPort: chrome.runtime.Port; private overlayButtonPort: chrome.runtime.Port;
private overlayListPort: chrome.runtime.Port; private overlayListPort: chrome.runtime.Port;
@@ -69,26 +69,27 @@ class OverlayBackground implements OverlayBackgroundInterface {
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message), autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender), autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender),
getAutofillOverlayVisibility: () => this.getOverlayVisibility(), getAutofillOverlayVisibility: () => this.getOverlayVisibility(),
checkAutofillOverlayFocused: () => this.checkOverlayFocused(), checkAutofillOverlayMenuFocused: () => this.checkOverlayMenuFocused(),
focusAutofillOverlayList: () => this.focusOverlayList(), focusAutofillOverlayList: () => this.focusOverlayList(),
updateAutofillOverlayPosition: ({ message, sender }) => updateAutofillOverlayMenuPosition: ({ message, sender }) =>
this.updateOverlayPosition(message, sender), this.updateOverlayMenuPosition(message, sender),
updateAutofillOverlayHidden: ({ message, sender }) => this.updateOverlayHidden(message, sender), updateAutofillOverlayMenuHidden: ({ message, sender }) =>
this.updateOverlayMenuHidden(message, sender),
updateFocusedFieldData: ({ message, sender }) => this.setFocusedFieldData(message, sender), updateFocusedFieldData: ({ message, sender }) => this.setFocusedFieldData(message, sender),
collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender),
unlockCompleted: ({ message }) => this.unlockCompleted(message),
addEditCipherSubmitted: () => this.updateOverlayCiphers(),
deletedCipher: () => this.updateOverlayCiphers(),
updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message), updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message),
checkIsFieldCurrentlyFocused: () => this.checkIsFieldCurrentlyFocused(), checkIsFieldCurrentlyFocused: () => this.checkIsFieldCurrentlyFocused(),
updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message), updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message),
checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(), checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(),
checkIsInlineMenuButtonVisible: ({ sender }) => this.checkIsInlineMenuButtonVisible(sender), checkIsInlineMenuButtonVisible: ({ sender }) => this.checkIsInlineMenuButtonVisible(sender),
checkIsInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender), checkIsInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender),
checkIsInlineMenuCiphersPopulated: ({ sender }) => checkIsOverlayLoginCiphersPopulated: ({ sender }) =>
this.checkIsInlineMenuCiphersPopulated(sender), this.checkIsOverlayLoginCiphersPopulated(sender),
updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender), updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender),
rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender), rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender),
collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender),
unlockCompleted: ({ message }) => this.unlockCompleted(message),
addEditCipherSubmitted: () => this.updateOverlayCiphers(),
deletedCipher: () => this.updateOverlayCiphers(),
}; };
private readonly overlayButtonPortMessageHandlers: OverlayButtonPortMessageHandlers = { private readonly overlayButtonPortMessageHandlers: OverlayButtonPortMessageHandlers = {
overlayButtonClicked: ({ port }) => this.handleOverlayButtonClicked(port), overlayButtonClicked: ({ port }) => this.handleOverlayButtonClicked(port),
@@ -316,8 +317,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
return; return;
} }
if (this.updateOverlayPositionAfterSubFrameRebuildTimeout) { if (this.updateOverlayMenuPositionTimeout) {
clearTimeout(this.updateOverlayPositionAfterSubFrameRebuildTimeout); clearTimeout(this.updateOverlayMenuPositionTimeout);
} }
const frameTabs = Array.from(subFrameOffsetsForTab.keys()); const frameTabs = Array.from(subFrameOffsetsForTab.keys());
@@ -330,10 +331,16 @@ class OverlayBackground implements OverlayBackgroundInterface {
await this.buildSubFrameOffsets(sender.tab, frameId, sender.url); await this.buildSubFrameOffsets(sender.tab, frameId, sender.url);
} }
this.updateOverlayPositionAfterSubFrameRebuildTimeout = setTimeout(() => { this.updateOverlayMenuPositionTimeout = setTimeout(() => {
if (this.isFieldCurrentlyFocused) { if (this.isFieldCurrentlyFocused) {
void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.List }, sender); void this.updateOverlayMenuPosition(
void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.Button }, sender); { overlayElement: AutofillOverlayElement.List },
sender,
);
void this.updateOverlayMenuPosition(
{ overlayElement: AutofillOverlayElement.Button },
sender,
);
} }
}, 650); }, 650);
} }
@@ -378,7 +385,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
* Checks if the overlay is focused. Will check the overlay list * Checks if the overlay is focused. Will check the overlay list
* if it is open, otherwise it will check the overlay button. * if it is open, otherwise it will check the overlay button.
*/ */
private checkOverlayFocused() { private checkOverlayMenuFocused() {
if (this.overlayListPort) { if (this.overlayListPort) {
this.checkOverlayListFocused(); this.checkOverlayListFocused();
@@ -473,7 +480,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
* @param overlayElement - The overlay element to update, either the list or button * @param overlayElement - The overlay element to update, either the list or button
* @param sender - The sender of the extension message * @param sender - The sender of the extension message
*/ */
private async updateOverlayPosition( private async updateOverlayMenuPosition(
{ overlayElement }: { overlayElement?: string }, { overlayElement }: { overlayElement?: string },
sender: chrome.runtime.MessageSender, sender: chrome.runtime.MessageSender,
) { ) {
@@ -584,7 +591,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
* @param display - The display property of the overlay, either "block" or "none" * @param display - The display property of the overlay, either "block" or "none"
* @param sender - The sender of the extension message * @param sender - The sender of the extension message
*/ */
private updateOverlayHidden( private updateOverlayMenuHidden(
{ isOverlayHidden, setTransparentOverlay }: OverlayBackgroundExtensionMessage, { isOverlayHidden, setTransparentOverlay }: OverlayBackgroundExtensionMessage,
sender: chrome.runtime.MessageSender, sender: chrome.runtime.MessageSender,
) { ) {
@@ -596,7 +603,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
styles = { ...styles, opacity }; styles = { ...styles, opacity };
} }
const portMessage = { command: "updateOverlayHidden", styles }; const portMessage = { command: "updateOverlayMenuHidden", styles };
void BrowserApi.tabSendMessage( void BrowserApi.tabSendMessage(
sender.tab, sender.tab,
@@ -880,7 +887,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
); );
} }
private checkIsInlineMenuCiphersPopulated(sender: chrome.runtime.MessageSender) { private checkIsOverlayLoginCiphersPopulated(sender: chrome.runtime.MessageSender) {
return sender.tab.id === this.focusedFieldData.tabId && this.overlayLoginCiphers.size > 0; return sender.tab.id === this.focusedFieldData.tabId && this.overlayLoginCiphers.size > 0;
} }
@@ -976,7 +983,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
? AutofillOverlayPort.ListMessageConnector ? AutofillOverlayPort.ListMessageConnector
: AutofillOverlayPort.ButtonMessageConnector, : AutofillOverlayPort.ButtonMessageConnector,
}); });
void this.updateOverlayPosition( void this.updateOverlayMenuPosition(
{ {
overlayElement: isOverlayListPort overlayElement: isOverlayListPort
? AutofillOverlayElement.List ? AutofillOverlayElement.List

View File

@@ -19,7 +19,7 @@ type BackgroundPortMessageHandlers = {
initAutofillOverlayButton: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void; initAutofillOverlayButton: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
initAutofillOverlayList: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void; initAutofillOverlayList: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
updateIframePosition: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void; updateIframePosition: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
updateOverlayHidden: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void; updateOverlayMenuHidden: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
updateOverlayPageColorScheme: () => void; updateOverlayPageColorScheme: () => void;
}; };

View File

@@ -395,7 +395,7 @@ describe("AutofillOverlayIframeService", () => {
it("updates the visibility of the iframe", () => { it("updates the visibility of the iframe", () => {
sendPortMessage(portSpy, { sendPortMessage(portSpy, {
command: "updateOverlayHidden", command: "updateOverlayMenuHidden",
styles: { display: "none" }, styles: { display: "none" },
}); });

View File

@@ -45,7 +45,7 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
initAutofillOverlayButton: ({ message }) => this.initAutofillOverlay(message), initAutofillOverlayButton: ({ message }) => this.initAutofillOverlay(message),
initAutofillOverlayList: ({ message }) => this.initAutofillOverlay(message), initAutofillOverlayList: ({ message }) => this.initAutofillOverlay(message),
updateIframePosition: ({ message }) => this.updateIframePosition(message.styles), updateIframePosition: ({ message }) => this.updateIframePosition(message.styles),
updateOverlayHidden: ({ message }) => this.updateElementStyles(this.iframe, message.styles), updateOverlayMenuHidden: ({ message }) => this.updateElementStyles(this.iframe, message.styles),
updateOverlayPageColorScheme: () => this.updateOverlayPageColorScheme(), updateOverlayPageColorScheme: () => this.updateOverlayPageColorScheme(),
}; };

View File

@@ -305,7 +305,7 @@ describe("AutofillOverlayContentService", () => {
it("sends a message to the background to check if the overlay is focused", () => { it("sends a message to the background to check if the overlay is focused", () => {
autofillFieldElement.dispatchEvent(new Event("blur")); autofillFieldElement.dispatchEvent(new Event("blur"));
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("checkAutofillOverlayFocused"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("checkAutofillOverlayMenuFocused");
}); });
}); });
@@ -704,9 +704,12 @@ describe("AutofillOverlayContentService", () => {
autofillFieldElement.dispatchEvent(new Event("focus")); autofillFieldElement.dispatchEvent(new Event("focus"));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith(
overlayElement: AutofillOverlayElement.Button, "updateAutofillOverlayMenuPosition",
}); {
overlayElement: AutofillOverlayElement.Button,
},
);
}); });
}); });
}); });
@@ -816,10 +819,10 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["openAutofillOverlayMenu"](); autofillOverlayContentService["openAutofillOverlayMenu"]();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
}); });
@@ -830,12 +833,15 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: false }); autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: false });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).not.toHaveBeenCalledWith(
overlayElement: AutofillOverlayElement.List, "updateAutofillOverlayMenuPosition",
}); {
overlayElement: AutofillOverlayElement.List,
},
);
}); });
it("overrides the onButtonClick visibility setting to open both overlay elements", () => { it("overrides the onButtonClick visibility setting to open both overlay elements", () => {
@@ -844,10 +850,10 @@ describe("AutofillOverlayContentService", () => {
autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: true }); autofillOverlayContentService["openAutofillOverlayMenu"]({ isOpeningFullOverlay: true });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
}); });
@@ -1098,7 +1104,7 @@ describe("AutofillOverlayContentService", () => {
globalThis.dispatchEvent(new Event(EVENTS.SCROLL)); globalThis.dispatchEvent(new Event(EVENTS.SCROLL));
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayHidden", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuHidden", {
isOverlayHidden: true, isOverlayHidden: true,
setTransparentOverlay: false, setTransparentOverlay: false,
}); });
@@ -1126,7 +1132,7 @@ describe("AutofillOverlayContentService", () => {
await flushPromises(); await flushPromises();
jest.advanceTimersByTime(800); jest.advanceTimersByTime(800);
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayHidden", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuHidden", {
isOverlayHidden: false, isOverlayHidden: false,
setTransparentOverlay: true, setTransparentOverlay: true,
}); });
@@ -1157,10 +1163,10 @@ describe("AutofillOverlayContentService", () => {
jest.advanceTimersByTime(800); jest.advanceTimersByTime(800);
await flushPromises(); await flushPromises();
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayPosition", { expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
expect(clearUserInteractionEventTimeoutSpy).toHaveBeenCalled(); expect(clearUserInteractionEventTimeoutSpy).toHaveBeenCalled();

View File

@@ -290,7 +290,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
void this.sendExtensionMessage("updateIsFieldCurrentlyFocused", { void this.sendExtensionMessage("updateIsFieldCurrentlyFocused", {
isFieldCurrentlyFocused: false, isFieldCurrentlyFocused: false,
}); });
void this.sendExtensionMessage("checkAutofillOverlayFocused"); void this.sendExtensionMessage("checkAutofillOverlayMenuFocused");
}; };
/** /**
@@ -547,7 +547,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* Updates the position of the overlay button. * Updates the position of the overlay button.
*/ */
private updateOverlayButtonPosition() { private updateOverlayButtonPosition() {
void this.sendExtensionMessage("updateAutofillOverlayPosition", { void this.sendExtensionMessage("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.Button, overlayElement: AutofillOverlayElement.Button,
}); });
} }
@@ -556,7 +556,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* Updates the position of the overlay list. * Updates the position of the overlay list.
*/ */
private updateOverlayListPosition() { private updateOverlayListPosition() {
void this.sendExtensionMessage("updateAutofillOverlayPosition", { void this.sendExtensionMessage("updateAutofillOverlayMenuPosition", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
}); });
} }
@@ -568,7 +568,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* @param setTransparentOverlay - Indicates if the overlay is closing. * @param setTransparentOverlay - Indicates if the overlay is closing.
*/ */
private toggleOverlayHidden(isHidden: boolean, setTransparentOverlay: boolean = false) { private toggleOverlayHidden(isHidden: boolean, setTransparentOverlay: boolean = false) {
void this.sendExtensionMessage("updateAutofillOverlayHidden", { void this.sendExtensionMessage("updateAutofillOverlayMenuHidden", {
isOverlayHidden: isHidden, isOverlayHidden: isHidden,
setTransparentOverlay, setTransparentOverlay,
}); });
@@ -1002,7 +1002,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
} }
private async isInlineMenuCiphersPopulated() { private async isInlineMenuCiphersPopulated() {
return (await this.sendExtensionMessage("checkIsInlineMenuCiphersPopulated")) === true; return (await this.sendExtensionMessage("checkIsOverlayLoginCiphersPopulated")) === true;
} }
/** /**

View File

@@ -38,7 +38,7 @@ describe("generateRandomCustomElementName", () => {
describe("sendExtensionMessage", () => { describe("sendExtensionMessage", () => {
it("sends a message to the extention", () => { it("sends a message to the extention", () => {
const extensionMessageResponse = sendExtensionMessage("updateAutofillOverlayHidden", { const extensionMessageResponse = sendExtensionMessage("updateAutofillOverlayMenuHidden", {
display: "none", display: "none",
}); });
jest.spyOn(chrome.runtime, "sendMessage"); jest.spyOn(chrome.runtime, "sendMessage");