Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / execCommand / script-tests / enabling-and-selection-2.js
blobb27deb810650072fa5c7545b9d8c7ad6b29135a4
1 description("This tests enabling of non-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 = testRunner.isCommandEnabled(command);
28 selection.removeAllRanges();
29 return result;
32 function whenEnabled(command)
34 if (!window.testRunner)
35 return "no layout test controller";
37 var enabledWithNoSelection = enabled(command);
38 var enabledWithCaret = enabled(command, editableParagraph, 0, 0);
39 var enabledWithEditableRange = enabled(command, editableParagraph, 0, 1);
40 var enabledWithPlainTextCaret = enabled(command, editablePlainTextParagraph, 0, 0);
41 var enabledWithPlainTextEditableRange = enabled(command, editablePlainTextParagraph, 0, 1);
42 var enabledWithPoint = enabled(command, nonEditableParagraph, 0, 0);
43 var enabledWithNonEditableRange = enabled(command, nonEditableParagraph, 0, 1);
45 var summaryInteger = enabledWithNoSelection
46 | (enabledWithCaret << 1)
47 | (enabledWithEditableRange << 2)
48 | (enabledWithPlainTextCaret << 3)
49 | (enabledWithPlainTextEditableRange << 4)
50 | (enabledWithPoint << 5)
51 | (enabledWithNonEditableRange << 6);
53 if (summaryInteger === 0x7F)
54 return "always";
56 if (summaryInteger === 0x54)
57 return "range";
59 if (summaryInteger === 0x1E)
60 return "editable";
61 if (summaryInteger === 0x0A)
62 return "caret";
63 if (summaryInteger === 0x14)
64 return "editable range";
66 if (summaryInteger === 0x06)
67 return "richly editable";
68 if (summaryInteger === 0x02)
69 return "richly editable caret";
70 if (summaryInteger === 0x04)
71 return "richly editable range";
73 if (summaryInteger === 0x5E)
74 return "visible";
76 return summaryInteger;
79 shouldBe("whenEnabled('Print')", "'always'");
80 shouldBe("whenEnabled('SelectAll')", "'always'");
82 shouldBe("whenEnabled('Transpose')", "'caret'");
84 shouldBe("whenEnabled('Copy')", "'range'");
86 shouldBe("whenEnabled('Cut')", "'editable range'");
87 shouldBe("whenEnabled('Delete')", "'editable range'");
89 shouldBe("whenEnabled('DeleteBackward')", "'editable'");
90 shouldBe("whenEnabled('DeleteBackwardByDecomposingPreviousCharacter')", "'editable'");
91 shouldBe("whenEnabled('DeleteForward')", "'editable'");
92 shouldBe("whenEnabled('DeleteToBeginningOfLine')", "'editable'");
93 shouldBe("whenEnabled('DeleteToBeginningOfParagraph')", "'editable'");
94 shouldBe("whenEnabled('DeleteToEndOfLine')", "'editable'");
95 shouldBe("whenEnabled('DeleteToEndOfParagraph')", "'editable'");
96 shouldBe("whenEnabled('DeleteToMark')", "'editable'");
97 shouldBe("whenEnabled('DeleteWordBackward')", "'editable'");
98 shouldBe("whenEnabled('DeleteWordForward')", "'editable'");
99 shouldBe("whenEnabled('IgnoreSpelling')", "'editable'");
100 shouldBe("whenEnabled('InsertBacktab')", "'editable'");
101 shouldBe("whenEnabled('InsertLineBreak')", "'editable'");
102 shouldBe("whenEnabled('InsertNewline')", "'editable'");
103 shouldBe("whenEnabled('InsertTab')", "'editable'");
104 shouldBe("whenEnabled('MoveBackward')", "'editable'");
105 shouldBe("whenEnabled('MoveDown')", "'editable'");
106 shouldBe("whenEnabled('MoveForward')", "'editable'");
107 shouldBe("whenEnabled('MoveLeft')", "'editable'");
108 shouldBe("whenEnabled('MoveRight')", "'editable'");
109 shouldBe("whenEnabled('MoveToBeginningOfDocument')", "'editable'");
110 shouldBe("whenEnabled('MoveToBeginningOfLine')", "'editable'");
111 shouldBe("whenEnabled('MoveToBeginningOfParagraph')", "'editable'");
112 shouldBe("whenEnabled('MoveToBeginningOfSentence')", "'editable'");
113 shouldBe("whenEnabled('MoveToEndOfDocument')", "'editable'");
114 shouldBe("whenEnabled('MoveToEndOfLine')", "'editable'");
115 shouldBe("whenEnabled('MoveToEndOfParagraph')", "'editable'");
116 shouldBe("whenEnabled('MoveToEndOfSentence')", "'editable'");
117 shouldBe("whenEnabled('MoveUp')", "'editable'");
118 shouldBe("whenEnabled('MoveParagraphBackward')", "'editable'");
119 shouldBe("whenEnabled('MoveParagraphForward')", "'editable'");
120 shouldBe("whenEnabled('MoveWordBackward')", "'editable'");
121 shouldBe("whenEnabled('MoveWordForward')", "'editable'");
122 shouldBe("whenEnabled('MoveWordLeft')", "'editable'");
123 shouldBe("whenEnabled('MoveWordRight')", "'editable'");
124 shouldBe("whenEnabled('Yank')", "'editable'");
125 shouldBe("whenEnabled('YankAndSelect')", "'editable'");
127 shouldBe("whenEnabled('AlignCenter')", "'richly editable'");
128 shouldBe("whenEnabled('AlignJustified')", "'richly editable'");
129 shouldBe("whenEnabled('AlignLeft')", "'richly editable'");
130 shouldBe("whenEnabled('AlignRight')", "'richly editable'");
131 shouldBe("whenEnabled('Indent')", "'richly editable'");
132 shouldBe("whenEnabled('MakeTextWritingDirectionLeftToRight')", "'richly editable'");
133 shouldBe("whenEnabled('MakeTextWritingDirectionNatural')", "'richly editable'");
134 shouldBe("whenEnabled('MakeTextWritingDirectionRightToLeft')", "'richly editable'");
135 shouldBe("whenEnabled('Outdent')", "'richly editable'");
136 shouldBe("whenEnabled('Subscript')", "'richly editable'");
137 shouldBe("whenEnabled('Superscript')", "'richly editable'");
138 shouldBe("whenEnabled('Underline')", "'richly editable'");
139 shouldBe("whenEnabled('Unscript')", "'richly editable'");
141 shouldBe("whenEnabled('Paste')", "'editable'");
143 shouldBe("whenEnabled('MoveBackwardAndModifySelection')", "'visible'");
144 shouldBe("whenEnabled('MoveDownAndModifySelection')", "'visible'");
145 shouldBe("whenEnabled('MoveForwardAndModifySelection')", "'visible'");
146 shouldBe("whenEnabled('MoveLeftAndModifySelection')", "'visible'");
147 shouldBe("whenEnabled('MoveParagraphBackwardAndModifySelection')", "'visible'");
148 shouldBe("whenEnabled('MoveParagraphForwardAndModifySelection')", "'visible'");
149 shouldBe("whenEnabled('MoveRightAndModifySelection')", "'visible'");
150 shouldBe("whenEnabled('MoveToBeginningOfDocumentAndModifySelection')", "'visible'");
151 shouldBe("whenEnabled('MoveToBeginningOfLineAndModifySelection')", "'visible'");
152 shouldBe("whenEnabled('MoveToBeginningOfParagraphAndModifySelection')", "'visible'");
153 shouldBe("whenEnabled('MoveToBeginningOfSentenceAndModifySelection')", "'visible'");
154 shouldBe("whenEnabled('MoveToEndOfDocumentAndModifySelection')", "'visible'");
155 shouldBe("whenEnabled('MoveToEndOfLineAndModifySelection')", "'visible'");
156 shouldBe("whenEnabled('MoveToEndOfParagraphAndModifySelection')", "'visible'");
157 shouldBe("whenEnabled('MoveToEndOfSentenceAndModifySelection')", "'visible'");
158 shouldBe("whenEnabled('MoveUpAndModifySelection')", "'visible'");
159 shouldBe("whenEnabled('MoveWordBackwardAndModifySelection')", "'visible'");
160 shouldBe("whenEnabled('MoveWordForwardAndModifySelection')", "'visible'");
161 shouldBe("whenEnabled('MoveWordLeftAndModifySelection')", "'visible'");
162 shouldBe("whenEnabled('MoveWordRightAndModifySelection')", "'visible'");
163 shouldBe("whenEnabled('SelectLine')", "'visible'");
164 shouldBe("whenEnabled('SelectParagraph')", "'visible'");
165 shouldBe("whenEnabled('SelectSentence')", "'visible'");
166 shouldBe("whenEnabled('SelectWord')", "'visible'");
167 shouldBe("whenEnabled('SetMark')", "'visible'");
169 shouldBe("whenEnabled('OverWrite')", "'richly editable'");
171 document.body.removeChild(nonEditableParagraph);
172 document.body.removeChild(editableParagraph);
173 document.body.removeChild(editablePlainTextParagraph);
175 var successfullyParsed = true;