1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import static org.htmlunit.javascript.host.xml.XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION;
18 import static org.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromFile;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.htmlunit.CollectingAlertHandler;
24 import org.htmlunit.MockWebConnection;
25 import org.htmlunit.SimpleWebTestCase;
26 import org.htmlunit.WebClient;
27 import org.htmlunit.junit.annotation.Alerts;
28 import org.htmlunit.util.MimeType;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34
35
36
37
38 public class HTMLCollection2Test extends SimpleWebTestCase {
39
40
41
42
43 @Test
44 @Alerts("1")
45 public void childNodes() throws Exception {
46 final String firstContent = DOCTYPE_HTML
47 + "<html><head><title>foo</title><script>\n"
48 + " function test() {\n"
49 + " var doc = " + callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
50 + " alert(doc.documentElement.childNodes.length);\n"
51 + " }\n"
52 + LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
53 + "</script></head><body onload='test()'>\n"
54 + "</body></html>";
55
56 final String secondContent = "<title>Immortality</title>";
57
58 final List<String> collectedAlerts = new ArrayList<>();
59 final WebClient client = getWebClient();
60 client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
61 final MockWebConnection conn = new MockWebConnection();
62 conn.setResponse(URL_FIRST, firstContent);
63 conn.setResponse(URL_SECOND, secondContent, MimeType.TEXT_XML);
64 client.setWebConnection(conn);
65
66 client.getPage(URL_FIRST);
67 assertEquals(getExpectedAlerts(), collectedAlerts);
68 }
69 }