1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +00:00

[PM-24650] Resolve sign in button disappearing from ADP login form (#16901)

* ensure autofillInsertActions execution order is preserved

* don't fill a field if it already has the value that is going to be filled

* update tests
This commit is contained in:
Jonathan Prusik
2025-10-23 11:54:20 -04:00
committed by GitHub
parent bb07365ea5
commit d91fdad011
2 changed files with 49 additions and 14 deletions

View File

@@ -103,7 +103,7 @@ describe("InsertAutofillContentService", () => {
delay_between_operations: 20,
},
metadata: {},
autosubmit: null,
autosubmit: [],
savedUrls: ["https://bitwarden.com"],
untrustedIframe: false,
itemType: "login",
@@ -218,28 +218,21 @@ describe("InsertAutofillContentService", () => {
await insertAutofillContentService.fillForm(fillScript);
expect(insertAutofillContentService["userCancelledInsecureUrlAutofill"]).toHaveBeenCalled();
expect(
insertAutofillContentService["userCancelledUntrustedIframeAutofill"],
).toHaveBeenCalled();
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenCalledTimes(3);
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
1,
fillScript.script[0],
0,
fillScript.script,
);
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
2,
fillScript.script[1],
1,
fillScript.script,
);
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
3,
fillScript.script[2],
2,
fillScript.script,
);
});
});
@@ -623,14 +616,12 @@ describe("InsertAutofillContentService", () => {
});
});
it("will set the `value` attribute of any passed input or textarea elements", () => {
document.body.innerHTML = `<input type="text" id="username" /><textarea id="bio"></textarea>`;
it("will set the `value` attribute of any passed input or textarea elements if the value differs", () => {
document.body.innerHTML = `<input type="text" id="username" value="old" /><textarea id="bio">old</textarea>`;
const value1 = "test";
const value2 = "test2";
const textInputElement = document.getElementById("username") as HTMLInputElement;
textInputElement.value = value1;
const textareaElement = document.getElementById("bio") as HTMLTextAreaElement;
textareaElement.value = value2;
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
insertAutofillContentService["insertValueIntoField"](textInputElement, value1);
@@ -647,6 +638,45 @@ describe("InsertAutofillContentService", () => {
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
).toHaveBeenCalledWith(textareaElement, expect.any(Function));
});
it("will NOT set the `value` attribute of any passed input or textarea elements if they already have values matching the passed value", () => {
document.body.innerHTML = `<input type="text" id="username" /><textarea id="bio"></textarea>`;
const value1 = "test";
const value2 = "test2";
const textInputElement = document.getElementById("username") as HTMLInputElement;
textInputElement.value = value1;
const textareaElement = document.getElementById("bio") as HTMLTextAreaElement;
textareaElement.value = value2;
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
insertAutofillContentService["insertValueIntoField"](textInputElement, value1);
expect(textInputElement.value).toBe(value1);
expect(
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
).not.toHaveBeenCalled();
insertAutofillContentService["insertValueIntoField"](textareaElement, value2);
expect(textareaElement.value).toBe(value2);
expect(
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
).not.toHaveBeenCalled();
});
it("skips filling when the field already has the target value", () => {
const value = "test";
document.body.innerHTML = `<input type="text" id="username" value="${value}"/>`;
const element = document.getElementById("username") as FillableFormFieldElement;
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
insertAutofillContentService["insertValueIntoField"](element, value);
expect(
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
).not.toHaveBeenCalled();
expect(element.value).toBe(value);
});
});
describe("handleInsertValueAndTriggerSimulatedEvents", () => {

View File

@@ -49,8 +49,9 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
return;
}
const fillActionPromises = fillScript.script.map(this.runFillScriptAction);
await Promise.all(fillActionPromises);
for (let index = 0; index < fillScript.script.length; index++) {
await this.runFillScriptAction(fillScript.script[index], index);
}
}
/**
@@ -189,10 +190,14 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
const elementCanBeReadonly =
elementIsInputElement(element) || elementIsTextAreaElement(element);
const elementCanBeFilled = elementCanBeReadonly || elementIsSelectElement(element);
const elementValue = (element as HTMLInputElement)?.value || element?.innerText || "";
const elementAlreadyHasTheValue = !!(elementValue?.length && elementValue === value);
if (
!element ||
!value ||
elementAlreadyHasTheValue ||
(elementCanBeReadonly && element.readOnly) ||
(elementCanBeFilled && element.disabled)
) {