From 4c986425b30968c0d7088379866170ef404236bd Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 16 Apr 2024 11:45:09 -0500 Subject: [PATCH] [PM-5189] Adding a test to the overlay iframe service --- .../autofill-overlay-iframe.service.spec.ts | 17 +++++++++++++++++ .../autofill-overlay-iframe.service.ts | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.spec.ts b/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.spec.ts index a1eeb36da23..05bace2da3e 100644 --- a/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.spec.ts +++ b/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.spec.ts @@ -202,6 +202,23 @@ describe("AutofillOverlayIframeService", () => { ).not.toHaveBeenCalled(); }); + describe("initializing the overlay button", () => { + it("sets the port key and posts the message to the overlay page iframe", () => { + const portKey = "portKey"; + const message = { + command: "initAutofillOverlayButton", + portKey, + }; + + sendPortMessage(portSpy, message); + + expect(autofillOverlayIframeService["portKey"]).toBe(portKey); + expect( + autofillOverlayIframeService["iframe"].contentWindow.postMessage, + ).toHaveBeenCalledWith(message, "*"); + }); + }); + describe("initializing the overlay list", () => { let updateElementStylesSpy: jest.SpyInstance; diff --git a/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.ts b/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.ts index ee1b9867d0d..fdeb7844ef1 100644 --- a/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.ts +++ b/apps/browser/src/autofill/overlay/iframe-content/autofill-overlay-iframe.service.ts @@ -93,7 +93,7 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf */ private createAriaAlertElement(ariaAlertText: string) { this.ariaAlertElement = globalThis.document.createElement("div"); - this.ariaAlertElement.setAttribute("role", "status"); + this.ariaAlertElement.setAttribute("role", "alert"); this.ariaAlertElement.setAttribute("aria-live", "polite"); this.ariaAlertElement.setAttribute("aria-atomic", "true"); this.updateElementStyles(this.ariaAlertElement, { @@ -182,6 +182,13 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf this.postMessageToIFrame(message); }; + /** + * Handles the initialization of the autofill overlay. This includes setting + * the port key and sending a message to the iframe to initialize the overlay. + * + * @param message + * @private + */ private initAutofillOverlay(message: AutofillOverlayIframeExtensionMessage) { this.portKey = message.portKey; if (message.command === "initAutofillOverlayList") { @@ -193,8 +200,8 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf } /** - * Handles messages sent from the iframe to the extension background script. - * Will adjust the border element to fit the user's set theme. + * Handles initialization of the autofill overlay list. This includes setting + * the theme and sending a message to the iframe to initialize the overlay. * * @param message - The message sent from the iframe */