Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / xsl / xslt-processor.html
blob8fd877c4b3b06779d94a5eaf29c3eb72a15f0282
1 <html>
2 <head>
3 <STYLE>
4 pre { border:1px solid blue }
5 span { font-weight: bold }
6 .success { color: green; }
7 .failure { color: red; }
8 </STYLE>
9 </head>
10 <body id="body">
12 <script>
13 if (window.testRunner)
14 testRunner.dumpAsText();
16 var requester = new XMLHttpRequest();
17 var processor = new XSLTProcessor();
18 var serializer = new XMLSerializer();
20 var sectionId = 0;
21 var testId = 0;
23 function addSectionHeader(name) {
24 sectionId++;
25 document.writeln("<br><span>" + sectionId + ".0 " + name + ":</span><br><br>");
26 testId = 0;
29 function addResultExpectException(name, func) {
30 try {
31 var result = func();
32 addStringResult(testname, "****Failure**** (expected exception, instead got result: \"" + result + "\")", "failure");
33 } catch (e) {
34 // FIXME: probably should check exception type
35 addSuccessResult(testname);
39 function addResultExpectValueWhenSerialized(name, value, expectedValue) {
40 var serializedValue;
41 if (value)
42 serializedValue = serializer.serializeToString(value);
43 if (serializedValue == expectedValue)
44 addSuccessResult(name);
45 else
46 addFailureResult(name, expectedValue, serializedValue);
49 function addResultExpectValue(name, value, expectedValue) {
50 if (value == expectedValue)
51 addSuccessResult(name);
52 else
53 addFailureResult(name, expectedValue, value);
56 function getXMLDocument(name)
58 requester.open("GET", name, false);
59 requester.send(null);
60 return requester.responseXML;
63 function addStringResult(name, result, cssClass)
65 testId++;
66 var testNumberString = "" + sectionId + "." + testId
67 var testIdString = "id" + testNumberString;
68 document.writeln("<span>" + testNumberString + " " + name + ":</span>");
69 document.writeln("<pre id=\"" + testIdString + "\" class=\"" + cssClass + "\">@@NO VALUE@@</pre>");
70 document.getElementById(testIdString).firstChild.nodeValue = result;
73 function addFailureResult(name, expectedValue, actual)
75 addStringResult(name, "****Failure**** (expected: \"" + expectedValue + "\" actual: \"" + actual + "\")", "failure");
78 function addSuccessResult(name)
80 addStringResult(name, "Success", "success");
83 function addXMLResult(name, result)
85 var str;
86 if (result)
87 str = serializer.serializeToString(result);
88 addStringResult(name, str);
91 var xml = getXMLDocument("resources/xslt-text.xml");
92 addXMLResult("original xml", xml);
93 var xsl1 = getXMLDocument("resources/xslt-text.xsl");
94 addXMLResult("xsl1", xsl1);
95 var xsl2 = getXMLDocument("resources/xslt-enc.xsl");
96 addXMLResult("xsl2", xsl2);
100 // 1.0 void importStylesheet(in DOMNode style);
101 addSectionHeader("void importStylesheet(in DOMNode style)");
102 // 1.1 Import two different stylesheets (last one wins)
104 processor.importStylesheet(xsl1);
105 processor.importStylesheet(xsl2);
106 var newXML = processor.transformToDocument(xml);
107 addXMLResult("Import two different stylesheets", newXML);
109 // 1.2 Import same stylesheet twice
111 processor.reset();
112 processor.importStylesheet(xsl1);
113 processor.importStylesheet(xsl1);
115 var newXML = processor.transformToDocument(xml);
116 addXMLResult("Import same stylesheet twice", newXML);
118 // 1.3 Import undefined stylesheet
120 processor.reset();
121 var testname = "Import undefined stylesheet";
122 addResultExpectException(testname, function () { return processor.importStylesheet(undefined); } );
124 // 1.4 Import invalid stylesheet (not wellformed xlst)
126 processor.reset();
127 var testName = "Import invalid stylesheet";
128 addResultExpectException(testname, function () { return processor.importStylesheet(xml); } );
130 // 1.5 Don't import stylesheet
132 processor.reset();
133 var newXML = processor.transformToDocument(xml);
134 addResultExpectValueWhenSerialized("Don't import stylesheet", newXML, undefined);
138 // 2.0 DOMDocumentFragment transformToFragment(in DOMNode source, in DOMDocument output);
139 addSectionHeader("DOMDocumentFragment transformToFragment(in DOMNode source, in DOMDocument output)");
140 // 2.1 fragment with undefined source
142 processor.reset();
143 processor.importStylesheet(xsl1);
144 var ownerDocument = document.implementation.createDocument("", "test", null);
145 var testname = "fragment with undefined source";
146 addResultExpectException(testname, function () { return processor.transformToFragment(undefined, ownerDocument); } );
148 // 2.2 fragment with undefined output document
150 ownerDocument = document.implementation.createDocument("", "test", null);
151 var testname = "fragment with undefined output document";
152 addResultExpectException(testname, function () { return processor.transformToFragment(xml, undefined); });
154 // 2.3 use non-DOMDocument output parameter
156 var testname = "use non-DOMDocument output parameter";
157 addResultExpectException(testname, function () { return processor.transformToFragment(xml, "error"); } );
159 // 2.4 transform to same fragment twice
161 ownerDocument = document.implementation.createDocument("", "test", null);
162 var secondDocument = document.implementation.createDocument("", "test", null);
163 newFragment = processor.transformToFragment(xml, ownerDocument);
164 var secondFragment = processor.transformToFragment(xml, secondDocument);
165 addResultExpectValueWhenSerialized("transform to same fragment twice", secondFragment, serializer.serializeToString(newFragment));
168 // 2.5 transform to text
169 // 2.6 fragment using passed parameters
170 var paramXSL = getXMLDocument("resources/xslt-param.xsl");
171 var paramXML = getXMLDocument("resources/xslt-param.xml");
173 var paramProcessor = new XSLTProcessor;
174 paramProcessor.importStylesheet(paramXSL);
175 paramProcessor.setParameter(null, "param", "SUCCESS");
177 var ownerDocument = document.implementation.createDocument("", "test", null);
178 var fragment = paramProcessor.transformToFragment(paramXML, ownerDocument);
179 addResultExpectValueWhenSerialized("transformed fragment containing only text", fragment, "SUCCESS");
180 addResultExpectValue("fragment using passed parameters", fragment.firstChild.nodeValue, "SUCCESS");
184 // 3.0 DOMDocument transformToDocument(in DOMNode source);
185 addSectionHeader("DOMDocument transformToDocument(in DOMNode source)");
187 // 3.1 document from undefined source
189 processor.reset();
190 processor.importStylesheet(xsl1);
191 addResultExpectException("document from undefined source", function () { return processor.transformToDocument(undefined); } );
193 // 3.2 transform twice
195 processor.reset();
196 processor.importStylesheet(xsl1);
197 var newXML = processor.transformToDocument(xml);
198 var newerXML = processor.transformToDocument(xml);
199 addResultExpectValueWhenSerialized("transform twice", newXML, serializer.serializeToString(newerXML));
204 // 4.0 void setParameter(in DOMString namespaceURI, in DOMString localName, in Value value);
205 addSectionHeader("void setParameter(in DOMString namespaceURI, in DOMString localName, in Value value)");
206 processor.reset();
208 // 4.1 pass setParameter same localname, different namespaces
209 processor.setParameter("foo", "foo", "Success");
210 processor.setParameter("bar", "foo", "Failure");
211 var testname = "pass setParameter same localname, different namespaces";
212 addResultExpectValue(testname, processor.getParameter("foo", "foo"), "Success");
214 // 4.2 pass undefined namespace
216 processor.setParameter(undefined, "foo", "Success");
217 addResultExpectValue("pass undefined namespace", processor.getParameter(undefined, "foo"), "Success");
219 // 4.3 pass setParameter an undefined name
221 var testname = "pass setParameter an undefined name";
222 processor.setParameter(undefined, undefined , "Success");
223 addResultExpectValue(testname, processor.getParameter(undefined, undefined), "Success");
225 // 4.4 pass undefined value
227 processor.setParameter(undefined, "foo", undefined);
228 var testname = "pass undefined value to setParameter";
229 addResultExpectValue(testname, processor.getParameter(undefined, "foo"), "undefined");
232 // 4.5 pass unsupported value to setParameter (object, for instance?)
234 var testname = "pass unsupported value to setParameter";
235 addResultExpectException(testname, function () { return processor.setParameter(undefined, "invalid" , new Array()); } );
238 // 5.0 Value getParameter(in DOMString namespaceURI, in DOMString localName);
239 addSectionHeader("Value getParameter(in DOMString namespaceURI, in DOMString localName)");
241 // 5.1 pass undefined name
243 var testname = "pass getParameter an undefined name";
244 addResultExpectValue(testname, processor.getParameter(undefined, undefined), "Success");
246 // 5.2 pass getParameter a name which has not been set
248 var testname = "pass getParameter a name which has not been set";
249 addResultExpectValue(testname, processor.getParameter(undefined, "hasnotbeenset"), null);
251 // 5.3 verify getParameter actually gets (and set sets)
252 processor.setParameter(null, "test", "testValue");
253 var testname = "verify getParameter actually gets (and set sets)";
254 addResultExpectValue(testname, processor.getParameter(null, "test"), "testValue");
258 // 6.0 void removeParameter(in DOMString namespaceURI, in DOMString localName);
259 addSectionHeader("void removeParameter(in DOMString namespaceURI, in DOMString localName)");
260 // 6.1 pass removeParameter same localname, different namespaces
262 processor.setParameter("foo", "foo", "Success");
263 processor.setParameter("bar", "foo", "Failure");
264 var testname = "pass removeParameter same localname, different namespaces";
265 addResultExpectValue(testname, processor.getParameter("foo", "foo"), "Success");
267 // 6.2 pass undefined namespace
269 processor.setParameter(undefined, "test", "testValue");
270 processor.removeParameter(undefined, "test");
271 var testname = "verify removeParameter actually removes using undefined namespace";
272 addResultExpectValue(testname, processor.getParameter(null, "test"), null);
274 // 6.3 pass removeParameter undefined name
276 processor.setParameter(undefined, "undefined", "Success");
277 processor.removeParameter(undefined, undefined);
278 var testname = "pass removeParameter undefined name";
279 addResultExpectValue(testname, processor.getParameter(undefined, "undefined"), null);
281 // 6.4 pass removeParameter a name which has not been set
283 processor.removeParameter(undefined, "neverbeensetforremove");
284 addResultExpectValue("pass removeParameter a name which has not been set", "Success", "Success");
286 // 6.5 verify removeParameter actually removes
287 processor.setParameter(null, "test", "testValue");
288 processor.removeParameter(null, "test");
289 var testname = "verify removeParameter actually removes";
290 addResultExpectValue(testname, processor.getParameter(null, "test"), null);
294 // 7.0 void clearParameters();
295 addSectionHeader("void clearParameters()");
297 // 7.1 call, verify that parameters have been cleared
298 processor.setParameter(null, "test", "testValue");
299 processor.clearParameters();
300 var testname = "verify that clearParameters does";
301 addResultExpectValue(testname, processor.getParameter(null, "test"), null);
304 // 8.0 void reset();
305 addSectionHeader("void reset()");
306 processor = new XSLTProcessor();
307 processor.importStylesheet(xsl1);
308 processor.setParameter(null, "test", "testValue");
309 processor.reset();
311 // 8.1 call, verify that parameters are cleared after reset()
312 var testname = "verify that parameters have been cleared";
313 addResultExpectValue(testname, processor.getParameter(null, "test"), null);
315 // 8.2 call, verify that stylesheet has been cleared after reset()
316 var testname = "verify that stylesheet has been cleared";
317 var resultDocument = processor.transformToDocument(xml);
318 addResultExpectValueWhenSerialized(testname, resultDocument, undefined);
320 </script>
322 </body>
323 </html>