1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug541937.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +--> 1.8 +<head> 1.9 + <title>Test for XHTML serializer, bug 541937</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.12 +</head> 1.13 +<body> 1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=541937">Mozilla Bug </a> 1.15 +<p id="display"></p> 1.16 +<div id="content" style="display: none"> 1.17 + <iframe id="testframe" src="file_bug541937.html"> 1.18 + </iframe> 1.19 + <iframe id="testframe2" src="file_bug541937.xhtml"> 1.20 + </iframe> 1.21 +</div> 1.22 + 1.23 +<pre id="test"> 1.24 +<script class="testbody" type="text/javascript"> 1.25 + 1.26 +function testSerializer () { 1.27 + const de = SpecialPowers.Ci.nsIDocumentEncoder; 1.28 + var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"] 1.29 + .createInstance(SpecialPowers.Ci.nsIDocumentEncoder); 1.30 + 1.31 + var parser = new DOMParser(); 1.32 + var serializer = new XMLSerializer(); 1.33 + 1.34 + // with content 1.35 + var str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes --> \n<content xmlns=""/></link>\n</doc>'; 1.36 + 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>'; 1.37 + 1.38 + var doc = parser.parseFromString(str,"application/xml"); 1.39 + var result = serializer.serializeToString(doc); 1.40 + result = result.replace(/\r\n/mg, "\n"); 1.41 + is(result, expected, "serialization of a link element inside an xml document with children"); 1.42 + 1.43 + // with only whitespaces 1.44 + str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>'; 1.45 + expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>'; 1.46 + 1.47 + doc = parser.parseFromString(str,"application/xml"); 1.48 + result = serializer.serializeToString(doc); 1.49 + result = result.replace(/\r\n/mg, "\n"); 1.50 + is(result, expected, "serialization of a link element with only whitespaces as content, inside an xml document"); 1.51 + 1.52 + // with only one space as content 1.53 + str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>'; 1.54 + expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>'; 1.55 + 1.56 + doc = parser.parseFromString(str,"application/xml"); 1.57 + result = serializer.serializeToString(doc); 1.58 + result = result.replace(/\r\n/mg, "\n"); 1.59 + is(result, expected, "serialization of a link element with only one space as content, inside an xml document"); 1.60 + 1.61 + // let's remove the content 1.62 + str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> <!-- child nodes --> \ndeleted content<content xmlns=""/> </link>\n</doc>'; 1.63 + expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; 1.64 + 1.65 + doc = parser.parseFromString(str,"application/xml"); 1.66 + doc.documentElement.firstElementChild.textContent = ''; 1.67 + result = serializer.serializeToString(doc); 1.68 + result = result.replace(/\r\n/mg, "\n"); 1.69 + is(result, expected, "serialization of a link element on which we removed dynamically the content, inside an xml document"); 1.70 + 1.71 + // with no content but an ended tag 1.72 + str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"></link>\n</doc>'; 1.73 + expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; 1.74 + 1.75 + doc = parser.parseFromString(str,"application/xml"); 1.76 + result = serializer.serializeToString(doc); 1.77 + result = result.replace(/\r\n/mg, "\n"); 1.78 + is(result, expected, "serialization of a link element with no content but with an ended tag, inside an xml document"); 1.79 + 1.80 + // with no content 1.81 + str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"/>\n</doc>'; 1.82 + expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>'; 1.83 + 1.84 + doc = parser.parseFromString(str,"application/xml"); 1.85 + result = serializer.serializeToString(doc); 1.86 + result = result.replace(/\r\n/mg, "\n"); 1.87 + is(result, expected, "serialization of a link element with no content, inside an xml document"); 1.88 + 1.89 + 1.90 + doc = $("testframe").contentDocument; 1.91 + encoder.init(doc, "text/html", de.OutputLFLineBreak); 1.92 + encoder.setCharset("UTF-8"); 1.93 + result = encoder.encodeToString(); 1.94 + expected = '<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n <title>Test</title>\n'; 1.95 + expected += ' <link rel=\"Top\" href=\"\"> '; 1.96 + expected += ' </head><body>foo \n\n\n <p>Hello world</p>\n</body></html>'; 1.97 + is(result, expected, "serialization of a link element with content, inside an html document"); 1.98 + 1.99 + doc = $("testframe2").contentDocument; 1.100 + encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak); 1.101 + encoder.setCharset("UTF-8"); 1.102 + result = encoder.encodeToString(); 1.103 + expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'; 1.104 + 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'; 1.105 + expected += ' <link rel="Top" href=""> foo </link>\n'; 1.106 + expected += '\n</head>\n<body>\n <p>Hello world</p>\n</body>\n</html>'; 1.107 + is(result, expected, "serialization of a link element with content, inside an xhtml document"); 1.108 + 1.109 + SimpleTest.finish(); 1.110 +} 1.111 + 1.112 + 1.113 +SimpleTest.waitForExplicitFinish(); 1.114 + 1.115 +addLoadEvent(testSerializer); 1.116 + 1.117 +</script> 1.118 +</pre> 1.119 +</body> 1.120 +</html> 1.121 + 1.122 +