Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / execCommand / script-tests / enabling-and-selection.js
blob4b1c516ea1820cf78571f3862947af13fc4f9590
1 description("This tests enabling of execCommand commands based on whether the selection is a caret or range or in editable content.");
3 var nonEditableParagraph = document.createElement("p");
4 nonEditableParagraph.appendChild(document.createTextNode("x"));
5 document.body.appendChild(nonEditableParagraph);
7 var editableParagraph = document.createElement("p");
8 editableParagraph.appendChild(document.createTextNode("x"));
9 editableParagraph.setAttribute("contentEditable", "true");
10 document.body.appendChild(editableParagraph);
12 var editablePlainTextParagraph = document.createElement("p");
13 editablePlainTextParagraph.appendChild(document.createTextNode("x"));
14 editablePlainTextParagraph.setAttribute("contentEditable", "plaintext-only");
15 document.body.appendChild(editablePlainTextParagraph);
17 function enabled(command, element, selectionStart, selectionEnd)
19 var selection = document.getSelection();
20 selection.removeAllRanges();
21 if (element) {
22 var range = document.createRange();
23 range.setStart(element.firstChild, selectionStart);
24 range.setEnd(element.firstChild, selectionEnd);
25 selection.addRange(range);
27 var result = document.queryCommandEnabled(command)
28 selection.removeAllRanges();
29 return result;
32 function whenEnabled(command)
34 var enabledWithNoSelection = enabled(command);
35 var enabledWithCaret = enabled(command, editableParagraph, 0, 0);
36 var enabledWithEditableRange = enabled(command, editableParagraph, 0, 1);
37 var enabledWithPlainTextCaret = enabled(command, editablePlainTextParagraph, 0, 0);
38 var enabledWithPlainTextEditableRange = enabled(command, editablePlainTextParagraph, 0, 1);
39 var enabledWithPoint = enabled(command, nonEditableParagraph, 0, 0);
40 var enabledWithNonEditableRange = enabled(command, nonEditableParagraph, 0, 1);
42 var summaryInteger = enabledWithNoSelection
43 | (enabledWithCaret << 1)
44 | (enabledWithEditableRange << 2)
45 | (enabledWithPlainTextCaret << 3)
46 | (enabledWithPlainTextEditableRange << 4)
47 | (enabledWithPoint << 5)
48 | (enabledWithNonEditableRange << 6);
50 if (summaryInteger === 0x7F)
51 return "always";
53 if (summaryInteger === 0x54)
54 return "range";
56 if (summaryInteger === 0x1E)
57 return "editable";
58 if (summaryInteger === 0x0A)
59 return "caret";
60 if (summaryInteger === 0x14)
61 return "editable range";
63 if (summaryInteger === 0x06)
64 return "richly editable";
65 if (summaryInteger === 0x02)
66 return "richly editable caret";
67 if (summaryInteger === 0x04)
68 return "richly editable range";
70 if (summaryInteger === 0x5E)
71 return "visible";
73 return summaryInteger;
76 shouldBe("whenEnabled('FindString')", "'always'");
77 shouldBe("whenEnabled('Print')", "'always'");
78 shouldBe("whenEnabled('SelectAll')", "'always'");
80 shouldBe("whenEnabled('Transpose')", "'caret'");
82 shouldBe("whenEnabled('Copy')", "'range'");
84 shouldBe("whenEnabled('Cut')", "'editable range'");
85 shouldBe("whenEnabled('RemoveFormat')", "'editable range'");
87 shouldBe("whenEnabled('Delete')", "'editable'");
88 shouldBe("whenEnabled('FontName')", "'editable'");
89 shouldBe("whenEnabled('FontSize')", "'editable'");
90 shouldBe("whenEnabled('FontSizeDelta')", "'editable'");
91 shouldBe("whenEnabled('ForwardDelete')", "'editable'");
92 shouldBe("whenEnabled('InsertHTML')", "'editable'");
93 shouldBe("whenEnabled('InsertParagraph')", "'editable'");
94 shouldBe("whenEnabled('InsertText')", "'editable'");
96 shouldBe("whenEnabled('BackColor')", "'richly editable'");
97 shouldBe("whenEnabled('Bold')", "'richly editable'");
98 shouldBe("whenEnabled('CreateLink')", "'richly editable'");
99 shouldBe("whenEnabled('ForeColor')", "'richly editable'");
100 shouldBe("whenEnabled('FormatBlock')", "'richly editable'");
101 shouldBe("whenEnabled('HiliteColor')", "'richly editable'");
102 shouldBe("whenEnabled('Indent')", "'richly editable'");
103 shouldBe("whenEnabled('InsertHorizontalRule')", "'richly editable'");
104 shouldBe("whenEnabled('InsertImage')", "'richly editable'");
105 shouldBe("whenEnabled('InsertNewlineInQuotedContent')", "'richly editable'");
106 shouldBe("whenEnabled('InsertOrderedList')", "'richly editable'");
107 shouldBe("whenEnabled('InsertUnorderedList')", "'richly editable'");
108 shouldBe("whenEnabled('Italic')", "'richly editable'");
109 shouldBe("whenEnabled('JustifyCenter')", "'richly editable'");
110 shouldBe("whenEnabled('JustifyFull')", "'richly editable'");
111 shouldBe("whenEnabled('JustifyLeft')", "'richly editable'");
112 shouldBe("whenEnabled('JustifyNone')", "'richly editable'");
113 shouldBe("whenEnabled('JustifyRight')", "'richly editable'");
114 shouldBe("whenEnabled('Outdent')", "'richly editable'");
115 shouldBe("whenEnabled('Strikethrough')", "'richly editable'");
116 shouldBe("whenEnabled('Subscript')", "'richly editable'");
117 shouldBe("whenEnabled('Superscript')", "'richly editable'");
118 shouldBe("whenEnabled('Underline')", "'richly editable'");
120 shouldBe("whenEnabled('Paste')", "'editable'");
121 shouldBe("whenEnabled('PasteAndMatchStyle')", "'editable'");
123 shouldBe("whenEnabled('Unlink')", "'richly editable range'");
125 shouldBe("whenEnabled('Unselect')", "'visible'");
127 document.body.removeChild(nonEditableParagraph);
128 document.body.removeChild(editableParagraph);
129 document.body.removeChild(editablePlainTextParagraph);
131 var successfullyParsed = true;