Bug 1887007 - P4. Fix layout reftest and autocomplete composition test failures r=credential-management-reviewers,emilio,sgalich

This patch fixes:
1. Replace `markAsAutofillField` with `markAsAutoCompletableField` for
   layout reftest since the API name is changed
2. In AutoCompleteChild, ensuring `result` is an array because the parent
   might return `false` when there is no autocomplete popup.
3. Remove `attachFormFillControllerTo` and `detachFormFillControllerFrom` because
   setting the popup element to FormFillController is no longer required.

Differential Revision: https://phabricator.services.mozilla.com/D206994
This commit is contained in:
Dimi 2024-04-15 15:48:48 +00:00
parent f1d5451cec
commit 7b9c6effa0
18 changed files with 54 additions and 79 deletions

View file

@ -2,8 +2,8 @@
<input type=text style="background-color: red; background-image: linear-gradient(red, blue);">
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutofillField() having being processed...
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutoCompletableField() having being processed...
input.previewValue = "Autofill";
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "-moz-autofill-preview");
</script>

View file

@ -2,7 +2,7 @@
<input type=text>
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect();
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "autofill");
</script>

View file

@ -2,8 +2,8 @@
<input type=text value="JOHN DOE">
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutofillField() having being processed...
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutoCompletableField() having being processed...
input.previewValue = "Autofill";
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "-moz-autofill-preview");
</script>

View file

@ -2,7 +2,7 @@
<input type=text>
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect();
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "-moz-autofill-preview");
</script>

View file

@ -5,8 +5,8 @@
<input value="Autofill">
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutofillField() having being processed...
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutoCompletableField() having being processed...
input.previewValue = "Autofill";
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "-moz-autofill-preview");
</script>

View file

@ -2,8 +2,8 @@
<input type=text>
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutofillField() having being processed...
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutoCompletableField() having being processed...
input.previewValue = "Autofill";
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "-moz-autofill-preview");
</script>

View file

@ -2,8 +2,8 @@
<input type=text>
<script>
let input = SpecialPowers.wrap(document.querySelector("input"));
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutofillField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutofillField() having being processed...
SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].getService(SpecialPowers.Ci.nsIFormFillController).markAsAutoCompletableField(input);
input.getBoundingClientRect(); // previewValue setter depends on the reframe posted by markAsAutoCompletableField() having being processed...
input.previewValue = "Autofill";
SpecialPowers.wrap(window).windowUtils.addManuallyManagedState(input, "autofill");
</script>

View file

