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