Bug 320462 - Send an input event when a value is selected from the autocomple or list dropdown. r=smaug a=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sat, 22 Jan 2011 00:06:27 +0100
changeset 61119 3f36d14effd1dc1baf2b4c8f731793424db2de35
parent 61118 ac1ddab6de5909de9a7046103cb7bd764100dc04
child 61120 d341b2ece4e43d655c9a57f80cda919d85321996
push idunknown
push userunknown
push dateunknown
reviewerssmaug, sicking
bugs320462
milestone2.0b10pre
Bug 320462 - Send an input event when a value is selected from the autocomple or list dropdown. r=smaug a=sicking
content/html/content/src/nsHTMLInputElement.cpp
toolkit/components/satchel/test/test_form_autocomplete.html
toolkit/components/satchel/test/test_form_autocomplete_with_list.html
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -1195,17 +1195,21 @@ nsHTMLInputElement::SetUserInput(const n
 
   if (mType == NS_FORM_INPUT_FILE)
   {
     const PRUnichar* name = PromiseFlatString(aValue).get();
     return MozSetFileNameArray(&name, 1);
   } else {
     SetValueInternal(aValue, PR_TRUE, PR_TRUE);
   }
-  return NS_OK;
+
+  return nsContentUtils::DispatchTrustedEvent(GetOwnerDoc(),
+                                              static_cast<nsIDOMHTMLInputElement*>(this),
+                                              NS_LITERAL_STRING("input"), PR_TRUE,
+                                              PR_TRUE);
 }
 
 NS_IMETHODIMP_(nsIEditor*)
 nsHTMLInputElement::GetTextEditor()
 {
   nsTextEditorState *state = GetEditorState();
   if (state) {
     return state->GetEditor();
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -677,32 +677,49 @@ function runTest(testNum) {
     case 401:
     case 402:
     case 403:
         checkMenuEntries(["value"]);
         doKey("down");
         doKey("return");
         checkForm("value");
 
-        if (testNum == 403) {
-          SimpleTest.finish();
-          return;
-        }
-
         if (testNum == 400) {
           input = $_(9, "field7");
         } else if (testNum == 401) {
           input = $_(10, "field8");
         } else if (testNum == 402) {
           input = $_(11, "field9");
+        } else if (testNum == 403) {
+          // Go to test 500.
+          fh.addEntry("field1", "value1");
+          input = $_(1, "field1");
+          testNum = 499;
         }
+
         restoreForm();
         doKey("down");
         break;
 
+    // Check that the input event is fired.
+    case 500:
+      input.addEventListener("input", function(event) {
+        input.removeEventListener("input", arguments.callee, false);
+        ok(true, "oninput should have been received");
+        ok(event.bubbles, "input event should bubble");
+        ok(event.cancelable, "input event should be cancelable");
+        SimpleTest.finish();
+      }, false);
+
+      doKey("down");
+      checkForm("");
+      doKey("return");
+      checkForm("value1");
+      return;
+
     default:
         ok(false, "Unexpected invocation of test #" + testNum);
         SimpleTest.finish();
         return;
   }
 
   setTimeout(runTest, 50, testNum + 1); // XXX 40ms was too slow, why?
 }
--- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
@@ -367,20 +367,38 @@ function runTest(testNum) {
       synthesizeKey("f", {});
       setTimeout(function() {
         doKey("down");
         doKey("return");
         checkForm("Google");
         input.removeAttribute('mozNoFilter');
         restoreForm();
         doKey("down");
-        SimpleTest.finish();
+        testNum = 399;
+        setTimeout(runTest, 50, testNum + 1); // XXX 40ms was too slow, why?
       }, 500);
       return;
       break;
+
+    case 400:
+      // Check that the input event is fired.
+      input.addEventListener("input", function(event) {
+        input.removeEventListener("input", arguments.callee, false);
+        ok(true, "oninput should have been received");
+        ok(event.bubbles, "input event should bubble");
+        ok(event.cancelable, "input event should be cancelable");
+        SimpleTest.finish();
+      }, false);
+
+      doKey("down");
+      checkForm("");
+      doKey("return");
+      checkForm("Google");
+      return;
+
     default:
         ok(false, "Unexpected invocation of test #" + testNum);
         SimpleTest.finish();
         return;
     }
 
     setTimeout(runTest, 50, testNum + 1); // XXX 40ms was too slow, why?
 }