Bug 1254629 - Add "hide on input" test case; r=esawin

The bug happens when an input is hidden (e.g. through 'display' style)
inside an input or key event handler.
This commit is contained in:
Jim Chen 2016-03-11 13:47:22 -05:00
parent fc50ab814f
commit eb65d5bc9f
2 changed files with 58 additions and 6 deletions

View File

@ -5,16 +5,26 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p><input id="input" type="text"></p>
<p><input id="resetting-input" type="text"></p>
<p>Input: <input id="input" type="text"></p>
<p>Resetting input: <input id="resetting-input" type="text"></p>
<p>Hiding input: <input id="hiding-input" type="text"></p>
<script type="application/javascript;version=1.8" src="robocop_head.js"></script>
<script type="application/javascript;version=1.8">
let input = document.getElementById("input");
// An input that resets the editor on every input by resetting the value property.
let resetting_input = document.getElementById("resetting-input");
resetting_input.addEventListener('input', function () {
this.value = this.value;
resetting_input.addEventListener('input', function() {
this.value = this.value;
});
// An input that hides on input.
let hiding_input = document.getElementById("hiding-input");
hiding_input.addEventListener('keydown', function(e) {
if (e.key === "!") { // '!' key event as sent by testInputConnection.java.
this.value = "";
this.style.display = "none";
}
});
let test = {
@ -30,7 +40,7 @@
// Ending the composition then setting the input value triggers the bug.
inputIme.forceCompositionEnd();
input.value = "good";
input.value = "good"; // Value that testInputConnection.java expects.
},
test_set_selection: function() {
@ -40,7 +50,7 @@
// Ending the composition then setting the selection triggers the bug.
inputIme.forceCompositionEnd();
input.setSelectionRange(3, 3);
input.setSelectionRange(3, 3); // Offsets that testInputConnection.java expects.
},
focus_resetting_input: function(val) {
@ -48,6 +58,12 @@
resetting_input.focus();
},
focus_hiding_input: function(val) {
hiding_input.value = val;
hiding_input.style.display = "";
hiding_input.focus();
},
finish_test: function() {
java.disconnect();
},

View File

@ -49,6 +49,12 @@ public class testInputConnection extends JavascriptBridgeTest {
.waitForInputConnection()
.testInputConnection(new ResettingInputConnectionTest());
// Then switch focus to the hiding input field, and run tests there.
getJS().syncCall("focus_hiding_input", "");
mGeckoView.mTextInput
.waitForInputConnection()
.testInputConnection(new HidingInputConnectionTest());
getJS().syncCall("finish_test");
}
@ -254,4 +260,34 @@ public class testInputConnection extends JavascriptBridgeTest {
assertTextAndSelectionAt("Can clear text", ic, "", 0);
}
}
/**
* HidingInputConnectionTest performs tests on the hiding input in
* robocop_input.html. Any test that uses the normal input should be put in
* BasicInputConnectionTest.
*/
private class HidingInputConnectionTest extends InputConnectionTest {
@Override
public void test(final InputConnection ic, EditorInfo info) {
waitFor("focus change", new Condition() {
@Override
public boolean isSatisfied() {
return "".equals(getText(ic));
}
});
// Bug 1254629, crash when hiding input during input.
ic.commitText("foo", 1);
assertTextAndSelectionAt("Can commit text (hiding)", ic, "foo", 3);
ic.commitText("!", 1);
// The '!' key causes the input to hide in robocop_input.html,
// and there won't be a text/selection update as a result.
assertTextAndSelectionAt("Can handle hiding input", ic, "foo", 3);
// Make sure we don't leave behind stale events for the following test.
processGeckoEvents(ic);
processInputConnectionEvents();
}
}
}