Bug 739557 Set focus to editing host and use document.getSelection().collapse() for setting caret to edit target; r=ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 29 Mar 2012 09:10:22 -0700
changeset 93945 f059dc47f3d7d219085e9d654a87263d7bdefb24
parent 93944 a9dfce8466063e7e76276cb3767c3fd555cb3ab7
child 93946 7737ca75286045bc60000236dacd39003ee1b9a2
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs739557
milestone14.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 739557 Set focus to editing host and use document.getSelection().collapse() for setting caret to edit target; r=ehsan
editor/libeditor/html/tests/test_dom_input_event_on_htmleditor.html
--- a/editor/libeditor/html/tests/test_dom_input_event_on_htmleditor.html
+++ b/editor/libeditor/html/tests/test_dom_input_event_on_htmleditor.html
@@ -31,26 +31,39 @@ const kIsMac = navigator.platform.indexO
 
 function runTests()
 {
   function doTests(aDocument, aWindow, aDescription)
   {
     aDescription += ": ";
     aWindow.focus();
 
+    var body = aDocument.body;
+
     var eventTarget = aDocument.getElementById("eventTarget");
+    // The event target must be focusable because it's the editing host.
+    eventTarget.focus();
 
     var editTarget = aDocument.getElementById("editTarget");
     if (!editTarget) {
       editTarget = eventTarget;
     }
+
+    // Root element never can be edit target.  If the editTarget is the root
+    // element, replace with its body.
+    if (editTarget == aDocument.documentElement) {
+      editTarget = body;
+    }
+
     editTarget.innerHTML = "";
-    editTarget.focus();
 
-    var body = aDocument.body;
+    // If the editTarget isn't its editing host, move caret to the start of it.
+    if (eventTarget != editTarget) {
+      aDocument.getSelection().collapse(editTarget, 0);
+    }
 
     var inputEvent = null;
 
     var handler = function (aEvent) {
       is(aEvent.target, eventTarget,
          "input event is fired on unexpected element: " + aEvent.target.tagName);
       ok(!aEvent.cancelable, "input event must not be cancelable");
       ok(aEvent.bubbles, "input event must be bubbles");
@@ -60,19 +73,17 @@ function runTests()
          "perhaps, timestamp wasn't set correctly :" + eventTime.toLocaleString());
       inputEvent = aEvent;
     };
 
     aWindow.addEventListener("input", handler, true);
 
     inputEvent = null;
     synthesizeKey("a", { }, aWindow);
-    if (editTarget != eventTarget) {
-      is(editTarget.innerHTML, "a", aDescription + "wrong element was edited");
-    }
+    is(editTarget.innerHTML, "a", aDescription + "wrong element was edited");
     ok(inputEvent, aDescription + "input event wasn't fired by 'a' key");
     ok(inputEvent.isTrusted, aDescription + "input event by 'a' key wasn't trusted event");
 
     inputEvent = null;
     synthesizeKey("VK_BACK_SPACE", { }, aWindow);
     ok(inputEvent, aDescription + "input event wasn't fired by BackSpace key");
     ok(inputEvent.isTrusted, aDescription + "input event by BackSpace key wasn't trusted event");