Bug 1241558 - Add test to testInputConnection; r=esawin
authorJim Chen <nchen@mozilla.com>
Tue, 09 Feb 2016 23:36:41 -0500
changeset 306701 1456f80ef613b32ed51ccd4a61ffbcae9d46128d
parent 306700 5ff7ebae71b27c27ee53dd98c9b478fd1057e298
child 306702 f2dfb3c8fd454eaf6366e2ca57758b45a058ecb8
push id9214
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:25:21 +0000
treeherdermozilla-aurora@8849dd1a4a79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1241558
milestone47.0a1
Bug 1241558 - Add test to testInputConnection; r=esawin
mobile/android/tests/browser/robocop/robocop_input.html
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
--- a/mobile/android/tests/browser/robocop/robocop_input.html
+++ b/mobile/android/tests/browser/robocop/robocop_input.html
@@ -28,16 +28,26 @@
           let inputIme = inputEditable.editor.QueryInterface(SpecialPowers.Ci.nsIEditorIMESupport);
           do_check_true(inputIme.composing);
 
           // Ending the composition then setting the input value triggers the bug.
           inputIme.forceCompositionEnd();
           input.value = "good";
         },
 
+        test_set_selection: function() {
+          let inputEditable = SpecialPowers.wrap(input).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement);
+          let inputIme = inputEditable.editor.QueryInterface(SpecialPowers.Ci.nsIEditorIMESupport);
+          do_check_true(inputIme.composing);
+
+          // Ending the composition then setting the selection triggers the bug.
+          inputIme.forceCompositionEnd();
+          input.setSelectionRange(3, 3);
+        },
+
         focus_resetting_input: function(val) {
           resetting_input.value = val;
           resetting_input.focus();
         },
 
         finish_test: function() {
           java.disconnect();
         },
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
@@ -189,16 +189,35 @@ public class testInputConnection extends
             ic.setComposingText("done", 1);
             assertTextAndSelectionAt("Can update composition after re-flushing", ic, "done", 4);
             ic.finishComposingText();
             assertTextAndSelectionAt("Can finish composing text", ic, "done", 4);
 
             ic.deleteSurroundingText(4, 0);
             assertTextAndSelectionAt("Can clear text", ic, "", 0);
 
+            // Bug 1241558 - wrong selection due to ignoring selection notification.
+            ic.setComposingText("foobar", 1);
+            assertTextAndSelectionAt("Can set the composing text", ic, "foobar", 6);
+            js.asyncCall("test_set_selection");
+            // Wait for text change notifications to come in.
+            processGeckoEvents(ic);
+            assertTextAndSelectionAt("Can select after committing", ic, "foobar", 3);
+            ic.setComposingText("barfoo", 1);
+            assertTextAndSelectionAt("Can compose after selecting", ic, "barfoo", 6);
+            ic.beginBatchEdit();
+            ic.setSelection(3, 3);
+            ic.finishComposingText();
+            ic.deleteSurroundingText(1, 1);
+            ic.endBatchEdit();
+            assertTextAndSelectionAt("Can delete after committing", ic, "baoo", 2);
+
+            ic.deleteSurroundingText(2, 2);
+            assertTextAndSelectionAt("Can clear text", ic, "", 0);
+
             // Make sure we don't leave behind stale events for the following test.
             processGeckoEvents(ic);
             processInputConnectionEvents();
         }
     }
 
     /**
      * ResettingInputConnectionTest performs tests on the resetting input in