Skip to content

Commit d91fdad

Browse files
authored
[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
1 parent bb07365 commit d91fdad

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("InsertAutofillContentService", () => {
103103
delay_between_operations: 20,
104104
},
105105
metadata: {},
106-
autosubmit: null,
106+
autosubmit: [],
107107
savedUrls: ["https://bitwarden.com"],
108108
untrustedIframe: false,
109109
itemType: "login",
@@ -218,28 +218,21 @@ describe("InsertAutofillContentService", () => {
218218

219219
await insertAutofillContentService.fillForm(fillScript);
220220

221-
expect(insertAutofillContentService["userCancelledInsecureUrlAutofill"]).toHaveBeenCalled();
222-
expect(
223-
insertAutofillContentService["userCancelledUntrustedIframeAutofill"],
224-
).toHaveBeenCalled();
225221
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenCalledTimes(3);
226222
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
227223
1,
228224
fillScript.script[0],
229225
0,
230-
fillScript.script,
231226
);
232227
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
233228
2,
234229
fillScript.script[1],
235230
1,
236-
fillScript.script,
237231
);
238232
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
239233
3,
240234
fillScript.script[2],
241235
2,
242-
fillScript.script,
243236
);
244237
});
245238
});
@@ -623,7 +616,30 @@ describe("InsertAutofillContentService", () => {
623616
});
624617
});
625618

626-
it("will set the `value` attribute of any passed input or textarea elements", () => {
619+
it("will set the `value` attribute of any passed input or textarea elements if the value differs", () => {
620+
document.body.innerHTML = `<input type="text" id="username" value="old" /><textarea id="bio">old</textarea>`;
621+
const value1 = "test";
622+
const value2 = "test2";
623+
const textInputElement = document.getElementById("username") as HTMLInputElement;
624+
const textareaElement = document.getElementById("bio") as HTMLTextAreaElement;
625+
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
626+
627+
insertAutofillContentService["insertValueIntoField"](textInputElement, value1);
628+
629+
expect(textInputElement.value).toBe(value1);
630+
expect(
631+
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
632+
).toHaveBeenCalledWith(textInputElement, expect.any(Function));
633+
634+
insertAutofillContentService["insertValueIntoField"](textareaElement, value2);
635+
636+
expect(textareaElement.value).toBe(value2);
637+
expect(
638+
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
639+
).toHaveBeenCalledWith(textareaElement, expect.any(Function));
640+
});
641+
642+
it("will NOT set the `value` attribute of any passed input or textarea elements if they already have values matching the passed value", () => {
627643
document.body.innerHTML = `<input type="text" id="username" /><textarea id="bio"></textarea>`;
628644
const value1 = "test";
629645
const value2 = "test2";
@@ -638,14 +654,28 @@ describe("InsertAutofillContentService", () => {
638654
expect(textInputElement.value).toBe(value1);
639655
expect(
640656
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
641-
).toHaveBeenCalledWith(textInputElement, expect.any(Function));
657+
).not.toHaveBeenCalled();
642658

643659
insertAutofillContentService["insertValueIntoField"](textareaElement, value2);
644660

645661
expect(textareaElement.value).toBe(value2);
646662
expect(
647663
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
648-
).toHaveBeenCalledWith(textareaElement, expect.any(Function));
664+
).not.toHaveBeenCalled();
665+
});
666+
667+
it("skips filling when the field already has the target value", () => {
668+
const value = "test";
669+
document.body.innerHTML = `<input type="text" id="username" value="${value}"/>`;
670+
const element = document.getElementById("username") as FillableFormFieldElement;
671+
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
672+
673+
insertAutofillContentService["insertValueIntoField"](element, value);
674+
675+
expect(
676+
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
677+
).not.toHaveBeenCalled();
678+
expect(element.value).toBe(value);
649679
});
650680
});
651681

apps/browser/src/autofill/services/insert-autofill-content.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
4949
return;
5050
}
5151

52-
const fillActionPromises = fillScript.script.map(this.runFillScriptAction);
53-
await Promise.all(fillActionPromises);
52+
for (let index = 0; index < fillScript.script.length; index++) {
53+
await this.runFillScriptAction(fillScript.script[index], index);
54+
}
5455
}
5556

5657
/**
@@ -189,10 +190,14 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
189190
const elementCanBeReadonly =
190191
elementIsInputElement(element) || elementIsTextAreaElement(element);
191192
const elementCanBeFilled = elementCanBeReadonly || elementIsSelectElement(element);
193+
const elementValue = (element as HTMLInputElement)?.value || element?.innerText || "";
194+
195+
const elementAlreadyHasTheValue = !!(elementValue?.length && elementValue === value);
192196

193197
if (
194198
!element ||
195199
!value ||
200+
elementAlreadyHasTheValue ||
196201
(elementCanBeReadonly && element.readOnly) ||
197202
(elementCanBeFilled && element.disabled)
198203
) {

0 commit comments

Comments
 (0)