ap@webkit.org | ea9701a | 2007-11-25 09:45:09 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <title>bug 15919</title> |
| 5 | </head> |
| 6 | <body> |
| 7 | <p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=15919">bug 15919</a>: |
| 8 | XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end.</p> |
| 9 | <div id="log"></div> |
| 10 | |
| 11 | <script type="text/javascript"> |
| 12 | |
rniwa@webkit.org | 224c8b5 | 2012-08-04 01:13:22 +0000 | [diff] [blame] | 13 | if (window.testRunner) |
| 14 | testRunner.dumpAsText(); |
ap@webkit.org | ea9701a | 2007-11-25 09:45:09 +0000 | [diff] [blame] | 15 | |
| 16 | function log(message) { |
| 17 | var newChild = document.createElement("div"); |
| 18 | newChild.appendChild(document.createTextNode(message)); |
| 19 | document.getElementById("log").appendChild(newChild); |
| 20 | } |
| 21 | |
| 22 | function assertEquals(oExpected, oExpr, sWarning) { |
| 23 | oActual = eval(oExpr); |
| 24 | if(oExpected !== oActual) |
| 25 | log('FAIL: Expected "'+ oExpected+'" was: "'+oActual+'" - '+sWarning); |
| 26 | else |
| 27 | log('PASS: ' + oExpr + ' ' + sWarning); |
| 28 | } |
| 29 | |
| 30 | var oProc = new XSLTProcessor(); |
| 31 | |
| 32 | var oStylesheet = new DOMParser().parseFromString( |
| 33 | '<?xml version="1.0" encoding="UTF-8"?>' + |
| 34 | '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'+ |
| 35 | '<xsl:output method="xml" omit-xml-declaration="yes" />'+ |
| 36 | '<xsl:param name="text" select="\'default\'" />'+ |
| 37 | '<xsl:template match="/">'+ |
| 38 | '<div><xsl:value-of select="$text" /></div>'+ |
| 39 | '<br />'+ |
| 40 | '</xsl:template>'+ |
| 41 | '</xsl:stylesheet>', 'text/xml'); |
| 42 | |
| 43 | oProc.importStylesheet(oStylesheet); |
| 44 | var oResult = new DOMParser().parseFromString('<root />', 'text/xml'); |
| 45 | |
| 46 | oProc.setParameter('', 'text', 'Hello World!'); |
| 47 | |
| 48 | oResult = oProc.transformToFragment(oStylesheet, oResult); |
| 49 | |
| 50 | assertEquals(11, "oResult.nodeType", 'should of type DOCUMENT_FRAGMENT_NODE(11)') |
| 51 | assertEquals('Hello World!', "oProc.getParameter(null, 'text')", 'getParameter should return the correct value'); |
| 52 | assertEquals('div', "oResult.firstChild.nodeName", 'can have multiple children, firstchild should be the div'); |
| 53 | assertEquals('br', "oResult.lastChild.nodeName", 'can have multiple children, lastchild should be the br'); |
| 54 | assertEquals('Hello World!', "oResult.firstChild.textContent || oResult.firstChild.text", 'textContent should be set to parameter value'); |
| 55 | log("Done"); |
| 56 | </script> |
| 57 | </body> |
| 58 | </html> |