3 <div contenteditable=
"true" id=
"work"></div>
6 <script src=
"../../resources/js-test.js"></script>
8 function $(id
) { return document
.getElementById(id
); }
10 var sampleHTML
= 'abc<br id="a"><br id="b"><br id="c">def';
11 var selection
= window
.getSelection();
12 function testIt(nth
, numberOfDeletes
, expectedOffset
, expectedHTML
) {
13 $('work').innerHTML
= sampleHTML
;
14 var range
= document
.createRange();
15 range
.setStartAfter($('work').querySelectorAll('br')[nth
]);
16 selection
.removeAllRanges();
17 selection
.addRange(range
);
18 for (var i
= 0; i
< numberOfDeletes
; ++i
)
19 document
.execCommand('Delete');
20 shouldBeEqualToString('$("work").innerHTML', expectedHTML
);
21 shouldBeEqualToString('selection.type', 'Caret');
22 shouldBe('selection.anchorOffset', expectedOffset
+ '');
25 testIt(0, 1, 3, 'abc<br id="b"><br id="c">def');
26 testIt(1, 1, 2, 'abc<br id="a"><br id="c">def');
27 testIt(2, 1, 0, 'abc<br id="a"><br id="b">def');
28 testIt(1, 2, 3, 'abc<br id="c">def');
29 testIt(2, 2, 0, 'abc<br id="a">def');
30 testIt(2, 3, 3, 'abcdef');
32 if (window
.testRunner
)
33 $('container').outerHTML
= '';
35 $('work').innerHTML
= sampleHTML
;