Bug 1478268 - Fix condition of MOZ_ASSERT() in TextEditor::InsertWithQuotationsAsSubAction() r=jorgk+176914

As explained in the comment of TextEditor::InsertWithQuotationsAsSubAction(),
it excepts that TextEditRules::WillDoAction() won't handle it.  So, the
MOZ_ASSERT() should check |!handled|, not |handled|.

Caused this regression means that we do not have test to paste text into
<textarea>.  Therefore, this patch adds the tests.

MozReview-Commit-ID: 2UUSVrmmNVK

--HG--
extra : rebase_source : 912d5428aeed83a7a46ec7e4a49c73c33dd7b295
This commit is contained in:
Masayuki Nakano 2018-07-26 17:01:15 +09:00
parent b590219ca3
commit 4619306c40
3 changed files with 147 additions and 1 deletions

View File

@ -1932,7 +1932,7 @@ TextEditor::InsertWithQuotationsAsSubAction(const nsAString& aQuotedText)
if (cancel) {
return NS_OK; // Rules canceled the operation.
}
MOZ_ASSERT(handled, "WillDoAction() shouldn't handle in this case");
MOZ_ASSERT(!handled, "WillDoAction() shouldn't handle in this case");
if (!handled) {
// TODO: Use InsertTextAsSubAction() when bug 1467796 is fixed.
rv = InsertTextAsAction(quotedStuff);

View File

@ -275,6 +275,8 @@ skip-if = os == 'android'
[test_inlineTableEditing.html]
[test_insertParagraph_in_inline_editing_host.html]
[test_keypress_untrusted_event.html]
[test_middle_click_paste.html]
subsuite = clipboard
[test_objectResizing.html]
[test_root_element_replacement.html]
[test_select_all_without_body.html]

View File

@ -0,0 +1,144 @@
<!DOCTYPE html>
<html>
<head>
<title>Test for paste as quotation with middle button click</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none;">
</div>
<div id="container"></div>
<textarea id="toCopyPlaintext" style="display: none;"></textarea>
<iframe id="toCopyHTMLContent" srcdoc="<body></body>" style="display: none;"></iframe>
<pre id="test">
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
// TODO: This file should test complicated cases too.
// E.g., pasting into existing content, e.g., pasting invalid child
// element for the parent elements at insertion point.
async function copyPlaintext(aText) {
return new Promise(resolve => {
SimpleTest.waitForClipboard(aText,
() => {
let element = document.getElementById("toCopyPlaintext");
element.style.display = "block";
element.focus();
element.value = aText;
synthesizeKey("a", {accelKey: true});
synthesizeKey("c", {accelKey: true});
},
() => {
ok(true, `Succeeded to copy "${aText}" to clipboard`);
let element = document.getElementById("toCopyPlaintext");
element.style.display = "none";
resolve();
},
() => {
SimpleTest.finish();
});
});
}
async function copyHTMLContent(aInnerHTML) {
return new Promise(resolve => {
SimpleTest.waitForClipboard(
() => { return true; },
() => {
let element = document.getElementById("toCopyHTMLContent");
element.style.display = "block";
element.contentDocument.body.innerHTML = aInnerHTML;
element.contentWindow.focus();
element.contentDocument.getSelection().selectAllChildren(element.contentDocument.body);
synthesizeKey("c", {accelKey: true}, element.contentWindow);
},
() => {
ok(true, `Succeeded to copy "${aInnerHTML}" to clipboard as HTML`);
let element = document.getElementById("toCopyHTMLContent");
element.style.display = "none";
resolve();
},
() => {
SimpleTest.finish();
},
"text/html");
});
}
async function doTextareaTests(aTextarea) {
await copyPlaintext("abc\ndef\nghi");
aTextarea.focus();
synthesizeMouseAtCenter(aTextarea, {button: 1, ctrlKey: true});
is(aTextarea.value,
"> abc\n> def\n> ghi\n\n",
"Pasted each line should start with \"> \"");
aTextarea.value = "";
await copyPlaintext("> abc\n> def\n> ghi");
aTextarea.focus();
synthesizeMouseAtCenter(aTextarea, {button: 1, ctrlKey: true});
is(aTextarea.value,
">> abc\n>> def\n>> ghi\n\n",
"Pasted each line should be start with \">> \" when already quoted one level");
aTextarea.value = "";
await copyPlaintext("> abc\n> def\n\nghi");
aTextarea.focus();
synthesizeMouseAtCenter(aTextarea, {button: 1, ctrlKey: true});
is(aTextarea.value,
">> abc\n>> def\n> \n> ghi\n\n",
"Pasted each line should be start with \">> \" when already quoted one level");
aTextarea.value = "";
await copyPlaintext("abc\ndef\n\n");
aTextarea.focus();
synthesizeMouseAtCenter(aTextarea, {button: 1, ctrlKey: true});
is(aTextarea.value,
"> abc\n> def\n> \n",
"If pasted text ends with \"\\n\", only the last line should not started with \">\"");
aTextarea.value = "";
}
async function doContenteditableTests(aEditableDiv) {
await copyPlaintext("abc\ndef\nghi");
aEditableDiv.focus();
synthesizeMouseAtCenter(aEditableDiv, {button: 1, ctrlKey: true});
is(aEditableDiv.innerHTML,
"<blockquote type=\"cite\">abc<br>def<br>ghi</blockquote>",
"Pasted plaintext should be in <blockquote> element and each linebreaker should be <br> element");
aEditableDiv.innerHTML = "";
await copyHTMLContent("<p>abc</p><p>def</p><p>ghi</p>");
aEditableDiv.focus();
synthesizeMouseAtCenter(aEditableDiv, {button: 1, ctrlKey: true});
is(aEditableDiv.innerHTML,
"<blockquote type=\"cite\"><p>abc</p><p>def</p><p>ghi</p></blockquote>",
"Pasted HTML content should be set to the <blockquote>");
aEditableDiv.innerHTML = "";
}
async function doTests() {
await SpecialPowers.pushPrefEnv({"set": [["middlemouse.paste", true],
["middlemouse.contentLoadURL", false]]});
let container = document.getElementById("container");
container.innerHTML = "<textarea id=\"editor\"></textarea>";
await doTextareaTests(document.getElementById("editor"));
container.innerHTML = "<div id=\"editor\" contenteditable style=\"min-height: 1em;\"></div>";
await doContenteditableTests(document.getElementById("editor"));
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTests);
</script>
</pre>
</body>
</html>