1 description("This test checks whether javascript programs can access clipboard.");
5 window
.testRunner
.setJavaScriptCanAccessClipboard(false);
8 var nonEditableParagraph
= document
.createElement("p");
9 nonEditableParagraph
.appendChild(document
.createTextNode("x"));
10 document
.body
.appendChild(nonEditableParagraph
);
12 var editableParagraph
= document
.createElement("p");
13 editableParagraph
.appendChild(document
.createTextNode("x"));
14 editableParagraph
.setAttribute("contentEditable", "true");
15 document
.body
.appendChild(editableParagraph
);
17 var editablePlainTextParagraph
= document
.createElement("p");
18 editablePlainTextParagraph
.appendChild(document
.createTextNode("x"));
19 editablePlainTextParagraph
.setAttribute("contentEditable", "plaintext-only");
20 document
.body
.appendChild(editablePlainTextParagraph
);
22 function enabled(command
, element
, selectionStart
, selectionEnd
)
24 var selection
= document
.getSelection();
25 selection
.removeAllRanges();
27 var range
= document
.createRange();
28 range
.setStart(element
.firstChild
, selectionStart
);
29 range
.setEnd(element
.firstChild
, selectionEnd
);
30 selection
.addRange(range
);
32 var result
= document
.queryCommandEnabled(command
)
33 selection
.removeAllRanges();
37 function whenEnabled(command
)
39 var enabledWithNoSelection
= enabled(command
);
40 var enabledWithCaret
= enabled(command
, editableParagraph
, 0, 0);
41 var enabledWithEditableRange
= enabled(command
, editableParagraph
, 0, 1);
42 var enabledWithPlainTextCaret
= enabled(command
, editablePlainTextParagraph
, 0, 0);
43 var enabledWithPlainTextEditableRange
= enabled(command
, editablePlainTextParagraph
, 0, 1);
44 var enabledWithPoint
= enabled(command
, nonEditableParagraph
, 0, 0);
45 var enabledWithNonEditableRange
= enabled(command
, nonEditableParagraph
, 0, 1);
47 var summaryInteger
= enabledWithNoSelection
48 | (enabledWithCaret
<< 1)
49 | (enabledWithEditableRange
<< 2)
50 | (enabledWithPlainTextCaret
<< 3)
51 | (enabledWithPlainTextEditableRange
<< 4)
52 | (enabledWithPoint
<< 5)
53 | (enabledWithNonEditableRange
<< 6);
55 if (summaryInteger
=== 0x7F)
58 if (summaryInteger
=== 0x54)
61 if (summaryInteger
=== 0x1E)
63 if (summaryInteger
=== 0x0A)
65 if (summaryInteger
=== 0x14)
66 return "editable range";
68 if (summaryInteger
=== 0x06)
69 return "richly editable";
70 if (summaryInteger
=== 0x02)
71 return "richly editable caret";
72 if (summaryInteger
=== 0x04)
73 return "richly editable range";
75 if (summaryInteger
=== 0x5E)
78 return summaryInteger
;
81 shouldBe("whenEnabled('Copy')", "0");
82 shouldBe("whenEnabled('Cut')", "0");
83 shouldBe("whenEnabled('Paste')", "0");
84 shouldBe("whenEnabled('PasteAndMatchStyle')", "0");
86 document
.body
.removeChild(nonEditableParagraph
);
87 document
.body
.removeChild(editableParagraph
);
88 document
.body
.removeChild(editablePlainTextParagraph
);
90 var successfullyParsed
= true;