Bug 309731 - Allow document.execCommand('inserthtml') with an empty string parameter. r=ehsan

This commit is contained in:
Michael Layzell 2015-05-14 08:02:00 -04:00
Родитель 20e1297913
Коммит 4e252b0ed5
6 изменённых файлов: 76 добавлений и 11 удалений

Просмотреть файл

@ -187,9 +187,8 @@
"Command insertHorizontalRule, value \"id\": input event, canceled":true,
"Command insertHorizontalRule, value \"id\": beforeinput event, uncanceled":true,
"Command insertHorizontalRule, value \"id\": input event, uncanceled":true,
"Command insertHTML, value \"\": execCommand() must not throw, canceled":true,
"Command insertHTML, value \"\": beforeinput event, canceled":true,
"Command insertHTML, value \"\": execCommand() must not throw, uncanceled":true,
"Command insertHTML, value \"\": input event, canceled":true,
"Command insertHTML, value \"\": beforeinput event, uncanceled":true,
"Command insertHTML, value \"\": input event, uncanceled":true,
"Command insertHTML, value \"quasit\": beforeinput event, canceled":true,

Просмотреть файл

@ -3801,9 +3801,6 @@
"[[\"inserthtml\",\"<!--abc-->\"]] \"<p><br>{}</p>\" compare innerHTML":true,
"[[\"inserthtml\",\"<!--abc-->\"]] \"<p><!--foo--><span><br></span>{}<!--bar--></p>\" compare innerHTML":true,
"[[\"inserthtml\",\"<!--abc-->\"]] \"<p><span><!--foo--><br><!--bar--></span>{}</p>\" compare innerHTML":true,
"[[\"inserthtml\",\"\"]] \"foo[bar]baz\": execCommand(\"inserthtml\", false, \"\") return value":true,
"[[\"inserthtml\",\"\"]] \"foo[bar]baz\" compare innerHTML":true,
"[[\"inserthtml\",\"\\u0000\"]] \"foo[bar]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"inserthtml\",\"<b>\"]] \"foo[bar]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"inserthtml\",\"<b>\"]] \"foo[bar]baz\" compare innerHTML":true,
"[[\"defaultparagraphseparator\",\"div\"],[\"inserthtml\",\"<p>abc\"]] \"<p>foo[bar]baz\": execCommand(\"defaultparagraphseparator\", false, \"div\") return value":true,

Просмотреть файл

@ -1311,7 +1311,15 @@ nsInsertHTMLCommand::IsCommandEnabled(const char * aCommandName,
NS_IMETHODIMP
nsInsertHTMLCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
{
return NS_ERROR_NOT_IMPLEMENTED;
// If nsInsertHTMLCommand is called with no parameters, it was probably called with
// an empty string parameter ''. In this case, it should act the same as the delete command
NS_ENSURE_ARG_POINTER(refCon);
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
nsString html = EmptyString();
return editor->InsertHTML(html);
}
NS_IMETHODIMP
@ -1330,10 +1338,7 @@ nsInsertHTMLCommand::DoCommandParams(const char *aCommandName,
nsresult rv = aParams->GetStringValue(STATE_DATA, html);
NS_ENSURE_SUCCESS(rv, rv);
if (!html.IsEmpty())
return editor->InsertHTML(html);
return NS_OK;
return editor->InsertHTML(html);
}
NS_IMETHODIMP

Просмотреть файл

@ -303,6 +303,11 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
streamEndParentNode, streamEndOffset);
if (nodeList.Length() == 0) {
// We aren't inserting anything, but if aDeleteSelection is set, we do want
// to delete everything.
if (aDeleteSelection) {
return DeleteSelection(eNone, eStrip);
}
return NS_OK;
}

Просмотреть файл

@ -19,6 +19,7 @@ support-files =
skip-if = os != "mac"
[test_bug290026.html]
[test_bug291780.html]
[test_bug309731.html]
[test_bug316447.html]
[test_bug318065.html]
[test_bug332636.html]
@ -161,4 +162,4 @@ skip-if = e10s
[test_spellcheck_pref.html]
skip-if = toolkit == 'android'
[test_bug1068979.html]
[test_bug1109465.html]
[test_bug1109465.html]

Просмотреть файл

@ -0,0 +1,58 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=309731
-->
<head>
<title>Test for Bug 309731</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=309731">Mozilla Bug 309731</a>
<p id="display"></p>
<div id="content">
<div id="input" contentEditable="true"></div>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 309731 **/
function selectNode(node) {
getSelection().selectAllChildren(node);
}
function selectInNode(node) {
getSelection().collapse(node, 0);
}
function doTest() {
var input = document.getElementById("input");
is(input.textContent, "", "Input node starts empty");
selectInNode(input);
ok(document.execCommand("inserthtml", false, ""), "execCommand should return true");
is(input.textContent, "", "empty inserthtml with empty selection shouldn't change contents");
selectInNode(input);
ok(document.execCommand("inserthtml", false, "foo"), "execCommand should return true");
is(input.textContent, "foo", "'foo'inserthtml with empty selection should add foo to contents");
selectNode(input);
ok(document.execCommand("inserthtml", false, "bar"), "execCommand should return true");
is(input.textContent, "bar", "'bar' inserthtml with complete selection should replace contents with bar");
selectNode(input);
ok(document.execCommand("inserthtml", false, ""), "execCommand should return true");
is(input.textContent, "", "empty inserthtml with complete selection should delete everything");
}
doTest();
</script>
</pre>
</body>
</html>