mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 783846 - Add paste tests to testSelectionHandler. r=wesj
This commit is contained in:
parent
f801d95686
commit
712267f7b0
@ -25,6 +25,14 @@ function getSelectionHandler() {
|
||||
this._selectionHandler;
|
||||
}
|
||||
|
||||
function getClipboard() {
|
||||
return Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
|
||||
}
|
||||
|
||||
function getTextValue(aElement) {
|
||||
return aElement.value || aElement.textContent;
|
||||
}
|
||||
|
||||
function todo(result, msg) {
|
||||
return Messaging.sendRequestForResult({
|
||||
type: TYPE_NAME,
|
||||
|
@ -9,8 +9,9 @@
|
||||
|
||||
const DIV_POINT_TEXT = "Under";
|
||||
const INPUT_TEXT = "Text for select all in an <input>";
|
||||
const TEXTAREA_TEXT = "Text for select all in a <textarea>";
|
||||
const PASTE_TEXT = "Text for testing paste";
|
||||
const READONLY_INPUT_TEXT = "readOnly text";
|
||||
const TEXTAREA_TEXT = "Text for select all in a <textarea>";
|
||||
|
||||
/* =================================================================================
|
||||
*
|
||||
@ -25,6 +26,7 @@ function startTests() {
|
||||
then(testReadonlyInput).
|
||||
then(testCloseSelection).
|
||||
then(testStartSelectionFail).
|
||||
then(testPaste).
|
||||
|
||||
then(testAttachCaret).
|
||||
then(testAttachCaretFail).
|
||||
@ -351,6 +353,44 @@ function testAttachCaretFail() {
|
||||
});
|
||||
}
|
||||
|
||||
/* =================================================================================
|
||||
*
|
||||
* Tests to ensure we can paste text inside editable elements
|
||||
*
|
||||
*/
|
||||
function testPaste() {
|
||||
let sh = getSelectionHandler();
|
||||
let clipboard = getClipboard();
|
||||
clipboard.copyString(PASTE_TEXT, document);
|
||||
|
||||
// Add a contentEditable element to the document.
|
||||
let div = document.createElement("div");
|
||||
div.contentEditable = true;
|
||||
div.dataset.editable = true;
|
||||
document.body.appendChild(div);
|
||||
|
||||
let elements = document.querySelectorAll("div, input, textarea");
|
||||
let promises = [];
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
sh.startSelection(elements[i]);
|
||||
if (sh.isElementEditableText(elements[i]) && !elements[i].disabled) {
|
||||
sh.actions.PASTE.action(elements[i]);
|
||||
}
|
||||
if (elements[i].dataset.editable) {
|
||||
promises.push(is(getTextValue(elements[i]), PASTE_TEXT, "Pasted correctly"));
|
||||
promises.push(ok(sh.isElementEditableText(elements[i]), "Element is editable"));
|
||||
} else {
|
||||
promises.push(isNot(getTextValue(elements[i]), PASTE_TEXT, "Paste failed correctly"));
|
||||
}
|
||||
}
|
||||
|
||||
document.body.removeChild(div);
|
||||
div = null;
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@ -381,9 +421,9 @@ function testAttachCaretFail() {
|
||||
nunc vel, fringilla turpis. Nulla lacinia, leo ut egestas hendrerit, risus
|
||||
ligula interdum enim, vel varius libero sem ut ligula.</div><br>
|
||||
|
||||
<input id="inputNode" type="text"><br>
|
||||
<input data-editable="true" id="inputNode" type="text"><br>
|
||||
|
||||
<textarea id="textareaNode"></textarea><br>
|
||||
<textarea data-editable="true" id="textareaNode"></textarea><br>
|
||||
|
||||
<input id="readOnlyTextInput" type="text" readonly><br>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user