editor/libeditor/html/tests/test_bug570144.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug570144.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=570144
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 570144</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=570144">Mozilla Bug 570144</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content">
    1.19 +  <!-- editable paragraphs in list item -->
    1.20 +  <section id="test1">
    1.21 +    <ol>
    1.22 +      <li><p contenteditable>foo</p></li>
    1.23 +    </ol>
    1.24 +    <ul>
    1.25 +      <li><p contenteditable>foo</p></li>
    1.26 +    </ul>
    1.27 +    <dl>
    1.28 +      <dt>foo</dt>
    1.29 +      <dd><p contenteditable>bar</p></dd>
    1.30 +    </dl>
    1.31 +  </section>
    1.32 +  <!-- paragraphs in editable list item -->
    1.33 +  <section id="test2">
    1.34 +    <ol>
    1.35 +      <li contenteditable><p>foo</p></li>
    1.36 +    </ol>
    1.37 +    <ul>
    1.38 +      <li contenteditable><p>foo</p></li>
    1.39 +    </ul>
    1.40 +    <dl>
    1.41 +      <dt>foo</dt>
    1.42 +      <dd contenteditable><p>bar</p></dd>
    1.43 +    </dl>
    1.44 +  </section>
    1.45 +  <!-- paragraphs in editable list -->
    1.46 +  <section id="test3">
    1.47 +    <ol contenteditable>
    1.48 +      <li><p>foo</p></li>
    1.49 +    </ol>
    1.50 +    <ul contenteditable>
    1.51 +      <li><p>foo</p></li>
    1.52 +    </ul>
    1.53 +    <dl contenteditable>
    1.54 +      <dt>foo</dt>
    1.55 +      <dd><p>bar</p></dd>
    1.56 +    </dl>
    1.57 +  </section>
    1.58 +</div>
    1.59 +
    1.60 +<pre id="test">
    1.61 +<script type="application/javascript">
    1.62 +
    1.63 +/** Test for Bug 570144 **/
    1.64 +SimpleTest.waitForExplicitFinish();
    1.65 +SimpleTest.waitForFocus(runTests);
    1.66 +
    1.67 +function try2split(list) {
    1.68 +  var editor = list.hasAttribute("contenteditable")
    1.69 +             ? list : list.querySelector("*[contenteditable]");
    1.70 +  editor.focus();
    1.71 +  // put the caret at the end of the paragraph
    1.72 +  var selection = window.getSelection();
    1.73 +  if (editor.nodeName.toLowerCase() == "p")
    1.74 +    selection.selectAllChildren(editor);
    1.75 +  else
    1.76 +    selection.selectAllChildren(editor.querySelector("p"));
    1.77 +  selection.collapseToEnd();
    1.78 +  // simulate a [Return] keypress
    1.79 +  synthesizeKey("VK_RETURN", {});
    1.80 +}
    1.81 +
    1.82 +function testSection(element, context, shouldCreateLI, shouldCreateP) {
    1.83 +  var nbLI = shouldCreateLI ? 2 : 1; // number of expected list items
    1.84 +  var nbP  = shouldCreateP  ? 2 : 1; // number of expected paragraphs
    1.85 +
    1.86 +  function message(nodeName, dup) {
    1.87 +    return context + ":[Return] should " + (dup ? "" : "not ")
    1.88 +                   + "create another <" + nodeName + ">."
    1.89 +  }
    1.90 +  var msgP  = message("p",  shouldCreateP);
    1.91 +  var msgLI = message("li", shouldCreateLI);
    1.92 +  var msgDT = message("dt", shouldCreateLI);
    1.93 +  var msgDD = message("dd", false);
    1.94 +
    1.95 +  const ol = element.querySelector("ol");
    1.96 +  try2split(ol);
    1.97 +  is(ol.querySelectorAll("li").length, nbLI, msgLI);
    1.98 +  is(ol.querySelectorAll("p").length, nbP, msgP);
    1.99 +
   1.100 +  const ul = element.querySelector("ul");
   1.101 +  try2split(ul);
   1.102 +  is(ul.querySelectorAll("li").length, nbLI, msgLI);
   1.103 +  is(ul.querySelectorAll("p").length, nbP, msgP);
   1.104 +
   1.105 +  const dl = element.querySelector("dl");
   1.106 +  try2split(dl);
   1.107 +  is(dl.querySelectorAll("dt").length, nbLI, msgDT);
   1.108 +  is(dl.querySelectorAll("dd").length, 1, msgDD);
   1.109 +  is(dl.querySelectorAll("p").length, nbP, msgP);
   1.110 +}
   1.111 +
   1.112 +function runTests() {
   1.113 +  testSection(document.getElementById("test1"), "editable paragraph in list item", false, false);
   1.114 +  testSection(document.getElementById("test2"), "paragraph in editable list item", false, true);
   1.115 +  testSection(document.getElementById("test3"), "paragraph in editable list",      true,  false);
   1.116 +  /* Note: concerning #test3, it would be preferrable that [Return] creates
   1.117 +   * another paragraph in another list item (i.e. last argument = 'true').
   1.118 +   * Currently it just creates an empty list item, which is acceptable.
   1.119 +   */
   1.120 +  SimpleTest.finish();
   1.121 +}
   1.122 +
   1.123 +</script>
   1.124 +</pre>
   1.125 +</body>
   1.126 +</html>

mercurial