editor/libeditor/html/tests/test_bug674861.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=674861
     5 -->
     6 <head>
     7   <title>Test for Bug 674861</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" 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=674861">Mozilla Bug 674861</a>
    14 <p id="display"></p>
    15 <div id="content">
    16   <section id="test1">
    17     <h2> Editable Bullet List </h2>
    18     <ul contenteditable>
    19       <li> item A </li>
    20       <li> item B </li>
    21       <li> item C </li>
    22     </ul>
    24     <h2> Editable Ordered List </h2>
    25     <ol contenteditable>
    26       <li> item A </li>
    27       <li> item B </li>
    28       <li> item C </li>
    29     </ol>
    31     <h2> Editable Definition List </h2>
    32     <dl contenteditable>
    33       <dt> term A </dt>
    34       <dd> definition A </dd>
    35       <dt> term B </dt>
    36       <dd> definition B </dd>
    37       <dt> term C </dt>
    38       <dd> definition C </dd>
    39     </dl>
    40   </section>
    42   <section id="test2" contenteditable>
    43     <h2> Bullet List In Editable Section </h2>
    44     <ul>
    45       <li> item A </li>
    46       <li> item B </li>
    47       <li> item C </li>
    48     </ul>
    50     <h2> Ordered List In Editable Section </h2>
    51     <ol>
    52       <li> item A </li>
    53       <li> item B </li>
    54       <li> item C </li>
    55     </ol>
    57     <h2> Definition List In Editable Section </h2>
    58     <dl>
    59       <dt> term A </dt>
    60       <dd> definition A </dd>
    61       <dt> term B </dt>
    62       <dd> definition B </dd>
    63       <dt> term C </dt>
    64       <dd> definition C </dd>
    65     </dl>
    66   </section>
    67 </div>
    69 <pre id="test">
    70 <script type="application/javascript">
    72 /** Test for Bug 674861 **/
    73 SimpleTest.waitForExplicitFinish();
    74 SimpleTest.waitForFocus(runTests);
    76 const CARET_BEGIN  = 0;
    77 const CARET_MIDDLE = 1;
    78 const CARET_END    = 2;
    80 function try2split(element, caretPos) {
    81   // compute the requested position
    82   var len = element.textContent.length;
    83   var pos = -1;
    84   switch (caretPos) {
    85     case CARET_BEGIN:
    86       pos = 0;
    87       break;
    88     case CARET_MIDDLE:
    89       pos = Math.floor(len/2);
    90       break;
    91     case CARET_END:
    92       pos = len;
    93       break;
    94   }
    96   // put the caret on the requested position
    97   var sel = window.getSelection();
    98   for (var i = 0; i < sel.rangeCount; i++) {
    99     var range = sel.getRangeAt(i);
   100     sel.removeRange(range);
   101   }
   102   range = document.createRange();
   103   range.setStart(element.firstChild, pos);
   104   range.setEnd(element.firstChild, pos);
   105   sel.addRange(range);
   107   // simulates two [Return] keypresses
   108   synthesizeKey("VK_RETURN", {});
   109   synthesizeKey("VK_RETURN", {});
   110 }
   112 function runTests() {
   113   const test1 = document.getElementById("test1");
   114   const test2 = document.getElementById("test2");
   116   // -----------------------------------------------------------------------
   117   // #test1: editable lists should NOT be splittable
   118   // -----------------------------------------------------------------------
   119   const ul = test1.querySelector("ul");
   120   const ol = test1.querySelector("ol");
   121   const dl = test1.querySelector("dl");
   123   // bullet list
   124   ul.focus();
   125   try2split(ul.querySelector("li"), CARET_END);
   126   is(test1.querySelectorAll("ul").length, 1,
   127     "The <ul contenteditable> list should not be splittable.");
   128   is(ul.querySelectorAll("li").length, 5,
   129     "Two new <li> elements should have been created.");
   131   // ordered list
   132   ol.focus();
   133   try2split(ol.querySelector("li"), CARET_END);
   134   is(test1.querySelectorAll("ol").length, 1,
   135     "The <ol contenteditable> list should not be splittable.");
   136   is(ol.querySelectorAll("li").length, 5,
   137     "Two new <li> elements should have been created.");
   139   // definition list
   140   dl.focus();
   141   try2split(dl.querySelector("dd"), CARET_END);
   142   is(test1.querySelectorAll("dl").length, 1,
   143     "The <dl contenteditable> list should not be splittable.");
   144   is(dl.querySelectorAll("dt").length, 5,
   145     "Two new <dt> elements should have been created.");
   147   // -----------------------------------------------------------------------
   148   // #test2: lists in editable blocks should be splittable
   149   // -----------------------------------------------------------------------
   150   test2.focus();
   152   // bullet list
   153   try2split(test2.querySelector("ul li"), CARET_END);
   154   is(test2.querySelectorAll("ul").length, 2,
   155     "The <ul> list should have been splitted.");
   156   is(test2.querySelectorAll("ul li").length, 3,
   157     "No new <li> element should have been created.");
   158   is(test2.querySelectorAll("ul+p").length, 1,
   159     "A new paragraph should have been created.");
   161   // ordered list
   162   try2split(test2.querySelector("ol li"), CARET_END);
   163   is(test2.querySelectorAll("ol").length, 2,
   164     "The <ol> list should have been splitted.");
   165   is(test2.querySelectorAll("ol li").length, 3,
   166     "No new <li> element should have been created.");
   167   is(test2.querySelectorAll("ol+p").length, 1,
   168     "A new paragraph should have been created.");
   170   // definition list
   171   try2split(test2.querySelector("dl dd"), CARET_END);
   172   is(test2.querySelectorAll("dl").length, 2,
   173     "The <dl> list should have been splitted.");
   174   is(test2.querySelectorAll("dt").length, 3,
   175     "No new <dt> element should have been created.");
   176   is(test2.querySelectorAll("dl+p").length, 1,
   177     "A new paragraph should have been created.");
   179   // done
   180   SimpleTest.finish();
   181 }
   182 </script>
   183 </pre>
   184 </body>
   185 </html>

mercurial