Bug 1973149 - fix form validation message not updating if the form validation popup is already open, a=diannaS

Original Revision: https://phabricator.services.mozilla.com/D254824

Differential Revision: https://phabricator.services.mozilla.com/D258550
This commit is contained in:
Gijs Kruitbosch
2025-07-24 17:51:18 +00:00
committed by dsmith@mozilla.com
parent 86d56b6382
commit 5adc9375da
4 changed files with 88 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ skip-if = ["true"] # bug 1057615
["browser_validation_invisible.js"]
["browser_validation_message_update.js"]
["browser_validation_navigation.js"]
["browser_validation_other_popups.js"]

View File

@@ -0,0 +1,76 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var gInvalidFormPopup =
gBrowser.selectedBrowser.browsingContext.currentWindowGlobal
.getActor("FormValidation")
._getAndMaybeCreatePanel(document);
function getValidationMessage() {
return gInvalidFormPopup.textContent ?? "";
}
/**
* Test that the form validation popup updates its message when the
* validation message changes while the popup is shown.
*/
add_task(async function test_validation_popup_message_update() {
ok(
gInvalidFormPopup,
"The browser should have a popup to show when a form is invalid"
);
await BrowserTestUtils.withNewTab(
"https://example.com/nothere",
async function checkTab(browser) {
// Inject a form with an input and set an initial invalid state
let popupShown = BrowserTestUtils.waitForPopupEvent(
gInvalidFormPopup,
"shown"
);
await SpecialPowers.spawn(browser, [], () => {
let doc = content.document;
let form = doc.createElement("form");
let input = doc.createElement("input");
input.required = true;
form.append(input);
doc.body.append(form);
// Set initial custom validity
input.setCustomValidity("First error message");
content.eval(`document.querySelector('input').reportValidity();`);
});
await popupShown;
Assert.stringContains(
getValidationMessage(),
"First error message",
"Popup should show the first error message"
);
// Change the message and trigger validation again
let popupUpdated = BrowserTestUtils.waitForMutationCondition(
gInvalidFormPopup,
{ subtree: true, childList: true },
() => getValidationMessage().includes("Second error message")
);
await SpecialPowers.spawn(browser, [], () => {
let input = content.document.querySelector("input");
input.setCustomValidity("Second error message");
content.eval(`document.querySelector('input').reportValidity();`);
});
info("Waiting for popup to update with new message");
await popupUpdated;
Assert.stringContains(
getValidationMessage(),
"Second error message",
"Popup should update to show the new error message"
);
let popupHidden = BrowserTestUtils.waitForPopupEvent(
gInvalidFormPopup,
"hidden"
);
gInvalidFormPopup.hidePopup();
await popupHidden;
}
);
});

View File

@@ -1,5 +1,5 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";