tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug676401.html (4183B)


      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 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"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=676401">Mozilla Bug 676401</a>
     14 <p id="display"></p>
     15 <div id="content">
     16  <!-- we need a blockquote to test the "outdent" command -->
     17  <section>
     18    <blockquote> not editable </blockquote>
     19  </section>
     20  <section contenteditable>
     21    <blockquote> editable </blockquote>
     22  </section>
     23 </div>
     24 
     25 <pre id="test">
     26 <script type="application/javascript">
     27 
     28 /** Test for Bug 676401 */
     29 SimpleTest.waitForExplicitFinish();
     30 SimpleTest.waitForFocus(runTests);
     31 
     32 var gBlock1, gBlock2;
     33 
     34 var alwaysEnabledCommands = [
     35  "contentReadOnly",
     36  "copy",
     37  "cut",
     38  "enableInlineTableEditing",
     39  "enableObjectResizing",
     40  "insertBrOnReturn",
     41  "selectAll",
     42  "styleWithCSS",
     43 ];
     44 
     45 function ensureNobodyHasFocus() {
     46  document.activeElement.blur();
     47 }
     48 
     49 function IsCommandEnabled(command) {
     50  ensureNobodyHasFocus();
     51 
     52  // non-editable div: should return false unless alwaysEnabled
     53  window.getSelection().selectAllChildren(gBlock1);
     54  is(
     55    document.queryCommandEnabled(command),
     56    alwaysEnabledCommands.includes(command) && document.queryCommandSupported(command),
     57     "'" + command + "' should not be enabled on a non-editable block."
     58  );
     59 
     60  // editable div: should return true if it's supported
     61  window.getSelection().selectAllChildren(gBlock2);
     62  is(
     63    document.queryCommandEnabled(command),
     64    document.queryCommandSupported(command),
     65    "'" + command + "' should be enabled on an editable block."
     66  );
     67 }
     68 
     69 function runTests() {
     70  var i, commands;
     71  gBlock1 = document.querySelector("#content section blockquote");
     72  gBlock2 = document.querySelector("#content [contenteditable] blockquote");
     73 
     74  // common commands: test with and without "styleWithCSS"
     75  commands = [
     76    "bold", "italic", "underline", "strikeThrough",
     77    "subscript", "superscript", "foreColor", "backColor", "hiliteColor",
     78    "fontName", "fontSize",
     79    "justifyLeft", "justifyCenter", "justifyRight", "justifyFull",
     80    "indent", "outdent",
     81    "insertOrderedList", "insertUnorderedList", "insertParagraph",
     82    "heading", "formatBlock",
     83    "contentReadOnly", "createLink",
     84    "decreaseFontSize", "increaseFontSize",
     85    "insertHTML", "insertHorizontalRule", "insertImage",
     86    "removeFormat", "selectAll", "styleWithCSS",
     87  ];
     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]);
     94 
     95  // Mozilla-specific stuff
     96  commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
     97  for (i = 0; i < commands.length; i++)
     98    IsCommandEnabled(commands[i]);
     99 
    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]);
    111  }
    112 
    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);
    120  }
    121 
    122  // done
    123  SimpleTest.finish();
    124 }
    125 
    126 </script>
    127 </pre>
    128 </body>
    129 </html>