editor/libeditor/html/tests/test_bug674861.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug674861.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,185 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=674861
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 674861</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=674861">Mozilla Bug 674861</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content">
    1.19 +  <section id="test1">
    1.20 +    <h2> Editable Bullet List </h2>
    1.21 +    <ul contenteditable>
    1.22 +      <li> item A </li>
    1.23 +      <li> item B </li>
    1.24 +      <li> item C </li>
    1.25 +    </ul>
    1.26 +
    1.27 +    <h2> Editable Ordered List </h2>
    1.28 +    <ol contenteditable>
    1.29 +      <li> item A </li>
    1.30 +      <li> item B </li>
    1.31 +      <li> item C </li>
    1.32 +    </ol>
    1.33 +
    1.34 +    <h2> Editable Definition List </h2>
    1.35 +    <dl contenteditable>
    1.36 +      <dt> term A </dt>
    1.37 +      <dd> definition A </dd>
    1.38 +      <dt> term B </dt>
    1.39 +      <dd> definition B </dd>
    1.40 +      <dt> term C </dt>
    1.41 +      <dd> definition C </dd>
    1.42 +    </dl>
    1.43 +  </section>
    1.44 +
    1.45 +  <section id="test2" contenteditable>
    1.46 +    <h2> Bullet List In Editable Section </h2>
    1.47 +    <ul>
    1.48 +      <li> item A </li>
    1.49 +      <li> item B </li>
    1.50 +      <li> item C </li>
    1.51 +    </ul>
    1.52 +
    1.53 +    <h2> Ordered List In Editable Section </h2>
    1.54 +    <ol>
    1.55 +      <li> item A </li>
    1.56 +      <li> item B </li>
    1.57 +      <li> item C </li>
    1.58 +    </ol>
    1.59 +
    1.60 +    <h2> Definition List In Editable Section </h2>
    1.61 +    <dl>
    1.62 +      <dt> term A </dt>
    1.63 +      <dd> definition A </dd>
    1.64 +      <dt> term B </dt>
    1.65 +      <dd> definition B </dd>
    1.66 +      <dt> term C </dt>
    1.67 +      <dd> definition C </dd>
    1.68 +    </dl>
    1.69 +  </section>
    1.70 +</div>
    1.71 +
    1.72 +<pre id="test">
    1.73 +<script type="application/javascript">
    1.74 +
    1.75 +/** Test for Bug 674861 **/
    1.76 +SimpleTest.waitForExplicitFinish();
    1.77 +SimpleTest.waitForFocus(runTests);
    1.78 +
    1.79 +const CARET_BEGIN  = 0;
    1.80 +const CARET_MIDDLE = 1;
    1.81 +const CARET_END    = 2;
    1.82 +
    1.83 +function try2split(element, caretPos) {
    1.84 +  // compute the requested position
    1.85 +  var len = element.textContent.length;
    1.86 +  var pos = -1;
    1.87 +  switch (caretPos) {
    1.88 +    case CARET_BEGIN:
    1.89 +      pos = 0;
    1.90 +      break;
    1.91 +    case CARET_MIDDLE:
    1.92 +      pos = Math.floor(len/2);
    1.93 +      break;
    1.94 +    case CARET_END:
    1.95 +      pos = len;
    1.96 +      break;
    1.97 +  }
    1.98 +
    1.99 +  // put the caret on the requested position
   1.100 +  var sel = window.getSelection();
   1.101 +  for (var i = 0; i < sel.rangeCount; i++) {
   1.102 +    var range = sel.getRangeAt(i);
   1.103 +    sel.removeRange(range);
   1.104 +  }
   1.105 +  range = document.createRange();
   1.106 +  range.setStart(element.firstChild, pos);
   1.107 +  range.setEnd(element.firstChild, pos);
   1.108 +  sel.addRange(range);
   1.109 +  
   1.110 +  // simulates two [Return] keypresses
   1.111 +  synthesizeKey("VK_RETURN", {});
   1.112 +  synthesizeKey("VK_RETURN", {});
   1.113 +}
   1.114 +
   1.115 +function runTests() {
   1.116 +  const test1 = document.getElementById("test1");
   1.117 +  const test2 = document.getElementById("test2");
   1.118 +
   1.119 +  // -----------------------------------------------------------------------
   1.120 +  // #test1: editable lists should NOT be splittable
   1.121 +  // -----------------------------------------------------------------------
   1.122 +  const ul = test1.querySelector("ul");
   1.123 +  const ol = test1.querySelector("ol");
   1.124 +  const dl = test1.querySelector("dl");
   1.125 +
   1.126 +  // bullet list
   1.127 +  ul.focus();
   1.128 +  try2split(ul.querySelector("li"), CARET_END);
   1.129 +  is(test1.querySelectorAll("ul").length, 1,
   1.130 +    "The <ul contenteditable> list should not be splittable.");
   1.131 +  is(ul.querySelectorAll("li").length, 5,
   1.132 +    "Two new <li> elements should have been created.");
   1.133 +
   1.134 +  // ordered list
   1.135 +  ol.focus();
   1.136 +  try2split(ol.querySelector("li"), CARET_END);
   1.137 +  is(test1.querySelectorAll("ol").length, 1,
   1.138 +    "The <ol contenteditable> list should not be splittable.");
   1.139 +  is(ol.querySelectorAll("li").length, 5,
   1.140 +    "Two new <li> elements should have been created.");
   1.141 +
   1.142 +  // definition list
   1.143 +  dl.focus();
   1.144 +  try2split(dl.querySelector("dd"), CARET_END);
   1.145 +  is(test1.querySelectorAll("dl").length, 1,
   1.146 +    "The <dl contenteditable> list should not be splittable.");
   1.147 +  is(dl.querySelectorAll("dt").length, 5,
   1.148 +    "Two new <dt> elements should have been created.");
   1.149 +
   1.150 +  // -----------------------------------------------------------------------
   1.151 +  // #test2: lists in editable blocks should be splittable
   1.152 +  // -----------------------------------------------------------------------
   1.153 +  test2.focus();
   1.154 +
   1.155 +  // bullet list
   1.156 +  try2split(test2.querySelector("ul li"), CARET_END);
   1.157 +  is(test2.querySelectorAll("ul").length, 2,
   1.158 +    "The <ul> list should have been splitted.");
   1.159 +  is(test2.querySelectorAll("ul li").length, 3,
   1.160 +    "No new <li> element should have been created.");
   1.161 +  is(test2.querySelectorAll("ul+p").length, 1,
   1.162 +    "A new paragraph should have been created.");
   1.163 +
   1.164 +  // ordered list
   1.165 +  try2split(test2.querySelector("ol li"), CARET_END);
   1.166 +  is(test2.querySelectorAll("ol").length, 2,
   1.167 +    "The <ol> list should have been splitted.");
   1.168 +  is(test2.querySelectorAll("ol li").length, 3,
   1.169 +    "No new <li> element should have been created.");
   1.170 +  is(test2.querySelectorAll("ol+p").length, 1,
   1.171 +    "A new paragraph should have been created.");
   1.172 +
   1.173 +  // definition list
   1.174 +  try2split(test2.querySelector("dl dd"), CARET_END);
   1.175 +  is(test2.querySelectorAll("dl").length, 2,
   1.176 +    "The <dl> list should have been splitted.");
   1.177 +  is(test2.querySelectorAll("dt").length, 3,
   1.178 +    "No new <dt> element should have been created.");
   1.179 +  is(test2.querySelectorAll("dl+p").length, 1,
   1.180 +    "A new paragraph should have been created.");
   1.181 +
   1.182 +  // done
   1.183 +  SimpleTest.finish();
   1.184 +}
   1.185 +</script>
   1.186 +</pre>
   1.187 +</body>
   1.188 +</html>

mercurial