1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.dom;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26
27
28
29 public class CommentTest extends WebDriverTestCase {
30
31
32
33
34 @Test
35 @Alerts("[object Comment]")
36 public void simpleScriptable() throws Exception {
37 final String html = DOCTYPE_HTML
38 + "<html><head>\n"
39 + "<script>\n"
40 + LOG_TITLE_FUNCTION
41 + "function test() {\n"
42 + " log(document.body.firstChild);\n"
43 + "}\n"
44 + "</script></head><body onload='test()'><!-- comment --></body></html>";
45
46 loadPageVerifyTitle2(html);
47 }
48
49
50
51
52 @Test
53 @Alerts({"after", "comment"})
54 public void textContent() throws Exception {
55 final String html = DOCTYPE_HTML
56 + "<html><body>\n"
57 + "<div id='it'><!--comment-->after</div>\n"
58 + "<script>\n"
59 + LOG_TITLE_FUNCTION
60 + "var node = document.getElementById('it');\n"
61 + "log(node.textContent);\n"
62 + "log(node.firstChild.textContent);\n"
63 + "</script></body></html>";
64
65 loadPageVerifyTitle2(html);
66 }
67
68
69
70
71 @Test
72 @Alerts({"after", "undefined"})
73 public void innerText() throws Exception {
74 final String html = DOCTYPE_HTML
75 + "<html><body>\n"
76 + "<div id='it'><!--comment-->after</div>\n"
77 + "<script>\n"
78 + LOG_TITLE_FUNCTION
79 + "var node = document.getElementById('it');\n"
80 + "log(node.innerText);\n"
81 + "log(node.firstChild.innerText);\n"
82 + "</script></body></html>";
83 loadPageVerifyTitle2(html);
84 }
85
86 private void property(final String property) throws Exception {
87 final String html = DOCTYPE_HTML
88 + "<html><body>\n"
89 + "<div id='it'><!--abcdefg-->after</div>\n"
90 + "<script>\n"
91 + LOG_TITLE_FUNCTION
92 + "var node = document.getElementById('it');\n"
93 + "log(node.firstChild." + property + ");\n"
94 + "</script></body></html>";
95 loadPageVerifyTitle2(html);
96 }
97
98
99
100
101 @Test
102 @Alerts("undefined")
103 public void id() throws Exception {
104 property("id");
105 }
106
107
108
109
110 @Test
111 @Alerts("undefined")
112 public void className() throws Exception {
113 property("className");
114 }
115
116
117
118
119 @Test
120 @Alerts("undefined")
121 public void tagName() throws Exception {
122 property("tagName");
123 }
124
125
126
127
128 @Test
129 @Alerts("undefined")
130 public void text() throws Exception {
131 property("text");
132 }
133
134
135
136
137 @Test
138 @Alerts("undefined")
139 public void document() throws Exception {
140 property("document");
141 }
142
143 }