editor/libeditor/tests/test_bug408231.html
author Csoregi Natalia <ncsoregi@mozilla.com>
Wed, 01 Dec 2021 22:45:29 +0200
changeset 600787 d7af815713793a815d1a10a9cb097c7d6261fa2e
parent 598368 5d6a85b1788ecb66fef5ea788eba0817e07db9e2
permissions -rw-r--r--
Backed out changeset c730f6ed4350 (bug 1743809) for causing failures on MediaRecorder-peerconnection.https.html. a=backout

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=408231
-->
<head>
  <title>Test for Bug 408231</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body style="font-family: serif">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408231">Mozilla Bug 408231</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 408231 **/

    var commandEnabledResults = [
      ["copy", "false"],
      ["createlink", "true"],
      ["cut", "false"],
      ["delete", "true"],
      ["fontname", "true"],
      ["fontsize", "true"],
      ["formatblock", "true"],
      ["hilitecolor", "true"],
      ["indent", "true"],
      ["inserthorizontalrule", "true"],
      ["inserthtml", "true"],
      ["insertimage", "true"],
      ["insertorderedlist", "true"],
      ["insertunorderedlist", "true"],
      ["insertparagraph", "true"],
      ["italic", "true"],
      ["justifycenter", "true"],
      ["justifyfull", "true"],
      ["justifyleft", "true"],
      ["justifyright", "true"],
      ["outdent", "true"],
      ["paste", "false"],
      ["redo", "false"],
      ["removeformat", "true"],
      ["selectall", "true"],
      ["strikethrough", "true"],
      ["styleWithCSS", "true"],
      ["subscript", "true"],
      ["superscript", "true"],
      ["underline", "true"],
      ["undo", "false"],
      ["unlink", "true"],
      ["not-a-command", "false"],
    ];

    var commandIndetermResults = [
      ["copy", "false"],
      ["createlink", "false"],
      ["cut", "false"],
      ["delete", "false"],
      ["fontname", "false"],
      ["fontsize", "false"],
      ["formatblock", "false"],
      ["hilitecolor", "false"],
      ["indent", "false"],
      ["inserthorizontalrule", "false"],
      ["inserthtml", "false"],
      ["insertimage", "false"],
      ["insertorderedlist", "false"],
      ["insertunorderedlist", "false"],
      ["insertparagraph", "false"],
      ["italic", "false"],
      ["justifycenter", "false"],
      ["justifyfull", "false"],
      ["justifyleft", "false"],
      ["justifyright", "false"],
      ["outdent", "false"],
      // ["paste", "false"],
      ["redo", "false"],
      ["removeformat", "false"],
      ["selectall", "false"],
      ["strikethrough", "false"],
      ["styleWithCSS", "false"],
      ["subscript", "false"],
      ["superscript", "false"],
      ["underline", "false"],
      ["undo", "false"],
      ["unlink", "false"],
      ["not-a-command", "false"],
    ];

    var commandStateResults = [
      ["copy", "false"],
      ["createlink", "false"],
      ["cut", "false"],
      ["delete", "false"],
      ["fontname", "false"],
      ["fontsize", "false"],
      ["formatblock", "false"],
      ["hilitecolor", "false"],
      ["indent", "false"],
      ["inserthorizontalrule", "false"],
      ["inserthtml", "false"],
      ["insertimage", "false"],
      ["insertorderedlist", "false"],
      ["insertunorderedlist", "false"],
      ["insertparagraph", "false"],
      ["italic", "false"],
      ["justifycenter", "false"],
      ["justifyfull", "false"],
      ["justifyleft", "true"],
      ["justifyright", "false"],
      ["outdent", "false"],
      // ["paste", "false"],
      ["redo", "false"],
      ["removeformat", "false"],
      ["selectall", "false"],
      ["strikethrough", "false"],
      ["styleWithCSS", "false"],
      ["subscript", "false"],
      ["superscript", "false"],
      ["underline", "false"],
      ["undo", "false"],
      ["unlink", "false"],
      ["not-a-command", "false"],
    ];

    var commandValueResults = [
      ["copy", ""],
      ["createlink", ""],
      ["cut", ""],
      ["delete", ""],
      ["fontname", "serif"],
      ["fontsize", ""],
      ["formatblock", ""],
      ["hilitecolor", "transparent"],
      ["indent", ""],
      ["inserthorizontalrule", ""],
      ["inserthtml", ""],
      ["insertimage", ""],
      ["insertorderedlist", ""],
      ["insertunorderedlist", ""],
      ["insertparagraph", ""],
      ["italic", ""],
      ["justifycenter", "left"],
      ["justifyfull", "left"],
      ["justifyleft", "left"],
      ["justifyright", "left"],
      ["outdent", ""],
      // ["paste", ""],
      ["redo", ""],
      ["removeformat", ""],
      ["selectall", ""],
      ["strikethrough", ""],
      ["styleWithCSS", ""],
      ["subscript", ""],
      ["superscript", ""],
      ["underline", ""],
      ["undo", ""],
      ["unlink", ""],
      ["not-a-command", ""],
    ];


    function callQueryCommandEnabled(cmdName) {
      var result;
      try {
        result = "" + document.queryCommandEnabled(cmdName);
      } catch (error) {
        result = "name" in error ? error.name : "exception";
      }
      return result;
    }

    function callQueryCommandIndeterm(cmdName) {
      var result;
      try {
        result = "" + document.queryCommandIndeterm(cmdName);
      } catch (error) {
        result = "name" in error ? error.name : "exception";
      }
      return result;
    }

    function callQueryCommandState(cmdName) {
      var result;
      try {
        result = "" + document.queryCommandState(cmdName);
      } catch (error) {
        result = "name" in error ? error.name : "exception";
      }
      return result;
    }

    function callQueryCommandValue(cmdName) {
      var result;
      try {
        result = "" + document.queryCommandValue(cmdName);
      } catch (error) {
        result = "name" in error ? error.name : "exception";
      }
      return result;
    }

    function testQueryCommand(expectedResults, fun, funName) {
      for (let i = 0; i < expectedResults.length; i++) {
        var commandName = expectedResults[i][0];
        var expectedResult = expectedResults[i][1];
        var result = fun(commandName);
        ok(result == expectedResult, funName + "(" + commandName + ") result=" + result + " expected=" + expectedResult);
      }
    }

    function runTests() {
      document.designMode = "on";
      window.getSelection().collapse(document.body, 0);
      testQueryCommand(commandEnabledResults, callQueryCommandEnabled, "queryCommandEnabled");
      testQueryCommand(commandIndetermResults, callQueryCommandIndeterm, "queryCommandIndeterm");
      testQueryCommand(commandStateResults, callQueryCommandState, "queryCommandState");
      testQueryCommand(commandValueResults, callQueryCommandValue, "queryCommandValue");
      document.designMode = "off";
      SimpleTest.finish();
    }

    window.onload = runTests;
    SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>