editor/libeditor/html/tests/test_bug676401.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=676401
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 676401</title>
michael@0 8 <script type="application/javascript" src="/MochiKit/packed.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12 </head>
michael@0 13 <body>
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=676401">Mozilla Bug 676401</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content">
michael@0 17 <!-- we need a blockquote to test the "outdent" command -->
michael@0 18 <section>
michael@0 19 <blockquote> not editable </blockquote>
michael@0 20 </section>
michael@0 21 <section contenteditable>
michael@0 22 <blockquote> editable </blockquote>
michael@0 23 </section>
michael@0 24 </div>
michael@0 25
michael@0 26 <pre id="test">
michael@0 27 <script type="application/javascript">
michael@0 28
michael@0 29 /** Test for Bug 676401 **/
michael@0 30 SimpleTest.waitForExplicitFinish();
michael@0 31 SimpleTest.waitForFocus(runTests);
michael@0 32
michael@0 33 var gBlock1, gBlock2;
michael@0 34
michael@0 35 var alwaysEnabledCommands = [
michael@0 36 "contentReadOnly",
michael@0 37 "copy",
michael@0 38 "enableInlineTableEditing",
michael@0 39 "enableObjectResizing",
michael@0 40 "insertBrOnReturn",
michael@0 41 "selectAll",
michael@0 42 "styleWithCSS",
michael@0 43 ];
michael@0 44
michael@0 45 function IsCommandEnabled(command) {
michael@0 46 var enabled;
michael@0 47
michael@0 48 // non-editable div: should return false unless alwaysEnabled
michael@0 49 window.getSelection().selectAllChildren(gBlock1);
michael@0 50 enabled = document.queryCommandEnabled(command);
michael@0 51 is(enabled, alwaysEnabledCommands.indexOf(command) != -1,
michael@0 52 "'" + command + "' should not be enabled on a non-editable block.");
michael@0 53
michael@0 54 // editable div: should return true
michael@0 55 window.getSelection().selectAllChildren(gBlock2);
michael@0 56 enabled = document.queryCommandEnabled(command);
michael@0 57 is(enabled, true, "'" + command + "' should be enabled on an editable block.");
michael@0 58 }
michael@0 59
michael@0 60 function runTests() {
michael@0 61 var i, commands;
michael@0 62 gBlock1 = document.querySelector("#content section blockquote");
michael@0 63 gBlock2 = document.querySelector("#content [contenteditable] blockquote");
michael@0 64
michael@0 65 // common commands: test with and without "styleWithCSS"
michael@0 66 commands = [
michael@0 67 "bold", "italic", "underline", "strikeThrough",
michael@0 68 "subscript", "superscript", "foreColor", "backColor", "hiliteColor",
michael@0 69 "fontName", "fontSize",
michael@0 70 "justifyLeft", "justifyCenter", "justifyRight", "justifyFull",
michael@0 71 "indent", "outdent",
michael@0 72 "insertOrderedList", "insertUnorderedList", "insertParagraph",
michael@0 73 "heading", "formatBlock",
michael@0 74 "contentReadOnly", "createLink",
michael@0 75 "decreaseFontSize", "increaseFontSize",
michael@0 76 "insertHTML", "insertHorizontalRule", "insertImage",
michael@0 77 "removeFormat", "selectAll", "styleWithCSS"
michael@0 78 ];
michael@0 79 document.execCommand("styleWithCSS", false, false);
michael@0 80 for (i = 0; i < commands.length; i++)
michael@0 81 IsCommandEnabled(commands[i]);
michael@0 82 document.execCommand("styleWithCSS", false, true);
michael@0 83 for (i = 0; i < commands.length; i++)
michael@0 84 IsCommandEnabled(commands[i]);
michael@0 85
michael@0 86 // Mozilla-specific stuff
michael@0 87 commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
michael@0 88 for (i = 0; i < commands.length; i++)
michael@0 89 IsCommandEnabled(commands[i]);
michael@0 90
michael@0 91 // These are privileged, and available only to chrome.
michael@0 92 commands = ["cut", "paste", "copy"];
michael@0 93 for (i = 0; i < commands.length; i++) {
michael@0 94 IsCommandEnabled(commands[i]);
michael@0 95 try {
michael@0 96 document.execCommand(commands[i], false, false);
michael@0 97 ok(false, "Thould have thrown: " + commands[i]);
michael@0 98 } catch (e) {
michael@0 99 ok(/insecure|denied/.test(e), "Threw correctly: " + commands[i] + " - " + e);
michael@0 100 }
michael@0 101 SpecialPowers.wrap(document).execCommand(commands[i], false, false);
michael@0 102 }
michael@0 103
michael@0 104 // delete/undo/redo -- we have to execute this commands because:
michael@0 105 // * there's nothing to undo if we haven't modified the selection first
michael@0 106 // * there's nothing to redo if we haven't undone something first
michael@0 107 commands = ["delete", "undo", "redo"];
michael@0 108 for (i = 0; i < commands.length; i++) {
michael@0 109 IsCommandEnabled(commands[i]);
michael@0 110 document.execCommand(commands[i], false, false);
michael@0 111 }
michael@0 112
michael@0 113 // done
michael@0 114 SimpleTest.finish();
michael@0 115 }
michael@0 116
michael@0 117 </script>
michael@0 118 </pre>
michael@0 119 </body>
michael@0 120 </html>

mercurial