test_bug401662.html (1601B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=401662 5 --> 6 <head> 7 <title>Test for Bug 401662</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=401662">Mozilla Bug 401662</a> 13 <p id="display"><iframe id="testframe2" 14 srcdoc="<html><body>foo<style style='display:block'>bar{}</style></body></html>"> 15 </iframe> 16 </p> 17 <div id="content" style="display: none"> 18 <iframe id="testframe" 19 srcdoc="<html><body>foo<style>bar</style></body></html>"> 20 </iframe> 21 </div> 22 <pre id="test"> 23 <script class="testbody" type="text/javascript"> 24 25 /** 26 * Test for Bug 401662 - don't serialize style elements in body into 27 * plaintext 28 */ 29 SimpleTest.waitForExplicitFinish(); 30 31 window.onload = function() { 32 const Cu = SpecialPowers.Cu; 33 34 var encoder = Cu.createDocumentEncoder("text/html"); 35 var doc = $("testframe").contentDocument; 36 encoder.init(doc, "text/plain", encoder.OutputBodyOnly); 37 encoder.setCharset("UTF-8"); 38 var out = encoder.encodeToString(); 39 is(out, "foo", "style content serialized in plaintext?"); 40 41 encoder = Cu.createDocumentEncoder("text/html"); 42 doc = $("testframe2").contentDocument; 43 encoder.init(doc, "text/plain", encoder.OutputBodyOnly); 44 encoder.setCharset("UTF-8"); 45 out = encoder.encodeToString(); 46 is(out.replace(/\r\n/g, "\n"), "foo\nbar{}", "visible style content NOT serialized in plaintext?"); 47 48 SimpleTest.finish(); 49 } 50 </script> 51 </pre> 52 </body> 53 </html>