1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host;
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
30 public class ScreenTest extends WebDriverTestCase {
31
32
33
34
35 @Test
36 @Alerts({"1040", "1040"})
37 public void availHeight() throws Exception {
38 testNumericProperty("availHeight");
39 }
40
41
42
43
44 @Test
45 @Alerts({"0", "0"})
46 public void availLeft() throws Exception {
47 testNumericProperty("availLeft");
48 }
49
50
51
52
53 @Test
54 @Alerts({"0", "0"})
55 public void availTop() throws Exception {
56 testNumericProperty("availTop");
57 }
58
59
60
61
62 @Test
63 @Alerts({"1920", "1920"})
64 public void availWidth() throws Exception {
65 testNumericProperty("availWidth");
66 }
67
68
69
70
71 @Test
72 @Alerts({"undefined", "1234"})
73 public void bufferDepth() throws Exception {
74 testNumericProperty("bufferDepth");
75 }
76
77
78
79
80 @Test
81 @Alerts({"24", "24"})
82 public void colorDepth() throws Exception {
83 testNumericProperty("colorDepth");
84 }
85
86
87
88
89 @Test
90 @Alerts({"undefined", "1234"})
91 public void deviceXDPI() throws Exception {
92 testNumericProperty("deviceXDPI");
93 }
94
95
96
97
98 @Test
99 @Alerts({"undefined", "1234"})
100 public void deviceYDPI() throws Exception {
101 testNumericProperty("deviceYDPI");
102 }
103
104
105
106
107 @Test
108 @Alerts({"undefined", "false"})
109 public void fontSmoothingEnabled() throws Exception {
110 testBooleanProperty("fontSmoothingEnabled");
111 }
112
113
114
115
116 @Test
117 @Alerts({"1080", "1080"})
118 public void height() throws Exception {
119 testNumericProperty("height");
120 }
121
122
123
124
125 @Test
126 @Alerts(DEFAULT = {"undefined", "1234"},
127 FF = {"0", "0"},
128 FF_ESR = {"0", "0"})
129 public void left() throws Exception {
130 testNumericProperty("left");
131 }
132
133
134
135
136 @Test
137 @Alerts(DEFAULT = {"undefined", "1234"},
138 FF = {"0", "0"},
139 FF_ESR = {"0", "0"})
140 public void top() throws Exception {
141 testNumericProperty("top");
142 }
143
144
145
146
147 @Test
148 @Alerts({"undefined", "1234"})
149 public void logicalXDPI() throws Exception {
150 testNumericProperty("logicalXDPI");
151 }
152
153
154
155
156 @Test
157 @Alerts({"undefined", "1234"})
158 public void logicalYDPI() throws Exception {
159 testNumericProperty("logicalYDPI");
160 }
161
162
163
164
165 @Test
166 @Alerts({"24", "24"})
167 public void pixelDepth() throws Exception {
168 testNumericProperty("pixelDepth");
169 }
170
171
172
173
174 @Test
175 @Alerts({"undefined", "1234"})
176 public void systemXDPI() throws Exception {
177 testNumericProperty("systemXDPI");
178 }
179
180
181
182
183 @Test
184 @Alerts({"undefined", "1234"})
185 public void systemYDPI() throws Exception {
186 testNumericProperty("systemYDPI");
187 }
188
189
190
191
192 @Test
193 @Alerts({"undefined", "1234"})
194 public void updateInterval() throws Exception {
195 testNumericProperty("updateInterval");
196 }
197
198
199
200
201 @Test
202 @Alerts({"1920", "1920"})
203 public void width() throws Exception {
204 testNumericProperty("width");
205 }
206
207 private void testBooleanProperty(final String prop) throws Exception {
208 final String html = DOCTYPE_HTML
209 + "<html><head>\n"
210 + " <script>\n"
211 + LOG_TITLE_FUNCTION
212 + " function doTest() {\n"
213 + " try {\n"
214 + " log(window.screen." + prop + ");\n"
215 + " } catch(e) { log('get exception') }\n"
216
217 + " try {\n"
218 + " window.screen." + prop + " = false;\n"
219 + " log(window.screen." + prop + ");\n"
220 + " } catch(e) { log('set exception') }\n"
221 + " }\n"
222 + " </script>\n"
223 + "</head>\n"
224 + "<body onload='doTest()'>\n"
225 + "</body></html>";
226
227 loadPageVerifyTitle2(html);
228 }
229
230 private void testNumericProperty(final String prop) throws Exception {
231 final String html = DOCTYPE_HTML
232 + "<html><head>\n"
233 + " <script>\n"
234 + LOG_TITLE_FUNCTION
235 + " function doTest() {\n"
236 + " try {\n"
237 + " log(window.screen." + prop + ");\n"
238 + " } catch(e) { log('get exception') }\n"
239
240 + " try {\n"
241 + " window.screen." + prop + " = 1234;\n"
242 + " log(window.screen." + prop + ");\n"
243 + " } catch(e) { log('set exception') }\n"
244 + " }\n"
245 + " </script>\n"
246 + "</head>\n"
247 + "<body onload='doTest()'>\n"
248 + "</body></html>";
249
250 loadPageVerifyTitle2(html);
251 }
252
253
254
255
256 @Test
257 @Alerts({"[object ScreenOrientation]", "landscape-primary", "0"})
258 public void orientation() throws Exception {
259 final String html = DOCTYPE_HTML
260 + "<html><head>\n"
261 + " <script>\n"
262 + LOG_TITLE_FUNCTION
263 + " function doTest() {\n"
264 + " try {\n"
265 + " var o = window.screen.orientation;"
266 + " log(o);\n"
267 + " log(o.type);\n"
268 + " log(o.angle);\n"
269 + " } catch(e) { logEx(e) }\n"
270 + " }\n"
271 + " </script>\n"
272 + "</head>\n"
273 + "<body onload='doTest()'>\n"
274 + "</body></html>";
275
276 loadPageVerifyTitle2(html);
277 }
278
279
280
281
282 @Test
283 @Alerts(DEFAULT = "undefined",
284 FF = "landscape-primary",
285 FF_ESR = "landscape-primary")
286 public void mozOrientation() throws Exception {
287 final String html = DOCTYPE_HTML
288 + "<html><head>\n"
289 + " <script>\n"
290 + LOG_TITLE_FUNCTION
291 + " function doTest() {\n"
292 + " try {\n"
293 + " var o = window.screen.mozOrientation;"
294 + " log(o);\n"
295 + " } catch(e) { logEx(e) }\n"
296 + " }\n"
297 + " </script>\n"
298 + "</head>\n"
299 + "<body onload='doTest()'>\n"
300 + "</body></html>";
301
302 loadPageVerifyTitle2(html);
303 }
304
305
306
307
308 @Test
309 @Alerts(DEFAULT = "false",
310 FF = "undefined",
311 FF_ESR = "undefined")
312 public void isExtended() throws Exception {
313 final String html = DOCTYPE_HTML
314 + "<html><head>\n"
315 + " <script>\n"
316 + LOG_TITLE_FUNCTION
317 + " function doTest() {\n"
318 + " try {\n"
319 + " log(window.screen.isExtended);\n"
320 + " } catch(e) { logEx(e) }\n"
321 + " }\n"
322 + " </script>\n"
323 + "</head>\n"
324 + "<body onload='doTest()'>\n"
325 + "</body></html>";
326
327 loadPageVerifyTitle2(html);
328 }
329 }