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.xhtml
blob46c91e87d0d365bba32798706f880f7fdf3a4526
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
5 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
6 title="Test for enabled state of cut/copy/delete commands">
7 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="application/javascript">
11 <![CDATA[
12 SimpleTest.waitForExplicitFinish();
13 SimpleTest.waitForFocus(() => {
14 let text = document.getElementById("textbox");
15 let password = document.getElementById("password");
17 let editor1 = text.editor;
18 let editor2 = password.editor;
20 text.focus();
21 text.select();
23 ok(editor1.canCopy(),
24 "nsIEditor.canCopy() should return true in <input>");
25 ok(editor1.canCut(),
26 "nsIEditor.canCut() should return true in <input>");
27 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
28 "cmd_copy command should be enabled in <input>");
29 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
30 "cmd_cut command should be enabled in <input>");
31 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
32 "cmd_delete command should be enabled in <input>");
34 password.focus();
35 password.select();
37 // Copy and cut commands should be disabled on password fields.
38 ok(!editor2.canCopy(),
39 "nsIEditor.canCopy() should return false in <input type=password>");
40 ok(!editor2.canCut(),
41 "nsIEditor.canCut() should return false in <input type=password>");
42 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
43 "cmd_copy command should be disabled in <input type=password>");
44 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
45 "cmd_cut command should be disabled in <input type=password>");
46 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
47 "cmd_delete command should be enabled in <input type=password>");
49 // If selection is in unmasked range, allow to copy the selected
50 // password into the clipboard.
51 editor2.unmask(0);
52 ok(editor2.canCopy(),
53 "nsIEditor.canCopy() should return true in <input type=password> if the password is unmasked");
54 ok(editor2.canCut(),
55 "nsIEditor.canCut() should return true in <input type=password> if the password is unmasked");
56 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
57 "cmd_copy command should be enabled in <input type=password> if the password is unmasked");
58 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
59 "cmd_cut command should be enabled in <input type=password> if the password is unmasked");
60 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
61 "cmd_delete command should be enabled in <input type=password> if the password is unmasked");
63 // If unmasked range will be masked automatically, we shouldn't allow to
64 // copy the selected password since the state may be changed during
65 // showing edit menu or something.
66 editor2.unmask(0, 13, 1000);
67 ok(!editor2.canCopy(),
68 "nsIEditor.canCopy() should return false in <input type=password> if the password is unmasked but will be masked automatically");
69 ok(!editor2.canCut(),
70 "nsIEditor.canCut() should return false in <input type=password> if the password is unmasked but will be masked automatically");
71 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
72 "cmd_copy command should be disabled in <input type=password> if the password is unmasked but will be masked automatically");
73 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
74 "cmd_cut command should be disabled in <input type=password> if the password is unmasked but will be masked automatically");
75 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
76 "cmd_delete command should be enabled in <input type=password> if the password is unmasked but will be masked automatically");
78 // <input type="password"> does not support setSelectionRange() oddly.
79 function setSelectionRange(aEditor, aStart, aEnd) {
80 let container = aEditor.rootElement.firstChild;
81 aEditor.selection.setBaseAndExtent(container, aStart, container, aEnd);
84 // Check the range boundaries.
85 editor2.unmask(3, 9);
86 setSelectionRange(editor2, 0, 2);
87 ok(!editor2.canCopy(),
88 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 0-2)");
89 ok(!editor2.canCut(),
90 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 0-2)");
91 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
92 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 0-2)");
93 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
94 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 0-2)");
95 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
96 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 0-2)");
98 setSelectionRange(editor2, 2, 3);
99 ok(!editor2.canCopy(),
100 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 2-3)");
101 ok(!editor2.canCut(),
102 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 2-3)");
103 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
104 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-3)");
105 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
106 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-3)");
107 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
108 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 2-3)");
110 setSelectionRange(editor2, 2, 5);
111 ok(!editor2.canCopy(),
112 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 2-5)");
113 ok(!editor2.canCut(),
114 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 2-5)");
115 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
116 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-5)");
117 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
118 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-5)");
119 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
120 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 2-5)");
122 setSelectionRange(editor2, 2, 10);
123 ok(!editor2.canCopy(),
124 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 2-10)");
125 ok(!editor2.canCut(),
126 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 2-10)");
127 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
128 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-10)");
129 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
130 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 2-10)");
131 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
132 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 2-10)");
134 setSelectionRange(editor2, 2, 10);
135 ok(!editor2.canCopy(),
136 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 3-10)");
137 ok(!editor2.canCut(),
138 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 3-10)");
139 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
140 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 3-10)");
141 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
142 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 3-10)");
143 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
144 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 3-10)");
146 setSelectionRange(editor2, 8, 12);
147 ok(!editor2.canCopy(),
148 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 8-12)");
149 ok(!editor2.canCut(),
150 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 8-12)");
151 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
152 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 8-12)");
153 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
154 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 8-12)");
155 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
156 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 8-12)");
158 setSelectionRange(editor2, 9, 12);
159 ok(!editor2.canCopy(),
160 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 9-12)");
161 ok(!editor2.canCut(),
162 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 9-12)");
163 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
164 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 9-12)");
165 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
166 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 9-12)");
167 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
168 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 9-12)");
170 setSelectionRange(editor2, 10, 12);
171 ok(!editor2.canCopy(),
172 "nsIEditor.canCopy() should return false in <input type=password> (unmasked range 3-9, selected range 10-12)");
173 ok(!editor2.canCut(),
174 "nsIEditor.canCut() should return false in <input type=password> (unmasked range 3-9, selected range 10-12)");
175 ok(!SpecialPowers.isCommandEnabled(window, "cmd_copy"),
176 "cmd_copy command should be disabled in <input type=password> (unmasked range 3-9, selected range 10-12)");
177 ok(!SpecialPowers.isCommandEnabled(window, "cmd_cut"),
178 "cmd_cut command should be disabled in <input type=password> (unmasked range 3-9, selected range 10-12)");
179 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
180 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 10-12)");
182 setSelectionRange(editor2, 3, 9);
183 ok(editor2.canCopy(),
184 "nsIEditor.canCopy() should return true in <input type=password> (unmasked range 3-9, selected range 3-9)");
185 ok(editor2.canCut(),
186 "nsIEditor.canCut() should return true in <input type=password> (unmasked range 3-9, selected range 3-9)");
187 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
188 "cmd_copy command should be enabled in <input type=password> (unmasked range 3-9, selected range 3-9)");
189 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
190 "cmd_cut command should be enabled in <input type=password> (unmasked range 3-9, selected range 3-9)");
191 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
192 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 3-9)");
194 setSelectionRange(editor2, 4, 8);
195 ok(editor2.canCopy(),
196 "nsIEditor.canCopy() should return true in <input type=password> (unmasked range 3-9, selected range 4-8)");
197 ok(editor2.canCut(),
198 "nsIEditor.canCut() should return true in <input type=password> (unmasked range 3-9, selected range 4-8)");
199 ok(SpecialPowers.isCommandEnabled(window, "cmd_copy"),
200 "cmd_copy command should be enabled in <input type=password> (unmasked range 3-9, selected range 4-8)");
201 ok(SpecialPowers.isCommandEnabled(window, "cmd_cut"),
202 "cmd_cut command should be enabled in <input type=password> (unmasked range 3-9, selected range 4-8)");
203 ok(SpecialPowers.isCommandEnabled(window, "cmd_delete"),
204 "cmd_delete command should be enabled in <input type=password> (unmasked range 3-9, selected range 4-8)");
206 SimpleTest.finish();
208 ]]></script>
210 <vbox flex="1">
211 <input xmlns="http://www.w3.org/1999/xhtml" id="textbox" value="normal text"/>
212 <input xmlns="http://www.w3.org/1999/xhtml" id="password" type="password" value="password text"/>
213 </vbox>
215 </window>