blob: 24cf865258142f8c680a53b95759ae7da3940625 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- webkit-test-runner [ JavaScriptCanAccessClipboard=false ] -->
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This test checks whether javascript programs can access clipboard.");
var nonEditableParagraph = document.createElement("p");
nonEditableParagraph.appendChild(document.createTextNode("x"));
document.body.appendChild(nonEditableParagraph);
var editableParagraph = document.createElement("p");
editableParagraph.appendChild(document.createTextNode("x"));
editableParagraph.setAttribute("contentEditable", "true");
document.body.appendChild(editableParagraph);
var editablePlainTextParagraph = document.createElement("p");
editablePlainTextParagraph.appendChild(document.createTextNode("x"));
editablePlainTextParagraph.setAttribute("contentEditable", "plaintext-only");
document.body.appendChild(editablePlainTextParagraph);
function enabled(command, element, selectionStart, selectionEnd)
{
var selection = document.getSelection();
selection.removeAllRanges();
if (element) {
var range = document.createRange();
range.setStart(element.firstChild, selectionStart);
range.setEnd(element.firstChild, selectionEnd);
selection.addRange(range);
}
var result = document.queryCommandEnabled(command)
selection.removeAllRanges();
return result;
}
function whenEnabled(command)
{
var enabledWithNoSelection = enabled(command);
var enabledWithCaret = enabled(command, editableParagraph, 0, 0);
var enabledWithEditableRange = enabled(command, editableParagraph, 0, 1);
var enabledWithPlainTextCaret = enabled(command, editablePlainTextParagraph, 0, 0);
var enabledWithPlainTextEditableRange = enabled(command, editablePlainTextParagraph, 0, 1);
var enabledWithPoint = enabled(command, nonEditableParagraph, 0, 0);
var enabledWithNonEditableRange = enabled(command, nonEditableParagraph, 0, 1);
var summaryInteger = enabledWithNoSelection
| (enabledWithCaret << 1)
| (enabledWithEditableRange << 2)
| (enabledWithPlainTextCaret << 3)
| (enabledWithPlainTextEditableRange << 4)
| (enabledWithPoint << 5)
| (enabledWithNonEditableRange << 6);
if (summaryInteger === 0x7F)
return "always";
if (summaryInteger === 0x54)
return "range";
if (summaryInteger === 0x1E)
return "editable";
if (summaryInteger === 0x0A)
return "caret";
if (summaryInteger === 0x14)
return "editable range";
if (summaryInteger === 0x06)
return "richly editable";
if (summaryInteger === 0x02)
return "richly editable caret";
if (summaryInteger === 0x04)
return "richly editable range";
if (summaryInteger === 0x5E)
return "visible";
return summaryInteger;
}
shouldBe("whenEnabled('Copy')", "0");
shouldBe("whenEnabled('Cut')", "0");
shouldBe("whenEnabled('Paste')", "0");
shouldBe("whenEnabled('PasteAndMatchStyle')", "0");
document.body.removeChild(nonEditableParagraph);
document.body.removeChild(editableParagraph);
document.body.removeChild(editablePlainTextParagraph);
var successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>