mirror of
https://github.com/bitwarden/browser
synced 2024-12-24 17:11:55 +01:00
[PM-6469] Fix inline menu UI visibility race condition bug (#8104)
This commit is contained in:
parent
0f9acf50f7
commit
73504d9bb0
@ -1214,7 +1214,10 @@ describe("AutofillOverlayContentService", () => {
|
||||
autofillOverlayContentService as any,
|
||||
"removeAutofillOverlay",
|
||||
);
|
||||
|
||||
autofillOverlayContentService["mostRecentlyFocusedField"] = undefined;
|
||||
autofillOverlayContentService["overlayButtonElement"] = document.createElement("div");
|
||||
autofillOverlayContentService["overlayListElement"] = document.createElement("div");
|
||||
|
||||
globalThis.dispatchEvent(new Event(EVENTS.SCROLL));
|
||||
jest.advanceTimersByTime(800);
|
||||
@ -1222,8 +1225,8 @@ describe("AutofillOverlayContentService", () => {
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateAutofillOverlayHidden", {
|
||||
display: "block",
|
||||
});
|
||||
expect(autofillOverlayContentService["isOverlayButtonVisible"]).toEqual(true);
|
||||
expect(autofillOverlayContentService["isOverlayListVisible"]).toEqual(true);
|
||||
expect(autofillOverlayContentService["isOverlayButtonVisible"]).toEqual(false);
|
||||
expect(autofillOverlayContentService["isOverlayListVisible"]).toEqual(false);
|
||||
expect(removeAutofillOverlaySpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@ -1280,6 +1283,32 @@ describe("AutofillOverlayContentService", () => {
|
||||
|
||||
expect(removeAutofillOverlaySpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("defaults overlay elements to a visibility of `false` if the element is not rendered on the page", async () => {
|
||||
jest.useFakeTimers();
|
||||
jest
|
||||
.spyOn(autofillOverlayContentService as any, "updateMostRecentlyFocusedField")
|
||||
.mockImplementation(() => {
|
||||
autofillOverlayContentService["focusedFieldData"] = {
|
||||
focusedFieldRects: {
|
||||
top: 100,
|
||||
},
|
||||
focusedFieldStyles: {},
|
||||
};
|
||||
});
|
||||
jest
|
||||
.spyOn(autofillOverlayContentService as any, "updateOverlayElementsPosition")
|
||||
.mockImplementation();
|
||||
autofillOverlayContentService["overlayButtonElement"] = document.createElement("div");
|
||||
autofillOverlayContentService["overlayListElement"] = undefined;
|
||||
|
||||
globalThis.dispatchEvent(new Event(EVENTS.SCROLL));
|
||||
jest.advanceTimersByTime(800);
|
||||
await flushPromises();
|
||||
|
||||
expect(autofillOverlayContentService["isOverlayButtonVisible"]).toEqual(true);
|
||||
expect(autofillOverlayContentService["isOverlayListVisible"]).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("handleOverlayElementMutationObserverUpdate", () => {
|
||||
|
@ -646,12 +646,10 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
||||
*/
|
||||
private toggleOverlayHidden(isHidden: boolean) {
|
||||
const displayValue = isHidden ? "none" : "block";
|
||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.sendExtensionMessage("updateAutofillOverlayHidden", { display: displayValue });
|
||||
void this.sendExtensionMessage("updateAutofillOverlayHidden", { display: displayValue });
|
||||
|
||||
this.isOverlayButtonVisible = !isHidden;
|
||||
this.isOverlayListVisible = !isHidden;
|
||||
this.isOverlayButtonVisible = !!this.overlayButtonElement && !isHidden;
|
||||
this.isOverlayListVisible = !!this.overlayListElement && !isHidden;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user