Bug 1338328 - Change error type for custom-clipdata mime type, and add test for correct exception type, r=baku

MozReview-Commit-ID: 9qwwXxWgWrO
This commit is contained in:
Michael Layzell 2017-03-01 15:15:36 -05:00
Родитель a54cbcb40f
Коммит 2f4b475ed1
2 изменённых файлов: 34 добавлений и 2 удалений

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

@ -681,7 +681,7 @@ DataTransfer::SetDataAtInternal(const nsAString& aFormat, nsIVariant* aData,
// Don't allow the custom type to be assigned.
if (aFormat.EqualsLiteral(kCustomTypesMime)) {
return NS_ERROR_TYPE_ERR;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
if (!PrincipalMaySetData(aFormat, aData, aSubjectPrincipal)) {

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

@ -54,7 +54,8 @@ var testFunctions = [
test_input_paste_abort_dataTransfer,
test_input_copypaste_dataTransfer_multiple,
test_input_copy_button_dataTransfer,
test_eventspref_disabled
test_eventspref_disabled,
test_input_cut_disallowed_types_dataTransfer,
];
function doTests()
@ -676,6 +677,37 @@ function checkCachedDataTransfer(cd, eventtype)
is(getClipboardText(), "Some Clipboard Text", "clipboard not changed using " + testprefix);
}
function test_input_cut_disallowed_types_dataTransfer() {
selectContentInput();
let oncutExecuted = false;
contentInput.oncut = function(event) {
// Setting an arbitrary type should be OK
try {
event.clipboardData.setData("apple/cider", "Anything your heart desires");
ok(true, "We should have successfully executed the setData call");
} catch(e) {
ok(false, "We should not have gotten an exception for trying to set that data");
}
// Unless that type happens to be application/x-moz-custom-clipdata
try {
event.clipboardData.setData("application/x-moz-custom-clipdata", "Anything your heart desires");
ok(false, "We should not have successfully executed the setData call");
} catch(e) {
is(e.name, "NotSupportedError",
"We should have gotten an NotSupportedError exception for trying to set that data");
}
oncutExecuted = true;
};
try {
synthesizeKey("x", {accelKey: 1});
ok(oncutExecuted, "The oncut handler should have been executed");
} finally {
contentInput.oncut = null;
}
}
SimpleTest.waitForFocus(doTests);
</script>