2 <p id=
"description"></p>
3 <div id=
"sample" contenteditable=
"true">
12 <script src=
"../../resources/js-test.js"></script>
14 function $(id
) { return document
.getElementById(id
); }
17 var selection
= getSelection();
19 function testIt(nth
, message
, expectedText
, expectedHTML
, initRange
, getResult
)
21 var listItem
= $('sample').querySelectorAll('li')[nth
];
22 var range
= document
.createRange();
23 initRange(listItem
, range
);
24 selection
.removeAllRanges();
25 selection
.addRange(range
);
26 document
.execCommand('InsertText', false, '\n');
28 actualHTML
= getResult(listItem
).outerHTML
;
29 shouldBeEqualToString('actualHTML', expectedHTML
);
30 shouldBeEqualToString('selection.type', 'Caret');
31 shouldBeEqualToString('selection.focusNode.textContent', expectedText
);
32 shouldBe('selection.focusOffset', '0');
38 testIt(2, 'insert at end', '', '<li><p><br></p></li>',
39 function(listChild
, range
) {
40 var textNode
= listChild
.firstChild
.firstChild
;
41 range
.setStart(textNode
, textNode
.nodeValue
.length
);
44 return listItem
.nextElementSibling
;
47 testIt(1, 'insert at start', 'is', '<li><p><br></p></li>',
48 function(listChild
, range
) {
49 var textNode
= listChild
.firstChild
.firstChild
;
50 range
.setStart(textNode
, 0);
53 return listItem
.previousElementSibling
;
56 testIt(0, 'insert at middle', 'his', '<li><p>his</p></li>',
57 function(listChild
, range
) {
58 var textNode
= listChild
.firstChild
.firstChild
;
59 range
.setStart(textNode
, 1);
62 return listItem
.nextElementSibling
;
65 if (window
.testRunner
)
66 $('container').outerHTML
= '';