5 <title>Testing
"cmd_backgroundColor" behavior
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
10 <div contenteditable
></div>
14 SimpleTest
.waitForExplicitFinish();
15 SimpleTest
.waitForFocus(() => {
16 document
.execCommand("styleWithCSS", false, "true");
17 const commandManager
=
18 SpecialPowers
.wrap(window
).
20 QueryInterface(SpecialPowers
.Ci
.nsIInterfaceRequestor
).
21 getInterface(SpecialPowers
.Ci
.nsICommandManager
);
22 const editor
= document
.querySelector("div[contenteditable]");
23 editor
.style
.backgroundColor
= "#ff0000";
25 editor
.innerHTML
= "<p>abc</p>";
26 editor
.getBoundingClientRect();
28 getSelection().collapse(editor
.querySelector("p").firstChild
, 1);
29 let params
= SpecialPowers
.Cu
.createCommandParams();
30 commandManager
.getCommandState("cmd_backgroundColor", window
, params
);
32 params
.getCStringValue("state_attribute"),
34 "cmd_backgroundColor should return the editing host's background color (should ignore the transparent paragraph)"
37 editor
.innerHTML
= "<p style=\"background-color: #00ff00\">abc</p>";
38 editor
.getBoundingClientRect();
40 getSelection().collapse(editor
.querySelector("p").firstChild
, 1);
41 params
= SpecialPowers
.Cu
.createCommandParams();
42 commandManager
.getCommandState("cmd_backgroundColor", window
, params
);
44 params
.getCStringValue("state_attribute"),
46 "cmd_backgroundColor should return the paragraph's background color"
49 editor
.innerHTML
= "<span style=\"background-color: #00ff00\">abc</span>";
50 editor
.getBoundingClientRect();
52 getSelection().collapse(editor
.querySelector("span").firstChild
, 1);
53 params
= SpecialPowers
.Cu
.createCommandParams();
54 commandManager
.getCommandState("cmd_backgroundColor", window
, params
);
56 params
.getCStringValue("state_attribute"),
58 "cmd_backgroundColor shouldn't return the span's background color due to inline element"
61 editor
.innerHTML
= "<p style=\"background-color: #00ff00\" contenteditable=\"false\">a<span style=\"background-color: #0000ff\" contenteditable=\"true\">b</span>c</p>";
62 editor
.getBoundingClientRect();
64 getSelection().collapse(editor
.querySelector("span[contenteditable=true]").firstChild
, 1);
65 params
= SpecialPowers
.Cu
.createCommandParams();
66 commandManager
.getCommandState("cmd_backgroundColor", window
, params
);
68 params
.getCStringValue("state_attribute"),
70 "cmd_backgroundColor should return non-editable block element's background color"
73 editor
.innerHTML
= "<p contenteditable=\"false\">a<span style=\"background-color: #0000ff\" contenteditable=\"true\">b</span>c</p>";
74 editor
.getBoundingClientRect();
76 getSelection().collapse(editor
.querySelector("span[contenteditable=true]").firstChild
, 1);
77 params
= SpecialPowers
.Cu
.createCommandParams();
78 commandManager
.getCommandState("cmd_backgroundColor", window
, params
);
80 params
.getCStringValue("state_attribute"),
82 "cmd_backgroundColor should return the parent editing host's background color (should ignore the transparent non-editable paragraph)"
85 editor
.style
.backgroundColor
= "#ff0000";
86 editor
.innerHTML
= "<div><p><span>abc</span></p></div>";
87 editor
.getBoundingClientRect();
89 getSelection().collapse(editor
.querySelector("span").firstChild
, 1);
90 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
93 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p></div></div>",
94 "cmd_backgroundColor should set background of the closest block element from the caret in a text node"
97 editor
.style
.backgroundColor
= "#ff0000";
98 editor
.innerHTML
= "abc";
99 editor
.getBoundingClientRect();
101 getSelection().collapse(editor
.firstChild
, 1);
102 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
105 "<div contenteditable=\"\" style=\"background-color: rgb(0, 255, 0);\">abc</div>",
106 "cmd_backgroundColor should set background of the editing host which is direct block parent from the caret in a text node"
109 editor
.style
.backgroundColor
= "#ff0000";
110 editor
.innerHTML
= "<div contenteditable=\"false\"><span contenteditable=\"true\">abc</span></div>";
111 editor
.getBoundingClientRect();
113 getSelection().collapse(editor
.firstChild
, 1);
114 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
117 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div contenteditable=\"false\"><span contenteditable=\"true\">abc</span></div></div>",
118 "cmd_backgroundColor should not set background color of inline editing host nor its non-editable parent block"
121 editor
.style
.backgroundColor
= "#ff0000";
122 editor
.innerHTML
= "<div><p><span>ab<br>c</span></p></div>";
123 editor
.getBoundingClientRect();
125 getSelection().setBaseAndExtent(editor
.querySelector("span"), 1, editor
.querySelector("span"), 2);
126 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
129 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>ab<br>c</span></p></div></div>",
130 "cmd_backgroundColor should set background of the closest block element when selection a leaf element"
133 editor
.style
.backgroundColor
= "#ff0000";
134 editor
.innerHTML
= "<div><p><span>abc</span></p></div>";
135 editor
.getBoundingClientRect();
137 getSelection().setBaseAndExtent(editor
.firstChild
, 0, editor
.firstChild
, 1);
138 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
141 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p></div></div>",
142 "cmd_backgroundColor should set background of the selected block element"
145 editor
.style
.backgroundColor
= "#ff0000";
146 editor
.innerHTML
= "<div><p><span>abc</span></p><p><span>def</span></p><p><span>ghi</span></p></div>";
147 editor
.getBoundingClientRect();
149 getSelection().setBaseAndExtent(editor
.querySelector("span").firstChild
, 1, editor
.querySelector("p + p + p > span").firstChild
, 1);
150 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
153 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p>" +
154 "<p style=\"background-color: rgb(0, 255, 0);\"><span>def</span></p>" +
155 "<p style=\"background-color: rgb(0, 255, 0);\"><span>ghi</span></p></div></div>",
156 "cmd_backgroundColor should set background of the paragraph elements in the selection range"
159 editor
.style
.backgroundColor
= "#ff0000";
160 editor
.innerHTML
= "<div><p><span>abc</span></p><p><span contenteditable=\"false\">def</span></p><p><span>ghi</span></p></div>";
161 editor
.getBoundingClientRect();
163 getSelection().setBaseAndExtent(editor
.querySelector("span").firstChild
, 1, editor
.querySelector("p + p + p > span").firstChild
, 1);
164 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
167 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p>" +
168 "<p style=\"background-color: rgb(0, 255, 0);\"><span contenteditable=\"false\">def</span></p>" +
169 "<p style=\"background-color: rgb(0, 255, 0);\"><span>ghi</span></p></div></div>",
170 "cmd_backgroundColor should set background of the paragraph elements in the selection range even if a paragraph has only non-editable content"
173 editor
.style
.backgroundColor
= "#ff0000";
174 editor
.innerHTML
= "<div><p><span>abc</span></p><p contenteditable=\"false\"><span>def</span></p><p><span>ghi</span></p></div>";
175 editor
.getBoundingClientRect();
177 getSelection().setBaseAndExtent(editor
.querySelector("span").firstChild
, 1, editor
.querySelector("p + p + p > span").firstChild
, 1);
178 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
181 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div><p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p>" +
182 "<p contenteditable=\"false\"><span>def</span></p>" +
183 "<p style=\"background-color: rgb(0, 255, 0);\"><span>ghi</span></p></div></div>",
184 "cmd_backgroundColor should set background of the paragraph elements in the selection range except the non-editable paragraph"
187 editor
.style
.backgroundColor
= "#ff0000";
188 editor
.innerHTML
= "<div><p><span>abc</span></p><span>def</span><p><span>ghi</span></p></div>";
189 editor
.getBoundingClientRect();
191 getSelection().setBaseAndExtent(editor
.querySelector("span").firstChild
, 1, editor
.querySelector("p + span + p > span").firstChild
, 1);
192 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
195 "<div contenteditable=\"\" style=\"background-color: rgb(255, 0, 0);\"><div style=\"background-color: rgb(0, 255, 0);\">" +
196 "<p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p>" +
198 "<p style=\"background-color: rgb(0, 255, 0);\"><span>ghi</span></p></div></div>",
199 "cmd_backgroundColor should set background of the paragraph elements in the selection range and the container <div> which has inline child"
202 editor
.style
.backgroundColor
= "#ff0000";
203 editor
.innerHTML
= "<p><span>abc</span></p><span>def</span><p><span>ghi</span></p>";
204 editor
.getBoundingClientRect();
206 getSelection().setBaseAndExtent(editor
.querySelector("span").firstChild
, 1, editor
.querySelector("p + span + p > span").firstChild
, 1);
207 SpecialPowers
.doCommand(window
, "cmd_backgroundColor", "#00ff00");
210 "<div contenteditable=\"\" style=\"background-color: rgb(0, 255, 0);\">" +
211 "<p style=\"background-color: rgb(0, 255, 0);\"><span>abc</span></p>" +
213 "<p style=\"background-color: rgb(0, 255, 0);\"><span>ghi</span></p></div>",
214 "cmd_backgroundColor should set background of the paragraph elements in the selection range and the editing host which has inline child"
217 // TODO: Add testcase for HTML styling mode.