Bug 808287 - Add test for IME focus/blur mismatch condition; r=masayuki
authorJim Chen <nchen@mozilla.com>
Sat, 17 Nov 2012 19:15:01 -0500
changeset 121568 131a7ee2362c4ae530cab9effc6143c9cfca4b00
parent 121567 e4cd4714357d9adbc53a05eb02bcf1bac03d1114
child 121569 940e9616ec59e34ab334440d753517aa2c1b6e22
push idunknown
push userunknown
push dateunknown
reviewersmasayuki
bugs808287
milestone19.0a1
Bug 808287 - Add test for IME focus/blur mismatch condition; r=masayuki
widget/tests/test_imestate.html
--- a/widget/tests/test_imestate.html
+++ b/widget/tests/test_imestate.html
@@ -1351,17 +1351,18 @@ function runTestPasswordFieldOnDialog()
       QueryInterface(Components.interfaces.nsIInterfaceRequestor).
       getInterface(Components.interfaces.nsIDOMWindowUtils);
     is(utils.IMEStatus, utils.IME_STATUS_PASSWORD,
        "IME isn't disabled on a password field of password dialog");
     synthesizeKey("VK_ESCAPE", { }, dialog);
   }
 }
 
-function runBug580388Tests(aCallback)
+// Bug 580388 and bug 808287
+function runEditorReframeTests(aCallback)
 {
   if (document.activeElement) {
     document.activeElement.blur();
   }
 
   var input = document.getElementById("text");
   input.focus();
   input.style.overflow = "visible";
@@ -1389,28 +1390,46 @@ function runBug580388Tests(aCallback)
 
   document.addEventListener("MozIMEFocusIn", handler, true);
   document.addEventListener("MozIMEFocusOut", handler, true);
   input.addEventListener("input", onInput, true);
 
   sendChar("a");
 
   hitEventLoop(function () {
-    ok(mozIMEFocusOut > 0, "runBug580388Tests(): IME focus must be lost at reframing");
-    ok(mozIMEFocusIn > 0, "runBug580388Tests(): IME focus must be restored after reframing");
-    ok(IMEHasFocus, "runBug580388Tests(): IME must have focus after reframing");
+    ok(mozIMEFocusOut > 0, "runEditorReframeTests(): IME focus must be lost at reframing");
+    ok(mozIMEFocusIn > 0, "runEditorReframeTests(): IME focus must be restored after reframing");
+    ok(IMEHasFocus, "runEditorReframeTests(): IME must have focus after reframing");
+
+    var focusQueryHandler = function(aEvent) {
+        // Perform a style change and query during focus to trigger reframing
+        input.style.overflow = "visible";
+        synthesizeQuerySelectedText();
+    }
+    document.addEventListener("MozIMEFocusIn", focusQueryHandler, true);
+    mozIMEFocusIn = mozIMEFocusOut = 0;
 
-    document.removeEventListener("MozIMEFocusIn", handler, true);
-    document.removeEventListener("MozIMEFocusOut", handler, true);
-    input.removeEventListener("input", onInput, true);
+    input.blur();
+    input.focus();
+    sendChar("a");
+
+    hitEventLoop(function() {
+        ok(IMEHasFocus, "runEditorReframeTests(): IME must have focus after reframing during focus");
+        ok(mozIMEFocusOut == mozIMEFocusIn, "runEditorReframeTests(): IME focus/blur (" + mozIMEFocusIn + "/" + mozIMEFocusOut + ") must match after reframing during focus");
 
-    input.style.overflow = "visible";
-    input.value = "";
+        document.removeEventListener("MozIMEFocusIn", focusQueryHandler, true);
+        document.removeEventListener("MozIMEFocusIn", handler, true);
+        document.removeEventListener("MozIMEFocusOut", handler, true);
+        input.removeEventListener("input", onInput, true);
 
-    hitEventLoop(aCallback, 20);
+        input.style.overflow = "visible";
+        input.value = "";
+
+        hitEventLoop(aCallback, 20);
+    }, 20);
   }, 20);
 }
 
 function runTests()
 {
   if (!kIMEEnabledSupported && !kIMEOpenSupported)
     return;
 
@@ -1456,17 +1475,17 @@ function runTests()
   // test whether the IME state and composition are not changed unexpectedly
   runEditorFlagChangeTests();
 
   // test password field on dialog
   // XXX temporary disable against failure
   //runTestPasswordFieldOnDialog();
 
   // Asynchronous tests
-  runBug580388Tests(function () {
+  runEditorReframeTests(function () {
     // This will call onFinish(), so, this test must be the last.
     runEditableSubframeTests();
   });
 }
 
 function onFinish()
 {
   SpecialPowers.clearUserPref("test.IME");