23
23
import com .gargoylesoftware .htmlunit .WebDriverTestCase ;
24
24
import com .gargoylesoftware .htmlunit .junit .BrowserRunner ;
25
25
import com .gargoylesoftware .htmlunit .junit .BrowserRunner .Alerts ;
26
+ import com .gargoylesoftware .htmlunit .junit .BrowserRunner .HtmlUnitNYI ;
26
27
import com .gargoylesoftware .htmlunit .util .MimeType ;
27
28
28
29
/**
@@ -38,28 +39,49 @@ public class XSLTProcessorTest extends WebDriverTestCase {
38
39
* @throws Exception if the test fails
39
40
*/
40
41
@ Test
41
- @ Alerts ("exception" )
42
+ @ Alerts (DEFAULT = "<html xmlns=\" http://www.w3.org/1999/xhtml\" >"
43
+ + "<head></head><body> <h2>My CD Collection</h2> "
44
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul> </body></html>" ,
45
+ FF = "<html xmlns=\" http://www.w3.org/1999/xhtml\" >"
46
+ + "<body><h2>My CD Collection</h2>"
47
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" ,
48
+ FF_ESR = "<html xmlns=\" http://www.w3.org/1999/xhtml\" >"
49
+ + "<body><h2>My CD Collection</h2>"
50
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" ,
51
+ IE = "exception" )
52
+ @ HtmlUnitNYI (CHROME = "<html><body><h2>My CD Collection</h2>"
53
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" ,
54
+ EDGE = "<html><body><h2>My CD Collection</h2>"
55
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" ,
56
+ FF = "<html><body><h2>My CD Collection</h2>"
57
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" ,
58
+ FF_ESR = "<html><body><h2>My CD Collection</h2>"
59
+ + "<ul><li>Empire Burlesque (Bob Dylan)</li></ul></body></html>" )
42
60
public void test () throws Exception {
43
61
final String html = "<html><head>\n "
44
62
+ "<script>\n "
45
63
+ LOG_TITLE_FUNCTION
64
+
65
+ + " function createXmlDocument() {\n "
66
+ + " return document.implementation.createDocument('', '', null);\n "
67
+ + " }\n "
68
+
69
+ + " function loadXMLDocument(url) {\n "
70
+ + " var xhttp = new XMLHttpRequest();\n "
71
+ + " xhttp.open('GET', url, false);\n "
72
+ + " xhttp.send();\n "
73
+ + " return xhttp.responseXML;\n "
74
+ + " }"
75
+
46
76
+ " function test() {\n "
47
77
+ " try {\n "
48
- + " var xmlDoc = createXmlDocument();\n "
49
- + " xmlDoc.async = false;\n "
50
- + " xmlDoc.load('" + URL_SECOND + "1');\n "
51
-
52
- + " var xslDoc;\n "
53
- + " xslDoc = createXmlDocument();\n "
54
- + " xslDoc.async = false;\n "
55
- + " xslDoc.load('" + URL_SECOND + "2');\n "
78
+ + " var xmlDoc = loadXMLDocument('" + URL_SECOND + "1');\n "
79
+ + " var xslDoc = loadXMLDocument('" + URL_SECOND + "2');\n "
56
80
57
81
+ " var processor = new XSLTProcessor();\n "
58
82
+ " processor.importStylesheet(xslDoc);\n "
59
83
+ " var newDocument = processor.transformToDocument(xmlDoc);\n "
60
- + " log(new XMLSerializer().serializeToString(newDocument.documentElement).length);\n "
61
- + " newDocument = processor.transformToDocument(xmlDoc.documentElement);\n "
62
- + " log(newDocument.documentElement);\n "
84
+ + " log(new XMLSerializer().serializeToString(newDocument.documentElement));\n "
63
85
+ " } catch(e) { log('exception'); }\n "
64
86
+ " }\n "
65
87
@@ -199,4 +221,68 @@ public void browserDetection() throws Exception {
199
221
+ "</body></html>" ;
200
222
loadPageVerifyTitle2 (html );
201
223
}
224
+
225
+ /**
226
+ * @throws Exception if the test fails
227
+ */
228
+ @ Test
229
+ @ Alerts (DEFAULT = {"preparation done" , "null" },
230
+ FF = {"preparation done" , "exception" },
231
+ FF_ESR = {"preparation done" , "exception" },
232
+ IE = "exception" )
233
+ @ HtmlUnitNYI (CHROME = {"preparation done" , "exception" },
234
+ EDGE = {"preparation done" , "exception" })
235
+ public void testSecurity () throws Exception {
236
+ final String html = "<html><head>\n "
237
+ + "<script>\n "
238
+ + LOG_TITLE_FUNCTION
239
+
240
+ + " function createXmlDocument() {\n "
241
+ + " return document.implementation.createDocument('', '', null);\n "
242
+ + " }\n "
243
+
244
+ + " function loadXMLDocument(url) {\n "
245
+ + " var xhttp = new XMLHttpRequest();\n "
246
+ + " xhttp.open('GET', url, false);\n "
247
+ + " xhttp.send();\n "
248
+ + " return xhttp.responseXML;\n "
249
+ + " }"
250
+
251
+ + " function test() {\n "
252
+ + " try {\n "
253
+ + " var xmlDoc = loadXMLDocument('" + URL_SECOND + "1');\n "
254
+ + " var xslDoc = loadXMLDocument('" + URL_SECOND + "2');\n "
255
+
256
+ + " var processor = new XSLTProcessor();\n "
257
+ + " processor.importStylesheet(xslDoc);\n "
258
+ + " log('preparation done');\n "
259
+ + " var newDocument = processor.transformToDocument(xmlDoc);\n "
260
+ + " log(newDocument);\n "
261
+ + " } catch(e) { log('exception'); }\n "
262
+ + " }\n "
263
+ + "</script></head>"
264
+ + "<body onload='test()'>\n "
265
+ + "</body></html>" ;
266
+
267
+ final String xml
268
+ = "<?xml version=\" 1.0\" encoding=\" ISO-8859-1\" ?>\n "
269
+ + "<s></s>" ;
270
+
271
+ final String xsl
272
+ = " <xsl:stylesheet version=\" 1.0\" xmlns:xsl=\" http://www.w3.org/1999/XSL/Transform\" "
273
+ + "xmlns:rt=\" http://xml.apache.org/xalan/java/java.lang.Runtime\" "
274
+ + "xmlns:ob=\" http://xml.apache.org/xalan/java/java.lang.Object\" >\r \n "
275
+ + " <xsl:template match='/'>\n "
276
+ + " <xsl:variable name='rtobject' select='rt:getRuntime()'/>\n "
277
+ + " <xsl:variable name=\" rtString\" select=\" ob:toString($rtobject)\" />\n "
278
+ + " <xsl:value-of select=\" $rtString\" />\n "
279
+ + " </xsl:template>\r \n "
280
+ + " </xsl:stylesheet>" ;
281
+
282
+ final MockWebConnection conn = getMockWebConnection ();
283
+ conn .setResponse (new URL (URL_SECOND , "1" ), xml , MimeType .TEXT_XML );
284
+ conn .setResponse (new URL (URL_SECOND , "2" ), xsl , MimeType .TEXT_XML );
285
+
286
+ loadPageVerifyTitle2 (html );
287
+ }
202
288
}
0 commit comments