From 0bcd573d784c41ed7dc4d830772a805cc0302e3f Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Fri, 4 Feb 2011 00:07:33 +0100 Subject: [PATCH] Bug 623870 - Update the message in the invalid form popup when the error message changes. r=gavin a=jst --- browser/base/content/browser.js | 8 +++ .../base/content/test/browser_bug561636.js | 50 ++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index cd0b3fbf301..6015298d789 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -860,6 +860,14 @@ const gFormSubmitObserver = { function inputHandler(e) { if (e.originalTarget.validity.valid) { gFormSubmitObserver.panel.hidePopup(); + } else { + // If the element is now invalid for a new reason, we should update the + // error message. + if (gFormSubmitObserver.panel.firstChild.textContent != + e.originalTarget.validationMessage) { + gFormSubmitObserver.panel.firstChild.textContent = + e.originalTarget.validationMessage; + } } }; element.addEventListener("input", inputHandler, false); diff --git a/browser/base/content/test/browser_bug561636.js b/browser/base/content/test/browser_bug561636.js index c7f8fffaa84..98b1a1c51ef 100644 --- a/browser/base/content/test/browser_bug561636.js +++ b/browser/base/content/test/browser_bug561636.js @@ -396,7 +396,55 @@ function test9() // Clean-up and next test. gBrowser.removeTab(gBrowser.selectedTab, {animate: false}); - executeSoon(finish); + executeSoon(test10); + }, false); + + tab.linkedBrowser.addEventListener("load", function(aEvent) { + tab.linkedBrowser.removeEventListener("load", arguments.callee, true); + + gBrowser.contentDocument.getElementById('s').click(); + }, true); + + gBrowser.selectedTab = tab; + gBrowser.selectedTab.linkedBrowser.loadURI(uri); +} + +/** + * In this test, we check that the message is correctly updated when it changes. + */ +function test10() +{ + let uri = "data:text/html,
"; + let tab = gBrowser.addTab(); + + gInvalidFormPopup.addEventListener("popupshown", function() { + gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false); + + let doc = gBrowser.contentDocument; + let input = doc.getElementById('i'); + is(doc.activeElement, input, "First invalid element should be focused"); + + checkPopupShow(); + + is(gInvalidFormPopup.firstChild.textContent, input.validationMessage, + "The panel should show the current validation message"); + + input.addEventListener('input', function() { + input.removeEventListener('input', arguments.callee, false); + + executeSoon(function() { + // Now, the element suffers from another error, the message should have + // been updated. + is(gInvalidFormPopup.firstChild.textContent, input.validationMessage, + "The panel should show the current validation message"); + + // Clean-up and next test. + gBrowser.removeTab(gBrowser.selectedTab, {animate: false}); + executeSoon(finish); + }); + }, false); + + EventUtils.synthesizeKey('f', {}); }, false); tab.linkedBrowser.addEventListener("load", function(aEvent) {