editor/libeditor/html/tests/test_bug676401.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug676401.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=676401
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 676401</title>
    1.11 +  <script type="application/javascript" src="/MochiKit/packed.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=676401">Mozilla Bug 676401</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content">
    1.20 +  <!-- we need a blockquote to test the "outdent" command -->
    1.21 +  <section>
    1.22 +    <blockquote> not editable </blockquote>
    1.23 +  </section>
    1.24 +  <section contenteditable>
    1.25 +    <blockquote> editable </blockquote>
    1.26 +  </section>
    1.27 +</div>
    1.28 +
    1.29 +<pre id="test">
    1.30 +<script type="application/javascript">
    1.31 +
    1.32 +/** Test for Bug 676401 **/
    1.33 +SimpleTest.waitForExplicitFinish();
    1.34 +SimpleTest.waitForFocus(runTests);
    1.35 +
    1.36 +var gBlock1, gBlock2;
    1.37 +
    1.38 +var alwaysEnabledCommands = [
    1.39 +  "contentReadOnly",
    1.40 +  "copy",
    1.41 +  "enableInlineTableEditing",
    1.42 +  "enableObjectResizing",
    1.43 +  "insertBrOnReturn",
    1.44 +  "selectAll",
    1.45 +  "styleWithCSS",
    1.46 +];
    1.47 +
    1.48 +function IsCommandEnabled(command) {
    1.49 +  var enabled;
    1.50 +
    1.51 +  // non-editable div: should return false unless alwaysEnabled
    1.52 +  window.getSelection().selectAllChildren(gBlock1);
    1.53 +  enabled = document.queryCommandEnabled(command);
    1.54 +  is(enabled, alwaysEnabledCommands.indexOf(command) != -1,
    1.55 +     "'" + command + "' should not be enabled on a non-editable block.");
    1.56 +
    1.57 +  // editable div: should return true
    1.58 +  window.getSelection().selectAllChildren(gBlock2);
    1.59 +  enabled = document.queryCommandEnabled(command);
    1.60 +  is(enabled, true, "'" + command + "' should be enabled on an editable block.");
    1.61 +}
    1.62 +
    1.63 +function runTests() {
    1.64 +  var i, commands;
    1.65 +  gBlock1 = document.querySelector("#content section blockquote");
    1.66 +  gBlock2 = document.querySelector("#content [contenteditable] blockquote");
    1.67 +
    1.68 +  // common commands: test with and without "styleWithCSS"
    1.69 +  commands = [
    1.70 +    "bold", "italic", "underline", "strikeThrough", 
    1.71 +    "subscript", "superscript", "foreColor", "backColor", "hiliteColor",
    1.72 +    "fontName", "fontSize",
    1.73 +    "justifyLeft", "justifyCenter", "justifyRight", "justifyFull",
    1.74 +    "indent", "outdent",
    1.75 +    "insertOrderedList", "insertUnorderedList", "insertParagraph",
    1.76 +    "heading", "formatBlock",
    1.77 +    "contentReadOnly", "createLink",
    1.78 +    "decreaseFontSize", "increaseFontSize",
    1.79 +    "insertHTML", "insertHorizontalRule", "insertImage",
    1.80 +    "removeFormat", "selectAll", "styleWithCSS"
    1.81 +  ];
    1.82 +  document.execCommand("styleWithCSS", false, false);
    1.83 +  for (i = 0; i < commands.length; i++)
    1.84 +    IsCommandEnabled(commands[i]);
    1.85 +  document.execCommand("styleWithCSS", false, true);
    1.86 +  for (i = 0; i < commands.length; i++)
    1.87 +    IsCommandEnabled(commands[i]);
    1.88 +
    1.89 +  // Mozilla-specific stuff
    1.90 +  commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
    1.91 +  for (i = 0; i < commands.length; i++)
    1.92 +    IsCommandEnabled(commands[i]);
    1.93 +
    1.94 +  // These are privileged, and available only to chrome.
    1.95 +  commands = ["cut", "paste", "copy"];
    1.96 +  for (i = 0; i < commands.length; i++) {
    1.97 +    IsCommandEnabled(commands[i]);
    1.98 +    try {
    1.99 +      document.execCommand(commands[i], false, false);
   1.100 +      ok(false, "Thould have thrown: " + commands[i]);
   1.101 +    } catch (e) {
   1.102 +      ok(/insecure|denied/.test(e), "Threw correctly: " + commands[i] + " - " + e);
   1.103 +    }
   1.104 +    SpecialPowers.wrap(document).execCommand(commands[i], false, false);
   1.105 +  }
   1.106 +
   1.107 +  // delete/undo/redo -- we have to execute this commands because:
   1.108 +  //  * there's nothing to undo if we haven't modified the selection first
   1.109 +  //  * there's nothing to redo if we haven't undone something first
   1.110 +  commands = ["delete", "undo", "redo"];
   1.111 +  for (i = 0; i < commands.length; i++) {
   1.112 +    IsCommandEnabled(commands[i]);
   1.113 +    document.execCommand(commands[i], false, false);
   1.114 +  }
   1.115 +
   1.116 +  // done
   1.117 +  SimpleTest.finish();
   1.118 +}
   1.119 +
   1.120 +</script>
   1.121 +</pre>
   1.122 +</body>
   1.123 +</html>

mercurial