Bug 623870 - Update the message in the invalid form popup when the error message changes. r=gavin a=jst
authorMounir Lamouri <mounir.lamouri@gmail.com>
Fri, 04 Feb 2011 00:07:33 +0100
changeset 61912 2c29556f324b8fea661b079378822bfe30668aec
parent 61911 2efc7cc537d753ef8c8478276cd1ca9e1a766d32
child 61913 89be93b83dcefe8a522751c12672ed035014d141
push idunknown
push userunknown
push dateunknown
reviewersgavin, jst
bugs623870
milestone2.0b12pre
Bug 623870 - Update the message in the invalid form popup when the error message changes. r=gavin a=jst
browser/base/content/browser.js
browser/base/content/test/browser_bug561636.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -855,16 +855,24 @@ const gFormSubmitObserver = {
     // we want to remove the popup.
     // We could check for clicks but a click is already removing the popup.
     function blurHandler() {
       gFormSubmitObserver.panel.hidePopup();
     };
     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);
     element.addEventListener("blur", blurHandler, false);
 
     // One event to bring them all and in the darkness bind them.
     this.panel.addEventListener("popuphiding", function(aEvent) {
       aEvent.target.removeEventListener("popuphiding", arguments.callee, false);
--- a/browser/base/content/test/browser_bug561636.js
+++ b/browser/base/content/test/browser_bug561636.js
@@ -391,20 +391,68 @@ function test9()
 
     checkPopupShow();
 
     is(gInvalidFormPopup.firstChild.textContent, "foo",
        "The panel should show the author defined error message");
 
     // 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,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input type='email' required id='i'><input id='s' type='submit'></form>";
+  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) {
+    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
+
+    gBrowser.contentDocument.getElementById('s').click();
+  }, true);
+
+  gBrowser.selectedTab = tab;
+  gBrowser.selectedTab.linkedBrowser.loadURI(uri);
+}