1 <p>Test some cases of Range.deleteContents() behavior (namely, examples from DOM Range spec).
</p>
2 <pre id=
"console"></pre>
4 <div style=
"visibility:hidden">
5 <FOO>AB
<MOO>CD
</MOO>CD
</FOO>
6 <FOO>A
<MOO>BC
</MOO>DE
</FOO>
7 <FOO>XY
<BAR>ZW
</BAR>Q
</FOO>
8 <FOO><BAR1>AB
</BAR1><BAR2></BAR2><BAR3>CD
</BAR3></FOO>
11 if (window
.testRunner
)
12 testRunner
.dumpAsText();
16 document
.getElementById('console').appendChild(document
.createTextNode(message
+ '\n'));
19 // Simple recursive "give me a string to represent this tree" function
20 function treeAsString(node
) {
21 var string
= node
.nodeName
;
23 string
= "<" + string
+ ">";
24 if (string
== "#text")
25 string
= node
.textContent
;
26 if (node
.childNodes
.length
) {
29 for (var x
= 0; x
< node
.childNodes
.length
; x
++) {
33 string
+= treeAsString(node
.childNodes
[x
]);
36 if (node
.childNodes
.length
) {
42 var range
= document
.createRange();
44 var foo
= document
.getElementsByTagName("FOO")[0];
45 range
.setStart(foo
.firstChild
, 1);
47 range
.deleteContents();
48 log(treeAsString(foo
) + ". Final range (" + range
.startContainer
.nodeName
+ ", " + range
.startOffset
+ ") - (" + range
.endContainer
.nodeName
+ ", " + range
.endOffset
+ ")");
50 var foo
= document
.getElementsByTagName("FOO")[1];
51 range
.setStart(foo
.firstChild
.nextSibling
.firstChild
, 1);
52 range
.setEnd(foo
.lastChild
, 1);
53 range
.deleteContents();
54 log(treeAsString(foo
) + ". Final range (" + range
.startContainer
.nodeName
+ ", " + range
.startOffset
+ ") - (" + range
.endContainer
.nodeName
+ ", " + range
.endOffset
+ ")");
56 var foo
= document
.getElementsByTagName("FOO")[2];
57 range
.setStart(foo
.firstChild
, 1);
58 range
.setEnd(foo
.firstChild
.nextSibling
.firstChild
, 1);
59 range
.deleteContents();
60 log(treeAsString(foo
) + ". Final range (" + range
.startContainer
.nodeName
+ ", " + range
.startOffset
+ ") - (" + range
.endContainer
.nodeName
+ ", " + range
.endOffset
+ ")");
62 var foo
= document
.getElementsByTagName("FOO")[3];
63 range
.setStart(foo
.firstChild
.firstChild
, 1);
64 range
.setEnd(foo
.lastChild
.firstChild
, 1);
65 range
.deleteContents();
66 log(treeAsString(foo
) + ". Final range (" + range
.startContainer
.nodeName
+ ", " + range
.startOffset
+ ") - (" + range
.endContainer
.nodeName
+ ", " + range
.endOffset
+ ")");