Editing tests should use testRunner instead of layoutTestController
[WebKit-https.git] / LayoutTests / editing / execCommand / script-tests / enabling-and-selection-2.js
1 description("This tests enabling of non-execCommand commands based on whether the selection is a caret or range or in editable content.");
2
3 var nonEditableParagraph = document.createElement("p");
4 nonEditableParagraph.appendChild(document.createTextNode("x"));
5 document.body.appendChild(nonEditableParagraph);
6
7 var editableParagraph = document.createElement("p");
8 editableParagraph.appendChild(document.createTextNode("x"));
9 editableParagraph.setAttribute("contentEditable", "true");
10 document.body.appendChild(editableParagraph);
11
12 var editablePlainTextParagraph = document.createElement("p");
13 editablePlainTextParagraph.appendChild(document.createTextNode("x"));
14 editablePlainTextParagraph.setAttribute("contentEditable", "plaintext-only");
15 document.body.appendChild(editablePlainTextParagraph);
16
17 function enabled(command, element, selectionStart, selectionEnd)
18 {
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);
26     }
27     var result = testRunner.isCommandEnabled(command);
28     selection.removeAllRanges();
29     return result;
30 }
31
32 function whenEnabled(command)
33 {
34     if (!window.testRunner)
35         return "no layout test controller";
36
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);
44
45     var summaryInteger = enabledWithNoSelection
46         | (enabledWithCaret << 1)
47         | (enabledWithEditableRange << 2)
48         | (enabledWithPlainTextCaret << 3)
49         | (enabledWithPlainTextEditableRange << 4)
50         | (enabledWithPoint << 5)
51         | (enabledWithNonEditableRange << 6);
52
53     if (summaryInteger === 0x7F)
54         return "always";
55
56     if (summaryInteger === 0x54)
57         return "range";
58
59     if (summaryInteger === 0x1E)
60         return "editable";
61     if (summaryInteger === 0x0A)
62         return "caret";
63     if (summaryInteger === 0x14)
64         return "editable range";
65
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";
72
73     if (summaryInteger === 0x5E)
74         return "visible";
75
76     return summaryInteger;
77 }
78
79 shouldBe("whenEnabled('Print')", "'always'");
80 shouldBe("whenEnabled('SelectAll')", "'always'");
81
82 shouldBe("whenEnabled('Transpose')", "'caret'");
83
84 shouldBe("whenEnabled('Copy')", "'range'");
85
86 shouldBe("whenEnabled('Cut')", "'editable range'");
87 shouldBe("whenEnabled('Delete')", "'editable range'");
88
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('MoveWordBackward')", "'editable'");
119 shouldBe("whenEnabled('MoveWordForward')", "'editable'");
120 shouldBe("whenEnabled('MoveWordLeft')", "'editable'");
121 shouldBe("whenEnabled('MoveWordRight')", "'editable'");
122 shouldBe("whenEnabled('Yank')", "'editable'");
123 shouldBe("whenEnabled('YankAndSelect')", "'editable'");
124
125 shouldBe("whenEnabled('AlignCenter')", "'richly editable'");
126 shouldBe("whenEnabled('AlignJustified')", "'richly editable'");
127 shouldBe("whenEnabled('AlignLeft')", "'richly editable'");
128 shouldBe("whenEnabled('AlignRight')", "'richly editable'");
129 shouldBe("whenEnabled('Indent')", "'richly editable'");
130 shouldBe("whenEnabled('MakeTextWritingDirectionLeftToRight')", "'richly editable'");
131 shouldBe("whenEnabled('MakeTextWritingDirectionNatural')", "'richly editable'");
132 shouldBe("whenEnabled('MakeTextWritingDirectionRightToLeft')", "'richly editable'");
133 shouldBe("whenEnabled('Outdent')", "'richly editable'");
134 shouldBe("whenEnabled('Subscript')", "'richly editable'");
135 shouldBe("whenEnabled('Superscript')", "'richly editable'");
136 shouldBe("whenEnabled('Underline')", "'richly editable'");
137 shouldBe("whenEnabled('Unscript')", "'richly editable'");
138
139 shouldBe("whenEnabled('Paste')", "'editable'");
140
141 shouldBe("whenEnabled('MoveBackwardAndModifySelection')", "'visible'");
142 shouldBe("whenEnabled('MoveDownAndModifySelection')", "'visible'");
143 shouldBe("whenEnabled('MoveForwardAndModifySelection')", "'visible'");
144 shouldBe("whenEnabled('MoveLeftAndModifySelection')", "'visible'");
145 shouldBe("whenEnabled('MoveParagraphBackwardAndModifySelection')", "'visible'");
146 shouldBe("whenEnabled('MoveParagraphForwardAndModifySelection')", "'visible'");
147 shouldBe("whenEnabled('MoveRightAndModifySelection')", "'visible'");
148 shouldBe("whenEnabled('MoveToBeginningOfDocumentAndModifySelection')", "'visible'");
149 shouldBe("whenEnabled('MoveToBeginningOfLineAndModifySelection')", "'visible'");
150 shouldBe("whenEnabled('MoveToBeginningOfParagraphAndModifySelection')", "'visible'");
151 shouldBe("whenEnabled('MoveToBeginningOfSentenceAndModifySelection')", "'visible'");
152 shouldBe("whenEnabled('MoveToEndOfDocumentAndModifySelection')", "'visible'");
153 shouldBe("whenEnabled('MoveToEndOfLineAndModifySelection')", "'visible'");
154 shouldBe("whenEnabled('MoveToEndOfParagraphAndModifySelection')", "'visible'");
155 shouldBe("whenEnabled('MoveToEndOfSentenceAndModifySelection')", "'visible'");
156 shouldBe("whenEnabled('MoveUpAndModifySelection')", "'visible'");
157 shouldBe("whenEnabled('MoveWordBackwardAndModifySelection')", "'visible'");
158 shouldBe("whenEnabled('MoveWordForwardAndModifySelection')", "'visible'");
159 shouldBe("whenEnabled('MoveWordLeftAndModifySelection')", "'visible'");
160 shouldBe("whenEnabled('MoveWordRightAndModifySelection')", "'visible'");
161 shouldBe("whenEnabled('SelectLine')", "'visible'");
162 shouldBe("whenEnabled('SelectParagraph')", "'visible'");
163 shouldBe("whenEnabled('SelectSentence')", "'visible'");
164 shouldBe("whenEnabled('SelectWord')", "'visible'");
165 shouldBe("whenEnabled('SetMark')", "'visible'");
166
167 document.body.removeChild(nonEditableParagraph);
168 document.body.removeChild(editableParagraph);
169 document.body.removeChild(editablePlainTextParagraph);
170
171 var successfullyParsed = true;