Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_cut_copy_delete_command_enabled.html
blob9e70178b11fd06699b160112738bbe6f9e2be7f5
1 <!DOCTYPE HTML>
2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
3 - License, v. 2.0. If a copy of the MPL was not distributed with this
4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5 <html>
6 <!--
7 https://bugzilla.mozilla.org/show_bug.cgi?id=1067255
8 -->
10 <head>
11 <title>Test for enabled state of cut/copy/delete commands</title>
12 <script src="/tests/SimpleTest/SimpleTest.js"></script>
13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
14 <script src="/tests/SimpleTest/EventUtils.js"></script>
15 </head>
17 <body onload="doTest();">
18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1067255">Mozilla Bug 1067255</a>
20 <pre id="test">
21 <script type="application/javascript">
22 /** Test for Bug 1067255 **/
23 SimpleTest.waitForExplicitFinish();
25 function doTest() {
26 var text = $("text-field");
27 var textWithHandlers = $("text-field-2");
28 var password = $("password-field");
29 var passwordWithHandlers = $("password-field-2");
30 var textWithParentHandlers = $("text-field-3");
31 var passwordWithParentHandlers = $("password-field-3");
32 var textarea1 = $("text-area-1");
33 var textarea2 = $("text-area-2");
34 var textarea3 = $("text-area-3");
36 var editor1 = SpecialPowers.wrap(text).editor;
37 var editor2 = SpecialPowers.wrap(password).editor;
38 var editor3 = SpecialPowers.wrap(textWithHandlers).editor;
39 var editor4 = SpecialPowers.wrap(passwordWithHandlers).editor;
40 var editor5 = SpecialPowers.wrap(textWithParentHandlers).editor;
41 var editor6 = SpecialPowers.wrap(passwordWithParentHandlers).editor;
42 var editor7 = SpecialPowers.wrap(textarea1).editor;
43 var editor8 = SpecialPowers.wrap(textarea2).editor;
44 var editor9 = SpecialPowers.wrap(textarea3).editor;
46 text.focus();
48 ok(!editor1.canCopy(),
49 "nsIEditor.canCopy() should return false in <input type=text> with no selection");
50 ok(!editor1.canCut(),
51 "nsIEditor.canCut() should return false in <input type=text> with no selection");
52 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
53 "cmd_copy command should be disabled in <input type=text> with no selection");
54 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
55 "cmd_cut command should be disabled in <input type=text> with no selection");
56 ok(!SpecialPowers.isCommandEnabled(window, "cmd_delete"),
57 "cmd_delete command should be disabled in <input type=text> with no selection");
59 text.select();
61 ok(editor1.canCopy(),
62 "nsIEditor.canCopy() should return true in <input type=text> with selection");
63 ok(editor1.canCut(),
64 "nsIEditor.canCut() should return true in <input type=text> with selection");
65 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
66 "cmd_copy command should be enabled in <input type=text> with selection");
67 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
68 "cmd_cut command should be enabled in <input type=text> with selection");
69 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
70 "cmd_delete command should be enabled in <input type=text> with selection");
72 password.focus();
74 ok(!editor2.canCopy(),
75 "nsIEditor.canCopy() should return false in <input type=password> with no selection");
76 ok(!editor2.canCut(),
77 "nsIEditor.canCut() should return false in <input type=password> with no selection");
78 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
79 "cmd_copy command should be disabled in <input type=password> with no selection");
80 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
81 "cmd_cut command should be disabled in <input type=password> with no selection");
82 ok(!SpecialPowers.isCommandEnabled(window, "cmd_delete"),
83 "cmd_delete command should be disabled in <input type=password> with no selection");
85 // Copy and cut commands don't do anything on password fields by default,
86 // so they remain disabled even when there is a selection...
87 password.select();
89 ok(!editor2.canCopy(),
90 "nsIEditor.canCopy() should return false in <input type=password> with selection");
91 ok(!editor2.canCut(),
92 "nsIEditor.canCut() should return false in <input type=password> with selection");
93 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
94 "cmd_copy command should be disabled in <input type=password> with selection");
95 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
96 "cmd_cut command should be disabled in <input type=password> with selection");
97 // Delete, on the other hand, does apply to password fields.
98 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
99 "cmd_delete command should be enabled in <input type=password with selection>");
101 // ...but webpages can hook up event handlers to cut/copy events, so we have to
102 // keep the cut and copy commands enabled if event handlers are attached,
103 // for both regular edit fields and password fields (even when there's no
104 // selection, as we don't know what the handler might want to do).
105 textWithHandlers.focus();
107 ok(editor3.canCopy(),
108 "nsIEditor.canCopy() should return true in <input type=text> with event handler");
109 ok(editor3.canCut(),
110 "nsIEditor.canCut() should return true in <input type=text> with event handler");
111 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
112 "cmd_copy command should be enabled in <input type=text> with event handler");
113 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
114 "cmd_cut command should be enabled in <input type=text> with event handler");
116 passwordWithHandlers.focus();
118 ok(editor4.canCopy(),
119 "nsIEditor.canCopy() should return true in <input type=password> with event handler");
120 ok(editor4.canCut(),
121 "nsIEditor.canCut() should return true in <input type=password> with event handler");
122 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
123 "cmd_copy command should be enabled in <input type=password> with event handler");
124 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
125 "cmd_cut command should be enabled in <input type=password> with event handler");
127 // Also check that the commands are enabled if there's a handler on a parent element.
128 textWithParentHandlers.focus();
130 ok(editor5.canCopy(),
131 "nsIEditor.canCopy() should return true in <input type=text> with event handler on an ancestor");
132 ok(editor5.canCut(),
133 "nsIEditor.canCut() should return true in <input type=text> with event handler on an ancestor");
134 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
135 "cmd_copy command should be enabled in <input type=text> with event handler on an ancestor");
136 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
137 "cmd_cut command should be enabled in <input type=text> with event handler on an ancestor");
139 passwordWithParentHandlers.focus();
141 ok(editor6.canCopy(),
142 "nsIEditor.canCopy() should return true in <input type=password> with event handler on an ancestor");
143 ok(editor6.canCut(),
144 "nsIEditor.canCut() should return true in <input type=password> with event handler on an ancestor");
145 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
146 "cmd_copy command should be enabled in <input type=password> with event handler on an ancestor");
147 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
148 "cmd_cut command should be enabled in <input type=password> with event handler on an ancestor");
150 // TEXTAREA tests
152 textarea1.focus();
154 ok(!editor7.canCopy(),
155 "nsIEditor.canCopy() should return false in <textarea> with no selection");
156 ok(!editor7.canCut(),
157 "nsIEditor.canCut() should return false in <textarea> with no selection");
158 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
159 "cmd_copy command should be disabled in <textarea> with no selection");
160 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
161 "cmd_cut command should be disabled in <textarea> with no selection");
162 ok(!SpecialPowers.isCommandEnabled(window, "cmd_delete"),
163 "cmd_delete command should be disabled in <textarea> with no selection");
165 textarea1.select();
167 ok(editor7.canCopy(),
168 "nsIEditor.canCopy() should return true in <textarea> with selection");
169 ok(editor7.canCut(),
170 "nsIEditor.canCut() should return true in <textarea> with selection");
171 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
172 "cmd_copy command should be enabled in <textarea> with selection");
173 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
174 "cmd_cut command should be enabled in <textarea> with selection");
175 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
176 "cmd_delete command should be enabled in <textarea> with selection");
178 textarea2.focus();
180 ok(!editor8.canCopy(),
181 "nsIEditor.canCopy() should return false in <textarea> with only a 'cut' handler");
182 ok(editor8.canCut(),
183 "nsIEditor.canCut() should return true in <textarea> with only a 'cut' handler");
184 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
185 "cmd_copy command should be disabled in <textarea> with only a 'cut' handler");
186 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
187 "cmd_cut command should be enabled in <textarea> with only a 'cut' handler");
188 ok(!SpecialPowers.isCommandEnabled(window, "cmd_delete"),
189 "cmd_delete command should be disabled in <textarea> with only a 'cut' handler");
191 textarea3.focus();
193 ok(editor9.canCopy(),
194 "nsIEditor.canCopy() should return true in <textarea> with only a 'copy' handler on ancestor");
195 ok(!editor9.canCut(),
196 "nsIEditor.canCut() should return false in <textarea> with only a 'copy' handler on ancestor");
197 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
198 "cmd_copy command should be enabled in <textarea> with only a 'copy' handler on ancestor");
199 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
200 "cmd_cut command should be disabled in <textarea> with only a 'copy' handler on ancestor");
201 ok(!SpecialPowers.isCommandEnabled(window, "cmd_delete"),
202 "cmd_delete command should be disabled in <textarea> with only a 'copy' handler on ancestor");
204 SimpleTest.finish();
206 </script>
207 </pre>
209 <input type="text" value="Gonzo says hi" id="text-field" />
210 <input type="password" value="Jan also" id="password-field" />
211 <input type="text" value="Hi says Gonzo" id="text-field-2" oncut="cut()" oncopy="copy()" ondelete="delete()"/>
212 <input type="password" value="Also Jan" id="password-field-2" oncut="cut()" oncopy="copy()" ondelete="delete()"/>
213 <div oncut="cut()">
214 <ul oncopy="copy()">
215 <li><input type="text" value="Hi again" id="text-field-3"/></li>
216 <li><input type="password" value="And again, hi" id="password-field-3"/></li>
217 </ul>
218 </div>
219 <textarea id="text-area-1">textarea</textarea>
220 <textarea oncut="cut()" id="text-area-2">textarea with cut handler</textarea>
221 <div oncopy="copy()">
222 <blockquote>
223 <p><textarea id="text-area-3">textarea with copy handler on parent</textarea></p>
224 </blockquote>
225 </div>
226 </body>
227 </html>