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