DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (71042f6bc4f6)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=430392
-->
<head>
  <title>Test for Bug 430392</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=430392">Mozilla Bug 430392</a>
<p id="display"></p>
<div id="content">
  <div contenteditable="true" id="edit"> <span contenteditable="false">A</span> ; <span contenteditable="false">B</span> ; <span contenteditable="false">C</span> </div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 430392 **/

function test() {
  var edit = document.getElementById("edit");
  var html = edit.innerHTML;
  var expectedText = edit.textContent;
  document.getElementById("edit").focus();

  // Each test is [desc, callback].  callback() is called and we check that the
  // textContent didn't change.  For expected failures, the format is [desc,
  // callback, expectedValue], and the test will be marked as an expected fail
  // if the textContent changes to expectedValue, and an unexpected fail if
  // it's neither the original value nor expectedValue.
  var tests = [["adding returns", () => {
    getSelection().collapse(edit.firstChild, 0);
    synthesizeKey("KEY_ArrowRight");
    synthesizeKey("KEY_Enter");
    synthesizeKey("KEY_Enter");
    synthesizeKey("KEY_Backspace");
    synthesizeKey("KEY_Backspace");
  }],
  ["adding shift-returns", () => {
    getSelection().collapse(edit.firstChild, 0);
    synthesizeKey("KEY_ArrowRight");
    synthesizeKey("KEY_Enter", {shiftKey: true});
    synthesizeKey("KEY_Enter", {shiftKey: true});
    synthesizeKey("KEY_Backspace");
    synthesizeKey("KEY_Backspace");
  }]];
  [
    "insertorderedlist",
    "insertunorderedlist",
    ["formatblock", "p"],
  ]
  .forEach(item => {
      var cmd = Array.isArray(item) ? item[0] : item;
      var param = Array.isArray(item) ? item[1] : "";
      tests.push([cmd, () => { document.execCommand(cmd, false, param); }]);
   });
  // These are all TODO -- they don't move the non-editable elements
  [
    "bold",
    "italic",
    "underline",
    "strikethrough",
    "subscript",
    "superscript",
    ["forecolor", "blue"],
    ["backcolor", "blue"],
    ["hilitecolor", "blue"],
    ["fontname", "monospace"],
    ["fontsize", "1"],
    "justifyright",
    "justifycenter",
    "justifyfull",
  ]
  .forEach(item => {
      var cmd = Array.isArray(item) ? item[0] : item;
      var param = Array.isArray(item) ? item[1] : "";
      tests.push([cmd, () => { document.execCommand(cmd, false, param); },
                  " A ;  ; BC "]);
   });
  tests.push(["indent", () => { document.execCommand("indent"); },
              "  ;  ;  ABC"]);
  tests.forEach(arr => {
    ["div", "br", "p"].forEach(sep => {
      document.execCommand("defaultParagraphSeparator", false, sep);

      var expectedFailText = typeof arr[2] == "function" ? arr[2]() : arr[2];

      edit.innerHTML = html;
      edit.focus();
      getSelection().selectAllChildren(edit);
      arr[1]();
      if (typeof expectedFailText != "undefined") {
        todo_is(edit.textContent, expectedText,
                arr[0] + " should not change text (" + sep + ")");
        if (edit.textContent !== expectedText &&
            edit.textContent !== expectedFailText) {
          is(edit.textContent, expectedFailText,
             arr[0] + " changed to different failure (" + sep + ")");
        }
      } else {
        is(edit.textContent, expectedText,
           arr[0] + " should not change text (" + sep + ")");
      }
    });
  });

  SimpleTest.finish();
}

// In WSRunScanner::GetEditableBlockParentOrTopmotEditableInlineContent().
// Before it, HTMLEditor must be able to stop handling edit action at
// non-editable content.
SimpleTest.expectAssertions(18);

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(test);

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