@ -1137,15 +1137,6 @@ export class SpecialPowersChild extends JSWindowActorChild {
Ci.nsIFormFillController
);
}
attachFormFillControllerTo(window) {
this.getFormFillController().attachPopupElementToDocument(
window.document,
this._getAutoCompletePopup(window)
);
}
detachFormFillControllerFrom(window) {
this.getFormFillController().detachFromDocument(window.document);
}
isBackButtonEnabled(window) {
return !this._getTopChromeWindow(window)
.document.getElementById("Browser:Back")

View file

@ -295,7 +295,10 @@ export class AutoCompleteChild extends JSWindowActorChild {
data,
});
this.#ongoingSearches.add(promise);
result = await promise;
result = await promise.catch(e => {
this.#ongoingSearches.delete(promise);
});
result ||= [];
// If the search is stopped, don't report back.
if (!this.#ongoingSearches.delete(promise)) {

View file

@ -365,9 +365,16 @@ export const ProfileAutocomplete = {
.lastProfileAutoCompleteResult;
},
set lastProfileAutoCompleteFocusedInput(input) {
if (lazy.FormAutofillContent.activeAutofillChild) {
lazy.FormAutofillContent.activeAutofillChild.lastProfileAutoCompleteFocusedInput =
input;
}
},
get lastProfileAutoCompleteFocusedInput() {
return lazy.FormAutofillContent.activeAutofillChild
.lastProfileAutoCompleteFocusedInput;
?.lastProfileAutoCompleteFocusedInput;
},
async _fillFromAutocompleteRow(focusedInput) {

View file

@ -829,15 +829,19 @@ export class LoginManagerParent extends JSWindowActorParent {
}))
);
}
autocompleteItems.push(
...(await lazy.WebAuthnFeature.autocompleteItemsAsync(
this._overrideBrowsingContextId ??
this.getRootBrowser().browsingContext.id,
formOrigin,
scenarioName,
isWebAuthn
))
);
// This check is only used to init webauthn in tests, which causes
// intermittent like Bug 1890419.
if (LoginManagerParent._webAuthnAutoComplete) {
autocompleteItems.push(
...(await lazy.WebAuthnFeature.autocompleteItemsAsync(
this._overrideBrowsingContextId ??
this.getRootBrowser().browsingContext.id,
formOrigin,
scenarioName,
isWebAuthn
))
);
}
return {
generatedPassword,
@ -1555,3 +1559,10 @@ XPCOMUtils.defineLazyPreferenceGetter(
"signon.masterPasswordReprompt.timeout_ms",
900000
); // 15 Minutes
XPCOMUtils.defineLazyPreferenceGetter(
LoginManagerParent,
"_webAuthnAutoComplete",
"signon.webauthn.autocomplete",
true
);

View file

@ -22,6 +22,8 @@ const iframe = document.getElementsByTagName("iframe")[0];
let iframeDoc, hostname;
add_setup(async () => {
SpecialPowers.pushPrefEnv({"set": [["signon.webauthn.autocomplete", false]]});
const origin = window.location.origin;
await setStoredLoginsAsync(
[origin, origin, null, "name", "pass"],

View file

@ -47,7 +47,7 @@ using mozilla::LogLevel;
static mozilla::LazyLogModule sLogger("satchel");
NS_IMPL_CYCLE_COLLECTION(nsFormFillController, mController, mFocusedPopup,
mPopups, mLastListener)
mLastListener)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormFillController)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFormFillController)
@ -208,34 +208,6 @@ void nsFormFillController::MaybeRemoveMutationObserver(nsINode* aNode) {
////////////////////////////////////////////////////////////////////////
//// nsIFormFillController
NS_IMETHODIMP
nsFormFillController::AttachPopupElementToDocument(Document* aDocument,
dom::Element* aPopupEl) {
if (!xpc::IsInAutomation()) {
return NS_ERROR_NOT_AVAILABLE;
}
MOZ_LOG(sLogger, LogLevel::Debug,
("AttachPopupElementToDocument for document %p with popup %p",
aDocument, aPopupEl));
NS_ENSURE_TRUE(aDocument && aPopupEl, NS_ERROR_ILLEGAL_VALUE);
nsCOMPtr<nsIAutoCompletePopup> popup = aPopupEl->AsAutoCompletePopup();
NS_ENSURE_STATE(popup);
mPopups.InsertOrUpdate(aDocument, popup);
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::DetachFromDocument(Document* aDocument) {
if (!xpc::IsInAutomation()) {
return NS_ERROR_NOT_AVAILABLE;
}
mPopups.Remove(aDocument);
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::MarkAsAutoCompletableField(HTMLInputElement* aInput) {
/*
@ -1099,12 +1071,10 @@ void nsFormFillController::StartControllingInput(HTMLInputElement* aInput) {
return;
}
nsCOMPtr<nsIAutoCompletePopup> popup = mPopups.Get(aInput->OwnerDoc());
nsCOMPtr<nsIAutoCompletePopup> popup =
do_QueryActor("AutoComplete", aInput->OwnerDoc());
if (!popup) {
popup = do_QueryActor("AutoComplete", aInput->OwnerDoc());
if (!popup) {
return;
}
return;
}
mFocusedPopup = popup;

View file

@ -107,11 +107,6 @@ class nsFormFillController final : public nsIFormFillController,
nsINode* mListNode;
nsCOMPtr<nsIAutoCompletePopup> mFocusedPopup;
// Only used by tests.
nsInterfaceHashtable<nsRefPtrHashKey<mozilla::dom::Document>,
nsIAutoCompletePopup>
mPopups;
// The observer passed to StartSearch. It will be notified when the search
// is complete or the data from a datalist changes.
nsCOMPtr<nsIAutoCompleteObserver> mLastListener;

View file

@ -35,10 +35,6 @@ interface nsIFormFillController : nsISupports
*/
readonly attribute boolean passwordPopupAutomaticallyOpened;
// Only used by tests.
void attachPopupElementToDocument(in Document document, in Element popup);
void detachFromDocument(in Document document);
/*
* Mark the specified <input> element as being managed by autocomplete entry provider.
* Autocomplete requests will be handed off to the AutoCompleteChild.

View file

@ -84,6 +84,10 @@ nsDoTestsForEditorWithAutoComplete.prototype = {
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH
);
});
if (test.popup) {
await waitForCondition(() => this._controller.input.popupOpen);
}
this._target.removeEventListener("beforeinput", onBeforeInput);
this._target.removeEventListener("input", onInput);
this._checkResult(test, beforeInputEvents, inputEvents);

View file

@ -27,7 +27,6 @@ function runTests() {
.QueryInterface(Ci.nsIAutoCompleteInput);
var originalFormFillTimeout = formFillController.timeout;
SpecialPowers.attachFormFillControllerTo(window);
var target = document.getElementById("input");
// Register a word to the form history.
@ -53,7 +52,6 @@ function runTests() {
function() { return target.value; },
function() {
formFillController.timeout = originalFormFillTimeout;
SpecialPowers.detachFormFillControllerFrom(window);
SimpleTest.finish();
});
});

View file

@ -51,7 +51,6 @@ async function runTests() {
.QueryInterface(Ci.nsIAutoCompleteInput);
var originalFormFillTimeout = formFillController.timeout;
SpecialPowers.attachFormFillControllerTo(window);
var target = document.getElementById("input");
// Register a word to the form history.
@ -71,7 +70,6 @@ async function runTests() {
await tests2.run();
formFillController.timeout = originalFormFillTimeout;
SpecialPowers.detachFormFillControllerFrom(window);
SimpleTest.finish();
}