Bug 717147 part.2 Don't do autocomplete during composition r=dolske
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 13 Jan 2012 15:19:22 +0900
changeset 84401 1a71337e5cf7b1443455ab68a9da65c747a1acd5
parent 84400 1f64197c3878270bc26fb030b87b81fcf4bceb0e
child 84402 78e58e679fca654cfc28fa12127803b824e62487
push id21848
push usermak77@bonardo.net
push dateSat, 14 Jan 2012 09:02:20 +0000
treeherdermozilla-central@27a7f197c6fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs717147
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 717147 part.2 Don't do autocomplete during composition r=dolske
editor/libeditor/text/tests/Makefile.in
editor/libeditor/text/tests/test_bug717147.html
toolkit/components/autocomplete/nsAutoCompleteController.cpp
--- a/editor/libeditor/text/tests/Makefile.in
+++ b/editor/libeditor/text/tests/Makefile.in
@@ -60,16 +60,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug604532.html \
 		test_bug625452.html \
 		test_bug629172.html \
 		test_bug638596.html \
 		test_bug641466.html \
 		test_bug645914.html \
 		test_bug681229.html \
 		test_bug692520.html \
+		test_bug717147.html \
 		$(NULL)
 
 # disables the key handling test on gtk2 because gtk2 overrides some key events
 # on our editor, and the combinations depend on the system.
 ifneq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 _TEST_FILES += \
 		test_texteditor_keyevent_handling.html \
 		$(NULL)
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/text/tests/test_bug717147.html
@@ -0,0 +1,99 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=717147
+-->
+<head>
+  <title>Test for Bug 717147</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717147">Mozilla Bug 717147</a>
+<p id="display"></p>
+<div id="content">
+  <iframe id="formTarget" name="formTarget"></iframe>
+  <form action="data:text/html," target="formTarget">
+    <input name="test" id="initValue"><input type="submit">
+  </form>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 717147 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+  var formTarget = document.getElementById("formTarget");
+  var initValue = document.getElementById("initValue");
+
+  formTarget.addEventListener("load", function() {
+    var newInput = document.createElement("input");
+    newInput.setAttribute("name", "test");
+    document.body.appendChild(newInput);
+
+    setTimeout(function() {
+      var popupShown = false;
+      function listener() {
+        popupShown = true;
+      }
+      SpecialPowers.addAutoCompletePopupEventListener(window, listener);
+
+      newInput.value = "";
+      newInput.focus();
+
+      synthesizeComposition({ type: "compositionstart" });
+      synthesizeComposition({ type: "compositionupdate", data: "f" });
+      synthesizeText(
+        { "composition":
+          { "string": "f",
+            "clauses":
+            [
+              { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
+            ]
+          },
+          "caret": { "start": 1, "length": 0 }
+        });
+
+      hitEventLoop(function() {
+        ok(!popupShown, "Popup must not be opened during composition");
+
+        synthesizeText(
+          { "composition":
+            { "string": "f",
+              "clauses":
+              [
+                { "length": 0, "attr": 0 }
+              ]
+            },
+            "caret": { "start": 1, "length": 0 }
+          });
+        synthesizeComposition({ type: "compositionend", data: "f" });
+
+        hitEventLoop(function () {
+          ok(popupShown, "Popup must be opened after compositionend");
+
+          SpecialPowers.removeAutoCompletePopupEventListener(window, listener);
+          SimpleTest.finish();
+        }, 100);
+      }, 100);
+    }, 0);
+  }, false);
+
+  initValue.focus();
+  initValue.value = "foo";
+  synthesizeKey("VK_ENTER", {});
+});
+
+function hitEventLoop(func, times) {
+  if (times > 0) {
+    setTimeout(hitEventLoop, 0, func, times - 1);
+  } else {
+    setTimeout(func, 0);
+  }
+}
+
+</script>
+</pre>
+</body>
+</html>
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -185,16 +185,21 @@ nsAutoCompleteController::StartSearch(co
   mSearchString = aSearchString;
   StartSearchTimer();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAutoCompleteController::HandleText()
 {
+  // We should do nothing during composition.
+  if (mIsIMEComposing) {
+    return NS_OK;
+  }
+
   if (!mInput) {
     // Stop all searches in case they are async.
     StopSearch();
     // Note: if now is after blur and IME end composition,
     // check mInput before calling.
     // See https://bugzilla.mozilla.org/show_bug.cgi?id=193544#c31
     NS_ERROR("Called before attaching to the control or after detaching from the control");
     return NS_OK;