Bug 1027560 - return false from document.execCommand() and friends when not in editable document. r=ehsan

This commit is contained in:
Michael Layzell 2015-05-14 06:46:00 +02:00
parent 2d8a6ecf05
commit c0bb6f08c3
3 changed files with 2 additions and 15 deletions

View File

@ -3256,7 +3256,6 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
// if editing is not on, bail
if (!isCutCopy && !IsEditingOnAfterFlush()) {
rv.Throw(NS_ERROR_FAILURE);
return false;
}
@ -3293,7 +3292,6 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
if (restricted && !nsContentUtils::IsCallerChrome()) {
rv = NS_ERROR_DOM_SECURITY_ERR;
return false;
}
@ -3390,7 +3388,6 @@ nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID, ErrorResult& rv)
// if editing is not on, bail
if (!IsEditingOnAfterFlush()) {
rv.Throw(NS_ERROR_FAILURE);
return false;
}
@ -3433,7 +3430,6 @@ nsHTMLDocument::QueryCommandIndeterm(const nsAString& commandID, ErrorResult& rv
// if editing is not on, bail
if (!IsEditingOnAfterFlush()) {
rv.Throw(NS_ERROR_FAILURE);
return false;
}
@ -3494,7 +3490,6 @@ nsHTMLDocument::QueryCommandState(const nsAString& commandID, ErrorResult& rv)
// if editing is not on, bail
if (!IsEditingOnAfterFlush()) {
rv.Throw(NS_ERROR_FAILURE);
return false;
}
@ -3607,7 +3602,6 @@ nsHTMLDocument::QueryCommandValue(const nsAString& commandID,
// if editing is not on, bail
if (!IsEditingOnAfterFlush()) {
rv.Throw(NS_ERROR_FAILURE);
return;
}

View File

@ -9,8 +9,6 @@
"Editable b: execCommand() must not throw, uncanceled":true,
"Editable b: beforeinput event, uncanceled":true,
"Editable b: input event, uncanceled":true,
"No editable content: execCommand() must not throw, canceled":true,
"No editable content: execCommand() must not throw, uncanceled":true,
"Changing selection from handler: beforeinput event, canceled":true,
"Changing selection from handler: input event, canceled":true,
"Changing selection from handler: beforeinput event, uncanceled":true,

View File

@ -96,13 +96,8 @@ function runTests() {
"Command should not be enabled for non-privileged code");
is(SpecialPowers.wrap(document).queryCommandEnabled(commands[i]), true,
"Command should be enabled for privileged code");
try {
document.execCommand(commands[i], false, false);
ok(false, "Thould have thrown: " + commands[i]);
} catch (e) {
ok(/insecure|denied/.test(e), "Threw correctly: " + commands[i] + " - " + e);
}
SpecialPowers.wrap(document).execCommand(commands[i], false, false);
is(document.execCommand(commands[i], false, false), false, "Should return false: " + commands[i]);
is(SpecialPowers.wrap(document).execCommand(commands[i], false, false), true, "Should return true: " + commands[i]);
}
// delete/undo/redo -- we have to execute this commands because: