4 <script src=
"../../resources/js-test.js"></script>
6 <div id=
"div1">A
</div><div id=
"div2">B
</div><div id=
"div3">C1
<div id=
"div4">D
</div><div id=
"div5">E
</div>C2
</div><div id=
"div6">F
</div><div id=
"div6">G
</div>
7 <div id=
"description">Test various cases of Range.insertNode with nodes in the same container as the Range.
</div>
10 var range
= document
.createRange();
12 var containerElement
= document
.getElementById("rootDiv");
13 var insertedElement
= document
.getElementById("div1");
15 range
.setStart(containerElement
, 3);
16 range
.setEnd(containerElement
, 3);
17 range
.insertNode(insertedElement
);
19 shouldBe('range.toString()', '"A"');
21 range
.setStart(containerElement
, 3);
22 range
.setEnd(containerElement
, 3);
23 range
.insertNode(insertedElement
);
25 shouldBe('range.toString()', '"A"');
27 insertedElement
= document
.getElementById("div3");
29 range
.setStart(containerElement
, 5);
30 range
.setEnd(containerElement
, 5);
31 range
.insertNode(insertedElement
);
33 shouldBe('range.toString()', '"C1DEC2"');
35 range
.setStart(containerElement
, 5);
36 range
.setEnd(containerElement
, 5);
37 range
.insertNode(insertedElement
);
39 shouldBe('range.toString()', '"C1DEC2"');
41 insertedElement
= document
.getElementById("div6");
43 range
.setStart(containerElement
, 1);
44 range
.setEnd(containerElement
, 1);
45 range
.insertNode(insertedElement
);
47 shouldBe('range.toString()', '"F"');
49 insertedElement
= document
.getElementById("div3");
51 range
.setStart(containerElement
, 4);
52 range
.setEnd(containerElement
, 4);
53 range
.insertNode(insertedElement
);
55 shouldBe('range.toString()', '"C1DEC2"');
57 var documentFragment
= range
.extractContents();
58 shouldBe('range.startContainer', 'containerElement');
59 shouldBe('range.startOffset', '4');
60 shouldBe('range.endContainer', 'containerElement');
61 shouldBe('range.endOffset', '4');
63 range
.insertNode(documentFragment
);
64 shouldBe('range.toString()', '"C1DEC2"');