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