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 15:45:45 -05:00
parent 43ba6256dc
commit c15439512b
7 changed files with 21 additions and 21 deletions

View File

@@ -96,7 +96,7 @@ type OverlayBackgroundExtensionMessageHandlers = {
closeAutofillOverlayMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; closeAutofillOverlayMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void; autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
getAutofillOverlayVisibility: () => void; getInlineMenuVisibilitySetting: () => void;
checkAutofillOverlayMenuFocused: () => void; checkAutofillOverlayMenuFocused: () => void;
focusAutofillOverlayList: () => void; focusAutofillOverlayList: () => void;
updateAutofillOverlayMenuPosition: ({ updateAutofillOverlayMenuPosition: ({

View File

@@ -133,7 +133,7 @@ describe("OverlayBackground", () => {
); );
jest jest
.spyOn(overlayBackground as any, "getOverlayVisibility") .spyOn(overlayBackground as any, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus); .mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
themeStateService.selectedTheme$ = of(ThemeType.Light); themeStateService.selectedTheme$ = of(ThemeType.Light);
@@ -161,13 +161,13 @@ describe("OverlayBackground", () => {
describe("init", () => { describe("init", () => {
it("sets up the extension message listeners, get the overlay's visibility settings, and get the user's auth status", async () => { it("sets up the extension message listeners, get the overlay's visibility settings, and get the user's auth status", async () => {
overlayBackground["setupExtensionMessageListeners"] = jest.fn(); overlayBackground["setupExtensionMessageListeners"] = jest.fn();
overlayBackground["getOverlayVisibility"] = jest.fn(); overlayBackground["getInlineMenuVisibility"] = jest.fn();
overlayBackground["getAuthStatus"] = jest.fn(); overlayBackground["getAuthStatus"] = jest.fn();
await overlayBackground.init(); await overlayBackground.init();
expect(overlayBackground["setupExtensionMessageListeners"]).toHaveBeenCalled(); expect(overlayBackground["setupExtensionMessageListeners"]).toHaveBeenCalled();
expect(overlayBackground["getOverlayVisibility"]).toHaveBeenCalled(); expect(overlayBackground["getInlineMenuVisibility"]).toHaveBeenCalled();
expect(overlayBackground["getAuthStatus"]).toHaveBeenCalled(); expect(overlayBackground["getAuthStatus"]).toHaveBeenCalled();
}); });
}); });
@@ -638,18 +638,18 @@ describe("OverlayBackground", () => {
}); });
}); });
describe("getAutofillOverlayVisibility message handler", () => { describe("getInlineMenuVisibilitySetting message handler", () => {
beforeEach(() => { beforeEach(() => {
jest jest
.spyOn(overlayBackground as any, "getOverlayVisibility") .spyOn(overlayBackground as any, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus); .mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
}); });
it("will set the overlayVisibility property", async () => { it("will set the overlayVisibility property", async () => {
sendMockExtensionMessage({ command: "getAutofillOverlayVisibility" }); sendMockExtensionMessage({ command: "getInlineMenuVisibilitySetting" });
await flushPromises(); await flushPromises();
expect(await overlayBackground["getOverlayVisibility"]()).toBe( expect(await overlayBackground["getInlineMenuVisibility"]()).toBe(
AutofillOverlayVisibility.OnFieldFocus, AutofillOverlayVisibility.OnFieldFocus,
); );
}); });
@@ -658,7 +658,7 @@ describe("OverlayBackground", () => {
const sendMessageSpy = jest.fn(); const sendMessageSpy = jest.fn();
sendMockExtensionMessage( sendMockExtensionMessage(
{ command: "getAutofillOverlayVisibility" }, { command: "getInlineMenuVisibilitySetting" },
undefined, undefined,
sendMessageSpy, sendMessageSpy,
); );

View File

@@ -68,7 +68,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
closeAutofillOverlayMenu: ({ message, sender }) => this.closeOverlayMenu(sender, message), closeAutofillOverlayMenu: ({ message, sender }) => this.closeOverlayMenu(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),
getAutofillOverlayVisibility: () => this.getOverlayVisibility(), getInlineMenuVisibilitySetting: () => this.getInlineMenuVisibility(),
checkAutofillOverlayMenuFocused: () => this.checkOverlayMenuFocused(), checkAutofillOverlayMenuFocused: () => this.checkOverlayMenuFocused(),
focusAutofillOverlayList: () => this.focusOverlayList(), focusAutofillOverlayList: () => this.focusOverlayList(),
updateAutofillOverlayMenuPosition: ({ message, sender }) => updateAutofillOverlayMenuPosition: ({ message, sender }) =>
@@ -135,7 +135,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
this.setupExtensionMessageListeners(); this.setupExtensionMessageListeners();
const env = await firstValueFrom(this.environmentService.environment$); const env = await firstValueFrom(this.environmentService.environment$);
this.iconsServerUrl = env.getIconsUrl(); this.iconsServerUrl = env.getIconsUrl();
await this.getOverlayVisibility(); await this.getInlineMenuVisibility();
await this.getAuthStatus(); await this.getAuthStatus();
} }
@@ -641,7 +641,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
/** /**
* Gets the overlay's visibility setting from the settings service. * Gets the overlay's visibility setting from the settings service.
*/ */
private async getOverlayVisibility(): Promise<InlineMenuVisibilitySetting> { private async getInlineMenuVisibility(): Promise<InlineMenuVisibilitySetting> {
return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$); return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$);
} }

View File

@@ -230,7 +230,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldData, autofillFieldData,
); );
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("getAutofillOverlayVisibility"); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("getInlineMenuVisibilitySetting");
expect(autofillOverlayContentService["autofillOverlayVisibility"]).toEqual( expect(autofillOverlayContentService["autofillOverlayVisibility"]).toEqual(
AutofillOverlayVisibility.OnFieldFocus, AutofillOverlayVisibility.OnFieldFocus,
); );

View File

@@ -93,7 +93,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
} }
if (!this.autofillOverlayVisibility) { if (!this.autofillOverlayVisibility) {
await this.getAutofillOverlayVisibility(); await this.getInlineMenuVisibilitySetting();
} }
this.setupFormFieldElementEventListeners(formFieldElement); this.setupFormFieldElementEventListeners(formFieldElement);
@@ -722,8 +722,8 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* If the setting is not found, a default value of OnFieldFocus will be used * If the setting is not found, a default value of OnFieldFocus will be used
* @private * @private
*/ */
private async getAutofillOverlayVisibility() { private async getInlineMenuVisibilitySetting() {
const overlayVisibility = await this.sendExtensionMessage("getAutofillOverlayVisibility"); const overlayVisibility = await this.sendExtensionMessage("getInlineMenuVisibilitySetting");
this.autofillOverlayVisibility = overlayVisibility || AutofillOverlayVisibility.OnFieldFocus; this.autofillOverlayVisibility = overlayVisibility || AutofillOverlayVisibility.OnFieldFocus;
} }

