1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.css;
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 public class CSSRuleListTest extends WebDriverTestCase {
29
30
31
32
33 @Test
34 @Alerts("TypeError")
35 public void ctor() throws Exception {
36 final String html = DOCTYPE_HTML
37 + "<html><body>\n"
38 + LOG_TEXTAREA
39 + "<script>\n"
40 + LOG_TEXTAREA_FUNCTION
41 + "try {\n"
42 + " var rule = new CSSRuleList();\n"
43 + " log(rule);\n"
44 + "} catch(e) { logEx(e); }\n"
45 + "</script></body></html>";
46
47 loadPageVerifyTextArea2(html);
48 }
49
50
51
52
53 @Test
54 @Alerts({"1", "[object CSSStyleRule]"})
55 public void ruleList() throws Exception {
56 final String html = DOCTYPE_HTML
57 + "<html><head>\n"
58 + "<style>\n"
59 + " BODY { font-size: 1234px; }\n"
60 + "</style>\n"
61 + "<script>\n"
62 + LOG_TITLE_FUNCTION
63 + " function test() {\n"
64 + " var rules = document.styleSheets[0].cssRules;\n"
65 + " log(rules.length);\n"
66 + " log(rules[0]);\n"
67 + " }\n"
68 + "</script>\n"
69 + "</head><body onload='test()'>\n"
70 + "</body></html>";
71 loadPageVerifyTitle2(html);
72 }
73
74
75
76
77 @Test
78 @Alerts("undefined")
79 public void wrongRuleListAccess() throws Exception {
80 final String html = DOCTYPE_HTML
81 + "<html><head>\n"
82 + "<style>\n"
83 + " BODY { font-size: 1234px; }\n"
84 + "</style>\n"
85 + "<script>\n"
86 + LOG_TITLE_FUNCTION
87 + " function test() {\n"
88 + " var rules = document.styleSheets[0].cssRules;\n"
89 + " var r = rules[1];\n"
90 + " log(r);\n"
91 + " }\n"
92 + "</script>\n"
93 + "</head><body onload='test()'>\n"
94 + "</body></html>";
95 loadPageVerifyTitle2(html);
96 }
97
98
99
100
101 @Test
102 @Alerts("true")
103 public void has() throws Exception {
104 final String html = DOCTYPE_HTML
105 + "<html><head>\n"
106 + "<style>\n"
107 + " BODY { font-size: 1234px; }\n"
108 + "</style>\n"
109 + "<script>\n"
110 + LOG_TITLE_FUNCTION
111 + " function test() {\n"
112 + " var rules = document.styleSheets[0].cssRules;\n"
113 + " log(0 in rules);\n"
114 + " }\n"
115 + "</script>\n"
116 + "</head><body onload='test()'>\n"
117 + "</body></html>";
118 loadPageVerifyTitle2(html);
119 }
120
121
122
123
124 @Test
125 @Alerts({"0", "undefined"})
126 public void ruleListUnknownAtRule() throws Exception {
127 final String html = DOCTYPE_HTML
128 + "<html><head>\n"
129 + "<style>\n"
130 + " @UnknownAtRule valo-animate-in-fade {0 {opacity: 0;}}\n"
131 + "</style>\n"
132 + "<script>\n"
133 + LOG_TITLE_FUNCTION
134 + " function test() {\n"
135 + " var rules = document.styleSheets[0].cssRules;\n"
136 + " log(rules.length);\n"
137 + " log(rules[0]);\n"
138 + " }\n"
139 + "</script>\n"
140 + "</head><body onload='test()'>\n"
141 + "</body></html>";
142 loadPageVerifyTitle2(html);
143 }
144
145
146
147
148 @Test
149 @Alerts({"1", "[object CSSKeyframesRule]"})
150 public void ruleListKeyframes() throws Exception {
151 final String html = DOCTYPE_HTML
152 + "<html><head>\n"
153 + "<style>\n"
154 + " @keyframes mymove {from {top: 0px;} to {top: 200px;}}\n"
155 + "</style>\n"
156 + "<script>\n"
157 + LOG_TITLE_FUNCTION
158 + " function test() {\n"
159 + " var rules = document.styleSheets[0].cssRules;\n"
160 + " log(rules.length);\n"
161 + " log(rules[0]);\n"
162 + " }\n"
163 + "</script>\n"
164 + "</head><body onload='test()'>\n"
165 + "</body></html>";
166 loadPageVerifyTitle2(html);
167 }
168
169
170
171
172 @Test
173 @Alerts({"1", "false", "true", "false", "false"})
174 public void in() throws Exception {
175 final String html = DOCTYPE_HTML
176 + "<html><head>\n"
177 + "<style>\n"
178 + " BODY { font-size: 1234px; }\n"
179 + "</style>\n"
180 + "<script>\n"
181 + LOG_TITLE_FUNCTION
182 + " function test() {\n"
183 + " var rules = document.styleSheets[0].cssRules;\n"
184 + " log(rules.length);\n"
185 + " log(-1 in rules);\n"
186 + " log(0 in rules);\n"
187 + " log(1 in rules);\n"
188 + " log(42 in rules);\n"
189 + " }\n"
190 + "</script>\n"
191 + "</head><body onload='test()'>\n"
192 + "</body></html>";
193 loadPageVerifyTitle2(html);
194 }
195
196
197
198
199 @Test
200 @Alerts("[object CSSStyleRule]")
201 public void index() throws Exception {
202 final String html = DOCTYPE_HTML
203 + "<html><head>\n"
204 + "<style>\n"
205 + " BODY { font-size: 1234px; }\n"
206 + "</style>\n"
207 + "<script>\n"
208 + LOG_TITLE_FUNCTION
209 + " function test() {\n"
210 + " var rules = document.styleSheets[0].cssRules;\n"
211 + " log(rules[0]);\n"
212 + " }\n"
213 + "</script>\n"
214 + "</head><body onload='test()'>\n"
215 + "</body></html>";
216 loadPageVerifyTitle2(html);
217 }
218
219
220
221
222 @Test
223 @Alerts("undefined")
224 public void indexNotFound() throws Exception {
225 final String html = DOCTYPE_HTML
226 + "<html><head>\n"
227 + "<style>\n"
228 + " BODY { font-size: 1234px; }\n"
229 + "</style>\n"
230 + "<script>\n"
231 + LOG_TITLE_FUNCTION
232 + " function test() {\n"
233 + " var rules = document.styleSheets[0].cssRules;\n"
234 + " log(rules[17]);\n"
235 + " }\n"
236 + "</script>\n"
237 + "</head><body onload='test()'>\n"
238 + "</body></html>";
239 loadPageVerifyTitle2(html);
240 }
241
242
243
244
245 @Test
246 @Alerts("[object CSSStyleRule]")
247 public void item() throws Exception {
248 final String html = DOCTYPE_HTML
249 + "<html><head>\n"
250 + "<style>\n"
251 + " BODY { font-size: 1234px; }\n"
252 + "</style>\n"
253 + "<script>\n"
254 + LOG_TITLE_FUNCTION
255 + " function test() {\n"
256 + " var rules = document.styleSheets[0].cssRules;\n"
257 + " log(rules.item(0));\n"
258 + " }\n"
259 + "</script>\n"
260 + "</head><body onload='test()'>\n"
261 + "</body></html>";
262 loadPageVerifyTitle2(html);
263 }
264
265
266
267
268 @Test
269 @Alerts("null")
270 public void itemNotFound() throws Exception {
271 final String html = DOCTYPE_HTML
272 + "<html><head>\n"
273 + "<style>\n"
274 + " BODY { font-size: 1234px; }\n"
275 + "</style>\n"
276 + "<script>\n"
277 + LOG_TITLE_FUNCTION
278 + " function test() {\n"
279 + " var rules = document.styleSheets[0].cssRules;\n"
280 + " log(rules.item(17));\n"
281 + " }\n"
282 + "</script>\n"
283 + "</head><body onload='test()'>\n"
284 + "</body></html>";
285 loadPageVerifyTitle2(html);
286 }
287 }