Bug 1123514 - Add test for wrong offset calculation; r=esawin
authorJim Chen <nchen@mozilla.com>
Sun, 06 Nov 2016 18:44:09 -0500
changeset 348056 803d5895353dd7053a80b3fcd702a17aeff7aad2
parent 348055 ad907a673389fb1d6b7b9690d8ed57b77e2c5aa0
child 348057 7fa6baac8f3790a6d217c88c7187e98cf1e22e0f
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1123514
milestone52.0a1
Bug 1123514 - Add test for wrong offset calculation; r=esawin Add a test that creates conditions for wrong offset calculation and potentially causes an exception.
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
@@ -122,16 +122,27 @@
           let inputIme = getEditor().QueryInterface(SpecialPowers.Ci.nsIEditorIMESupport);
           do_check_true(inputIme.composing);
 
           // Ending the composition then setting the selection triggers the bug.
           inputIme.forceCompositionEnd();
           setSelection(3); // Offsets that testInputConnection.java expects.
         },
 
+        test_bug1123514: function() {
+          document.activeElement.addEventListener('input', function test_bug1123514_listener() {
+            this.removeEventListener('input', test_bug1123514_listener);
+
+            // Only works on input and textarea.
+            if (this.value === 'b') {
+              this.value = 'abc';
+            }
+          });
+        },
+
         focus_resetting_input: function(val) {
           resetting_input.value = val;
           resetting_input.focus();
         },
 
         focus_hiding_input: function(val) {
           hiding_input.value = val;
           hiding_input.style.display = "";
--- 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
@@ -238,16 +238,29 @@ public class testInputConnection extends
             ic.sendKeyEvent(delKey);
             ic.sendKeyEvent(KeyEvent.changeAction(delKey, KeyEvent.ACTION_UP));
             ic.sendKeyEvent(KeyEvent.changeAction(shiftKey, KeyEvent.ACTION_UP));
             assertTextAndSelectionAt("Cannot forward delete with shift+backspace", ic, "oo", 0);
 
             ic.deleteSurroundingText(0, 2);
             assertTextAndSelectionAt("Can clear text", ic, "", 0);
 
+            // Bug 1123514 - exception due to incorrect text replacement offsets.
+            getJS().syncCall("test_bug1123514");
+            // Gecko will change text to 'abc' when we input 'b', potentially causing
+            // incorrect calculation of text replacement offsets.
+            ic.commitText("b", 1);
+            // We don't assert text here because this test only works for input/textarea,
+            // so an assertion would fail for contentEditable/designMode.
+            processGeckoEvents();
+            processInputConnectionEvents();
+
+            ic.deleteSurroundingText(2, 1);
+            assertTextAndSelectionAt("Can clear text", ic, "", 0);
+
             // Make sure we don't leave behind stale events for the following test.
             processGeckoEvents();
             processInputConnectionEvents();
         }
     }
 
     /**
      * ResettingInputConnectionTest performs tests on the resetting input in