4 https://bugzilla.mozilla.org/show_bug.cgi?id=570144
7 <title>Test for Bug
570144</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"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=570144">Mozilla Bug
570144</a>
16 <!-- editable paragraphs in list item -->
19 <li><p contenteditable
>foo
</p></li>
22 <li><p contenteditable
>foo
</p></li>
26 <dd><p contenteditable
>bar
</p></dd>
29 <!-- paragraphs in editable list item -->
32 <li contenteditable
><p>foo
</p></li>
35 <li contenteditable
><p>foo
</p></li>
39 <dd contenteditable
><p>bar
</p></dd>
42 <!-- paragraphs in editable list -->
58 <script type=
"application/javascript">
60 /** Test for Bug
570144 **/
61 SimpleTest.waitForExplicitFinish();
62 SimpleTest.waitForFocus(runTests);
64 function try2split(list) {
65 var editor = list.hasAttribute(
"contenteditable")
66 ? list : list.querySelector(
"*[contenteditable]");
68 // put the caret at the end of the paragraph
69 var selection = window.getSelection();
70 if (editor.nodeName.toLowerCase() ==
"p")
71 selection.selectAllChildren(editor);
73 selection.selectAllChildren(editor.querySelector(
"p"));
74 selection.collapseToEnd();
75 // simulate a [Enter] keypress
76 synthesizeKey(
"KEY_Enter");
79 function testSection(element, context, shouldCreateLI, shouldCreateP) {
80 var nbLI = shouldCreateLI ?
2 :
1; // number of expected list items
81 var nbP = shouldCreateP ?
2 :
1; // number of expected paragraphs
83 function message(nodeName, dup) {
84 return context +
":[Return] should " + (dup ?
"" :
"not ")
85 +
"create another <" + nodeName +
">.";
87 var msgP = message(
"p", shouldCreateP);
88 var msgLI = message(
"li", shouldCreateLI);
89 var msgDT = message(
"dt", shouldCreateLI);
90 var msgDD = message(
"dd", false);
92 const ol = element.querySelector(
"ol");
94 is(ol.querySelectorAll(
"li").length, nbLI, msgLI);
95 is(ol.querySelectorAll(
"p").length, nbP, msgP);
97 const ul = element.querySelector(
"ul");
99 is(ul.querySelectorAll(
"li").length, nbLI, msgLI);
100 is(ul.querySelectorAll(
"p").length, nbP, msgP);
102 const dl = element.querySelector(
"dl");
104 is(dl.querySelectorAll(
"dt").length, nbLI, msgDT);
105 is(dl.querySelectorAll(
"dd").length,
1, msgDD);
106 is(dl.querySelectorAll(
"p").length, nbP, msgP);
109 function runTests() {
110 testSection(document.getElementById(
"test1"),
"editable paragraph in list item", false, false);
111 testSection(document.getElementById(
"test2"),
"paragraph in editable list item", false, true);
112 testSection(document.getElementById(
"test3"),
"paragraph in editable list", true, false);
113 /* Note: concerning #test3, it would be preferrable that [Return] creates
114 * another paragraph in another list item (i.e. last argument = 'true').
115 * Currently it just creates an empty list item, which is acceptable.