4 https://bugzilla.mozilla.org/show_bug.cgi?id=676401
7 <title>Test for Bug
676401</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=676401">Mozilla Bug
676401</a>
16 <!-- we need a blockquote to test the "outdent" command -->
18 <blockquote> not editable
</blockquote>
20 <section contenteditable
>
21 <blockquote> editable
</blockquote>
26 <script type=
"application/javascript">
28 /** Test for Bug
676401 **/
29 SimpleTest.waitForExplicitFinish();
30 SimpleTest.waitForFocus(runTests);
34 var alwaysEnabledCommands = [
38 "enableInlineTableEditing",
39 "enableObjectResizing",
45 function ensureNobodyHasFocus() {
46 document.activeElement.blur();
49 function IsCommandEnabled(command) {
50 ensureNobodyHasFocus();
52 // non-editable div: should return false unless alwaysEnabled
53 window.getSelection().selectAllChildren(gBlock1);
55 document.queryCommandEnabled(command),
56 alwaysEnabledCommands.includes(command) && document.queryCommandSupported(command),
57 "'" + command +
"' should not be enabled on a non-editable block."
60 // editable div: should return true if it's supported
61 window.getSelection().selectAllChildren(gBlock2);
63 document.queryCommandEnabled(command),
64 document.queryCommandSupported(command),
65 "'" + command +
"' should be enabled on an editable block."
71 gBlock1 = document.querySelector(
"#content section blockquote");
72 gBlock2 = document.querySelector(
"#content [contenteditable] blockquote");
74 // common commands: test with and without
"styleWithCSS"
76 "bold",
"italic",
"underline",
"strikeThrough",
77 "subscript",
"superscript",
"foreColor",
"backColor",
"hiliteColor",
78 "fontName",
"fontSize",
79 "justifyLeft",
"justifyCenter",
"justifyRight",
"justifyFull",
81 "insertOrderedList",
"insertUnorderedList",
"insertParagraph",
82 "heading",
"formatBlock",
83 "contentReadOnly",
"createLink",
84 "decreaseFontSize",
"increaseFontSize",
85 "insertHTML",
"insertHorizontalRule",
"insertImage",
86 "removeFormat",
"selectAll",
"styleWithCSS",
88 document.execCommand(
"styleWithCSS", false, false);
89 for (i =
0; i < commands.length; i++)
90 IsCommandEnabled(commands[i]);
91 document.execCommand(
"styleWithCSS", false, true);
92 for (i =
0; i < commands.length; i++)
93 IsCommandEnabled(commands[i]);
95 // Mozilla-specific stuff
96 commands = [
"enableInlineTableEditing",
"enableObjectResizing",
"insertBrOnReturn"];
97 for (i =
0; i < commands.length; i++)
98 IsCommandEnabled(commands[i]);
100 // These are privileged, and available only to chrome.
101 ensureNobodyHasFocus();
102 window.getSelection().selectAllChildren(gBlock2);
103 commands = [
"paste"];
104 for (i =
0; i < commands.length; i++) {
105 is(document.queryCommandEnabled(commands[i]), false,
106 "Command should not be enabled for non-privileged code");
107 is(SpecialPowers.wrap(document).queryCommandEnabled(commands[i]), true,
108 "Command should be enabled for privileged code");
109 is(document.execCommand(commands[i], false, false), false,
"Should return false: " + commands[i]);
110 is(SpecialPowers.wrap(document).execCommand(commands[i], false, false), true,
"Should return true: " + commands[i]);
113 // delete/undo/redo -- we have to execute this commands because:
114 // * there's nothing to undo if we haven't modified the selection first
115 // * there's nothing to redo if we haven't undone something first
116 commands = [
"delete",
"undo",
"redo"];
117 for (i =
0; i < commands.length; i++) {
118 IsCommandEnabled(commands[i]);
119 document.execCommand(commands[i], false, false);