1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-06 23:51:28 +01:00

[PM-5189] Adding a test to the overlay iframe service

This commit is contained in:
Cesar Gonzalez 2024-04-16 11:45:09 -05:00
parent ab80443073
commit 4c986425b3
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
2 changed files with 27 additions and 3 deletions

View File

@ -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;

View File

@ -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
*/