4 <script src=
"../../../resources/dump-as-markup.js"></script>
7 <div id=
"test"><div><a href=
"#">link
</a></div><div></div><div><br><br><img src=
"" id=
"img-tag"></div><div><br><br>text
</div></div>
8 <div id=
"expectations">
9 <div id=
"test_right_complex_subtree"><div><a href=
"#">link
</a></div><div></div><div><br><br></div></div>
10 <div id=
"test_left_complex_subtree"><div></div><div><br><br>text
</div></div>
12 <pre id=
"console"></pre>
15 function log(message
) {
16 document
.getElementById('console').innerHTML
+= message
+ '\n';
19 function testCloneContents(description
, range
, expectedContentsId
) {
20 var actualContents
= range
.cloneContents();
22 var action
= description
+ ' yields:\n' + Markup
.get(actualContents
).replace(/</g
, '<');
23 var expectedContents
= document
.getElementById(expectedContentsId
);
24 if (Markup
.get(actualContents
) == Markup
.get(expectedContents
))
25 log('PASS: ' + action
);
27 log('FAIL: ' + action
+ '\n but expected:\n' + Markup
.get(expectedContents
).replace(/</g
, '<'));
34 var test
= document
.getElementById('test');
35 log('test contents:\n' + Markup
.get(test
).replace(/</g
, '<') + '\n')
37 var range
= document
.createRange();
39 range
.setStartBefore(test
.firstChild
);
40 var imgTag
= document
.getElementById('img-tag')
41 range
.setEndBefore(imgTag
);
43 testCloneContents('Cloning right complex subtree', range
, 'test_right_complex_subtree');
45 range
.setStartAfter(imgTag
);
46 range
.setEndAfter(test
.lastChild
);
48 testCloneContents('Cloning left complex subtree', range
, 'test_left_complex_subtree');
50 test
.style
.display
= 'none';
51 document
.getElementById('expectations').style
.display
= 'none';