mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1255586 - Add test cases for more input types in testInputConnection; r=esawin
Add test cases for text areas, content editables, and design mode editors.
This commit is contained in:
parent
1f14c2a2c3
commit
b1cb0d5438
@ -6,11 +6,22 @@
|
||||
</head>
|
||||
<body>
|
||||
<p>Input: <input id="input" type="text"></p>
|
||||
<p>Text area: <textarea id="text-area"></textarea></p>
|
||||
<p>Content editable: <div id="content-editable" contentEditable="true"></div></p>
|
||||
<p>Design mode: <iframe id="design-mode" src="data:text/html;charset=utf-8,<html><body></body></html>"></iframe></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");
|
||||
let textArea = document.getElementById("text-area");
|
||||
let contentEditable = document.getElementById("content-editable");
|
||||
|
||||
let designMode = document.getElementById("design-mode");
|
||||
designMode.contentDocument.designMode = "on";
|
||||
|
||||
// Spatial navigation interferes with design-mode key event tests.
|
||||
SpecialPowers.setBoolPref("snav.enabled", false);
|
||||
|
||||
// An input that resets the editor on every input by resetting the value property.
|
||||
let resetting_input = document.getElementById("resetting-input");
|
||||
@ -27,30 +38,92 @@
|
||||
}
|
||||
});
|
||||
|
||||
let getEditor, setValue, setSelection;
|
||||
|
||||
let test = {
|
||||
focus_input: function(val) {
|
||||
input.value = val;
|
||||
getEditor = function() {
|
||||
return SpecialPowers.wrap(input).QueryInterface(
|
||||
SpecialPowers.Ci.nsIDOMNSEditableElement).editor;
|
||||
};
|
||||
setValue = function(val) {
|
||||
input.value = val;
|
||||
};
|
||||
setSelection = function(pos) {
|
||||
input.setSelectionRange(pos, pos);
|
||||
};
|
||||
setValue(val);
|
||||
input.focus();
|
||||
},
|
||||
|
||||
focus_textArea: function(val) {
|
||||
getEditor = function() {
|
||||
return SpecialPowers.wrap(textArea).QueryInterface(
|
||||
SpecialPowers.Ci.nsIDOMNSEditableElement).editor;
|
||||
};
|
||||
setValue = function(val) {
|
||||
textArea.value = val;
|
||||
};
|
||||
setSelection = function(pos) {
|
||||
textArea.setSelectionRange(pos, pos);
|
||||
};
|
||||
setValue(val);
|
||||
textArea.focus();
|
||||
},
|
||||
|
||||
focus_contentEditable: function(val) {
|
||||
getEditor = function() {
|
||||
return SpecialPowers.wrap(window).QueryInterface(
|
||||
SpecialPowers.Ci.nsIInterfaceRequestor).getInterface(
|
||||
SpecialPowers.Ci.nsIWebNavigation).QueryInterface(
|
||||
SpecialPowers.Ci.nsIDocShell).editor;
|
||||
};
|
||||
setValue = function(val) {
|
||||
contentEditable.innerHTML = val;
|
||||
};
|
||||
setSelection = function(pos) {
|
||||
window.getSelection().collapse(contentEditable.firstChild, pos);
|
||||
};
|
||||
setValue(val);
|
||||
contentEditable.focus();
|
||||
},
|
||||
|
||||
focus_designMode: function(val) {
|
||||
getEditor = function() {
|
||||
return SpecialPowers.wrap(designMode.contentWindow).QueryInterface(
|
||||
SpecialPowers.Ci.nsIInterfaceRequestor).getInterface(
|
||||
SpecialPowers.Ci.nsIWebNavigation).QueryInterface(
|
||||
SpecialPowers.Ci.nsIDocShell).editor;
|
||||
};
|
||||
setValue = function(val) {
|
||||
designMode.contentDocument.body.innerHTML = val;
|
||||
};
|
||||
setSelection = function(pos) {
|
||||
designMode.contentWindow.getSelection().collapse(
|
||||
designMode.contentDocument.body.firstChild, pos);
|
||||
};
|
||||
setValue(val);
|
||||
designMode.contentWindow.focus();
|
||||
designMode.contentDocument.body.focus();
|
||||
},
|
||||
|
||||
test_reflush_changes: function() {
|
||||
let inputEditable = SpecialPowers.wrap(input).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement);
|
||||
let inputIme = inputEditable.editor.QueryInterface(SpecialPowers.Ci.nsIEditorIMESupport);
|
||||
let inputIme = getEditor().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"; // Value that testInputConnection.java expects.
|
||||
setValue("good"); // Value that testInputConnection.java expects.
|
||||
setSelection(4);
|
||||
},
|
||||
|
||||
test_set_selection: function() {
|
||||
let inputEditable = SpecialPowers.wrap(input).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement);
|
||||
let inputIme = inputEditable.editor.QueryInterface(SpecialPowers.Ci.nsIEditorIMESupport);
|
||||
let inputIme = getEditor().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); // Offsets that testInputConnection.java expects.
|
||||
setSelection(3); // Offsets that testInputConnection.java expects.
|
||||
},
|
||||
|
||||
focus_resetting_input: function(val) {
|
||||
|
@ -43,6 +43,24 @@ public class testInputConnection extends JavascriptBridgeTest {
|
||||
.waitForInputConnection()
|
||||
.testInputConnection(new BasicInputConnectionTest());
|
||||
|
||||
// Then switch focus to the text area and rerun tests.
|
||||
getJS().syncCall("focus_text_area", INITIAL_TEXT);
|
||||
mGeckoView.mTextInput
|
||||
.waitForInputConnection()
|
||||
.testInputConnection(new BasicInputConnectionTest());
|
||||
|
||||
// Then switch focus to the content editable and rerun tests.
|
||||
getJS().syncCall("focus_content_editable", INITIAL_TEXT);
|
||||
mGeckoView.mTextInput
|
||||
.waitForInputConnection()
|
||||
.testInputConnection(new BasicInputConnectionTest());
|
||||
|
||||
// Then switch focus to the design mode document and rerun tests.
|
||||
getJS().syncCall("focus_design_mode", INITIAL_TEXT);
|
||||
mGeckoView.mTextInput
|
||||
.waitForInputConnection()
|
||||
.testInputConnection(new BasicInputConnectionTest());
|
||||
|
||||
// Then switch focus to the resetting input field, and run tests there.
|
||||
getJS().syncCall("focus_resetting_input", "");
|
||||
mGeckoView.mTextInput
|
||||
@ -60,9 +78,13 @@ public class testInputConnection extends JavascriptBridgeTest {
|
||||
|
||||
private class BasicInputConnectionTest extends InputConnectionTest {
|
||||
@Override
|
||||
public void test(InputConnection ic, EditorInfo info) {
|
||||
// Test initial text provided by the hash in the test page URL
|
||||
assertText("Initial text matches URL hash", ic, INITIAL_TEXT);
|
||||
public void test(final InputConnection ic, EditorInfo info) {
|
||||
waitFor("focus change", new Condition() {
|
||||
@Override
|
||||
public boolean isSatisfied() {
|
||||
return INITIAL_TEXT.equals(getText(ic));
|
||||
}
|
||||
});
|
||||
|
||||
// Test setSelection
|
||||
ic.setSelection(0, 3);
|
||||
@ -258,6 +280,10 @@ public class testInputConnection extends JavascriptBridgeTest {
|
||||
|
||||
ic.deleteSurroundingText(3, 0);
|
||||
assertTextAndSelectionAt("Can clear text", ic, "", 0);
|
||||
|
||||
// Make sure we don't leave behind stale events for the following test.
|
||||
processGeckoEvents(ic);
|
||||
processInputConnectionEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user