|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 --> |
|
5 <head> |
|
6 <title>Test for XHTML serializer, bug 541937</title> |
|
7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
9 </head> |
|
10 <body> |
|
11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=541937">Mozilla Bug </a> |
|
12 <p id="display"></p> |
|
13 <div id="content" style="display: none"> |
|
14 <iframe id="testframe" src="file_bug541937.html"> |
|
15 </iframe> |
|
16 <iframe id="testframe2" src="file_bug541937.xhtml"> |
|
17 </iframe> |
|
18 </div> |
|
19 |
|
20 <pre id="test"> |
|
21 <script class="testbody" type="text/javascript"> |
|
22 |
|
23 function testSerializer () { |
|
24 const de = SpecialPowers.Ci.nsIDocumentEncoder; |
|
25 var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"] |
|
26 .createInstance(SpecialPowers.Ci.nsIDocumentEncoder); |
|
27 |
|
28 var parser = new DOMParser(); |
|
29 var serializer = new XMLSerializer(); |
|
30 |
|
31 // with content |
|
32 var str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes --> \n<content xmlns=""/></link>\n</doc>'; |
|
33 var expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes --> \n<content xmlns=""/></link>\n</doc>'; |
|
34 |
|
35 var doc = parser.parseFromString(str,"application/xml"); |
|
36 var result = serializer.serializeToString(doc); |
|
37 result = result.replace(/\r\n/mg, "\n"); |
|
38 is(result, expected, "serialization of a link element inside an xml document with children"); |
|
39 |
|
40 // with only whitespaces |
|
41 str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>'; |
|
42 expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>'; |
|
43 |
|
44 doc = parser.parseFromString(str,"application/xml"); |
|
45 result = serializer.serializeToString(doc); |
|
46 result = result.replace(/\r\n/mg, "\n"); |
|
47 is(result, expected, "serialization of a link element with only whitespaces as content, inside an xml document"); |
|
48 |
|
49 // with only one space as content |
|
50 str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>'; |
|
51 expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>'; |
|
52 |
|
53 doc = parser.parseFromString(str,"application/xml"); |
|
54 result = serializer.serializeToString(doc); |
|
55 result = result.replace(/\r\n/mg, "\n"); |
|
56 is(result, expected, "serialization of a link element with only one space as content, inside an xml document"); |
|
57 |
|
58 // let's remove the content |
|
59 str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> <!-- child nodes --> \ndeleted content<content xmlns=""/> </link>\n</doc>'; |
|
60 expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; |
|
61 |
|
62 doc = parser.parseFromString(str,"application/xml"); |
|
63 doc.documentElement.firstElementChild.textContent = ''; |
|
64 result = serializer.serializeToString(doc); |
|
65 result = result.replace(/\r\n/mg, "\n"); |
|
66 is(result, expected, "serialization of a link element on which we removed dynamically the content, inside an xml document"); |
|
67 |
|
68 // with no content but an ended tag |
|
69 str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"></link>\n</doc>'; |
|
70 expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; |
|
71 |
|
72 doc = parser.parseFromString(str,"application/xml"); |
|
73 result = serializer.serializeToString(doc); |
|
74 result = result.replace(/\r\n/mg, "\n"); |
|
75 is(result, expected, "serialization of a link element with no content but with an ended tag, inside an xml document"); |
|
76 |
|
77 // with no content |
|
78 str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"/>\n</doc>'; |
|
79 expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; |
|
80 |
|
81 doc = parser.parseFromString(str,"application/xml"); |
|
82 result = serializer.serializeToString(doc); |
|
83 result = result.replace(/\r\n/mg, "\n"); |
|
84 is(result, expected, "serialization of a link element with no content, inside an xml document"); |
|
85 |
|
86 |
|
87 doc = $("testframe").contentDocument; |
|
88 encoder.init(doc, "text/html", de.OutputLFLineBreak); |
|
89 encoder.setCharset("UTF-8"); |
|
90 result = encoder.encodeToString(); |
|
91 expected = '<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n <title>Test</title>\n'; |
|
92 expected += ' <link rel=\"Top\" href=\"\"> '; |
|
93 expected += ' </head><body>foo \n\n\n <p>Hello world</p>\n</body></html>'; |
|
94 is(result, expected, "serialization of a link element with content, inside an html document"); |
|
95 |
|
96 doc = $("testframe2").contentDocument; |
|
97 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak); |
|
98 encoder.setCharset("UTF-8"); |
|
99 result = encoder.encodeToString(); |
|
100 expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'; |
|
101 expected += '<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n <meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n <title>Test</title>\n'; |
|
102 expected += ' <link rel="Top" href=""> foo </link>\n'; |
|
103 expected += '\n</head>\n<body>\n <p>Hello world</p>\n</body>\n</html>'; |
|
104 is(result, expected, "serialization of a link element with content, inside an xhtml document"); |
|
105 |
|
106 SimpleTest.finish(); |
|
107 } |
|
108 |
|
109 |
|
110 SimpleTest.waitForExplicitFinish(); |
|
111 |
|
112 addLoadEvent(testSerializer); |
|
113 |
|
114 </script> |
|
115 </pre> |
|
116 </body> |
|
117 </html> |
|
118 |
|
119 |