View File

@@ -108,7 +108,7 @@ describe("AutofillService", () => {
.spyOn(BrowserApi, "getAllFrames") .spyOn(BrowserApi, "getAllFrames")
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]); .mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
jest jest
.spyOn(autofillService, "getOverlayVisibility") .spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus); .mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true); jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true);
}); });
@@ -186,7 +186,7 @@ describe("AutofillService", () => {
sender = { tab: tabMock, frameId: 1 }; sender = { tab: tabMock, frameId: 1 };
jest.spyOn(BrowserApi, "executeScriptInTab").mockImplementation(); jest.spyOn(BrowserApi, "executeScriptInTab").mockImplementation();
jest jest
.spyOn(autofillService, "getOverlayVisibility") .spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus); .mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true); jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true);
}); });
@@ -232,7 +232,7 @@ describe("AutofillService", () => {
it("will inject the bootstrap-autofill script if the user does not have the autofill overlay enabled", async () => { it("will inject the bootstrap-autofill script if the user does not have the autofill overlay enabled", async () => {
jest jest
.spyOn(autofillService, "getOverlayVisibility") .spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.Off); .mockResolvedValue(AutofillOverlayVisibility.Off);
await autofillService.injectAutofillScripts(sender.tab, sender.frameId); await autofillService.injectAutofillScripts(sender.tab, sender.frameId);

View File

@@ -99,7 +99,7 @@ export default class AutofillService implements AutofillServiceInterface {
frameId = 0, frameId = 0,
triggeringOnPageLoad = true, triggeringOnPageLoad = true,
): Promise<void> { ): Promise<void> {
const mainAutofillScript = (await this.getOverlayVisibility()) const mainAutofillScript = (await this.getInlineMenuVisibility())
? "bootstrap-autofill-overlay.js" ? "bootstrap-autofill-overlay.js"
: "bootstrap-autofill.js"; : "bootstrap-autofill.js";
@@ -199,7 +199,7 @@ export default class AutofillService implements AutofillServiceInterface {
/** /**
* Gets the overlay's visibility setting from the autofill settings service. * Gets the overlay's visibility setting from the autofill settings service.
*/ */
async getOverlayVisibility(): Promise<InlineMenuVisibilitySetting> { async getInlineMenuVisibility(): Promise<InlineMenuVisibilitySetting> {
return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$); return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$);
} }