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.

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

mercurial