mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +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:
@@ -103,7 +103,7 @@ describe("InsertAutofillContentService", () => {
|
|||||||
delay_between_operations: 20,
|
delay_between_operations: 20,
|
||||||
},
|
},
|
||||||
metadata: {},
|
metadata: {},
|
||||||
autosubmit: null,
|
autosubmit: [],
|
||||||
savedUrls: ["https://bitwarden.com"],
|
savedUrls: ["https://bitwarden.com"],
|
||||||
untrustedIframe: false,
|
untrustedIframe: false,
|
||||||
itemType: "login",
|
itemType: "login",
|
||||||
@@ -218,28 +218,21 @@ describe("InsertAutofillContentService", () => {
|
|||||||
|
|
||||||
await insertAutofillContentService.fillForm(fillScript);
|
await insertAutofillContentService.fillForm(fillScript);
|
||||||
|
|
||||||
expect(insertAutofillContentService["userCancelledInsecureUrlAutofill"]).toHaveBeenCalled();
|
|
||||||
expect(
|
|
||||||
insertAutofillContentService["userCancelledUntrustedIframeAutofill"],
|
|
||||||
).toHaveBeenCalled();
|
|
||||||
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenCalledTimes(3);
|
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenCalledTimes(3);
|
||||||
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
fillScript.script[0],
|
fillScript.script[0],
|
||||||
0,
|
0,
|
||||||
fillScript.script,
|
|
||||||
);
|
);
|
||||||
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
fillScript.script[1],
|
fillScript.script[1],
|
||||||
1,
|
1,
|
||||||
fillScript.script,
|
|
||||||
);
|
);
|
||||||
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
expect(insertAutofillContentService["runFillScriptAction"]).toHaveBeenNthCalledWith(
|
||||||
3,
|
3,
|
||||||
fillScript.script[2],
|
fillScript.script[2],
|
||||||
2,
|
2,
|
||||||
fillScript.script,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -623,14 +616,12 @@ describe("InsertAutofillContentService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("will set the `value` attribute of any passed input or textarea elements", () => {
|
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" /><textarea id="bio"></textarea>`;
|
document.body.innerHTML = `<input type="text" id="username" value="old" /><textarea id="bio">old</textarea>`;
|
||||||
const value1 = "test";
|
const value1 = "test";
|
||||||
const value2 = "test2";
|
const value2 = "test2";
|
||||||
const textInputElement = document.getElementById("username") as HTMLInputElement;
|
const textInputElement = document.getElementById("username") as HTMLInputElement;
|
||||||
textInputElement.value = value1;
|
|
||||||
const textareaElement = document.getElementById("bio") as HTMLTextAreaElement;
|
const textareaElement = document.getElementById("bio") as HTMLTextAreaElement;
|
||||||
textareaElement.value = value2;
|
|
||||||
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
|
jest.spyOn(insertAutofillContentService as any, "handleInsertValueAndTriggerSimulatedEvents");
|
||||||
|
|
||||||
insertAutofillContentService["insertValueIntoField"](textInputElement, value1);
|
insertAutofillContentService["insertValueIntoField"](textInputElement, value1);
|
||||||
@@ -647,6 +638,45 @@ describe("InsertAutofillContentService", () => {
|
|||||||
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
|
insertAutofillContentService["handleInsertValueAndTriggerSimulatedEvents"],
|
||||||
).toHaveBeenCalledWith(textareaElement, expect.any(Function));
|
).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", () => {
|
describe("handleInsertValueAndTriggerSimulatedEvents", () => {
|
||||||
|
|||||||
@@ -49,8 +49,9 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fillActionPromises = fillScript.script.map(this.runFillScriptAction);
|
for (let index = 0; index < fillScript.script.length; index++) {
|
||||||
await Promise.all(fillActionPromises);
|
await this.runFillScriptAction(fillScript.script[index], index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,10 +190,14 @@ class InsertAutofillContentService implements InsertAutofillContentServiceInterf
|
|||||||
const elementCanBeReadonly =
|
const elementCanBeReadonly =
|
||||||
elementIsInputElement(element) || elementIsTextAreaElement(element);
|
elementIsInputElement(element) || elementIsTextAreaElement(element);
|
||||||
const elementCanBeFilled = elementCanBeReadonly || elementIsSelectElement(element);
|
const elementCanBeFilled = elementCanBeReadonly || elementIsSelectElement(element);
|
||||||
|
const elementValue = (element as HTMLInputElement)?.value || element?.innerText || "";
|
||||||
|
|
||||||
|
const elementAlreadyHasTheValue = !!(elementValue?.length && elementValue === value);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!element ||
|
!element ||
|
||||||
!value ||
|
!value ||
|
||||||
|
elementAlreadyHasTheValue ||
|
||||||
(elementCanBeReadonly && element.readOnly) ||
|
(elementCanBeReadonly && element.readOnly) ||
|
||||||
(elementCanBeFilled && element.disabled)
|
(elementCanBeFilled && element.disabled)
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user