| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <body> | |
| 4 <script src="../../resources/testharness.js"></script> | |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <div id="log"></div> | |
| 7 <script> | |
| 8 // TODO(tkent): This should be merged to web-platform-tests/domparsing/XMLSerial
izer-serializeToString.html. | |
| 9 | |
| 10 function parseDocument() { | |
| 11 str = '<test><child1>First child</child1>'; | |
| 12 str += '<child2 attr="an attribute">Second child</child2>'; | |
| 13 str += '<!-- A comment --></test>'; | |
| 14 | |
| 15 parser = new DOMParser(); | |
| 16 return parser.parseFromString(str, 'text/xml'); | |
| 17 } | |
| 18 | |
| 19 var doc = parseDocument(); | |
| 20 var child1 = doc.documentElement.firstChild; | |
| 21 var child2 = child1.nextSibling | |
| 22 var serializer = new XMLSerializer(); | |
| 23 var comment = child2.nextSibling; | |
| 24 | |
| 25 test(function() { | |
| 26 assert_equals(serializer.serializeToString(child1), '<child1>First child</ch
ild1>'); | |
| 27 assert_equals(serializer.serializeToString(child2), '<child2 attr="an attrib
ute">Second child</child2>'); | |
| 28 }, 'Check Element serialization.'); | |
| 29 | |
| 30 test(function() { | |
| 31 assert_equals(serializer.serializeToString(comment), '<!-- A comment -->'); | |
| 32 }, 'Check Comment serialization.'); | |
| 33 | |
| 34 test(function() { | |
| 35 assert_equals(serializer.serializeToString(doc), '<test><child1>First child<
/child1><child2 attr="an attribute">Second child</child2><!-- A comment --></tes
t>'); | |
| 36 }, 'Check Document serialization.'); | |
| 37 | |
| 38 test(function() { | |
| 39 var fragment = doc.createDocumentFragment(); | |
| 40 fragment.appendChild(doc.documentElement.cloneNode(true)); | |
| 41 assert_equals(serializer.serializeToString(fragment), '<test><child1>First c
hild</child1><child2 attr="an attribute">Second child</child2><!-- A comment -->
</test>'); | |
| 42 }, 'Check DocumentFragment serialization.'); | |
| 43 | |
| 44 test(function() { | |
| 45 var attr = child2.getAttributeNode('attr'); | |
| 46 assert_equals(serializer.serializeToString(attr), 'an attribute'); | |
| 47 | |
| 48 var element = doc.createElement('foo'); | |
| 49 element.setAttribute('attr1', ' abc\ndef\tghi\r'); | |
| 50 assert_equals(serializer.serializeToString(element), '<foo attr1=" abc d
ef	ghi "/>'); | |
| 51 }, 'Check Attr serializiation.'); | |
| 52 </script> | |
| 53 </body> | |
| 54 </html> | |
| OLD | NEW |