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 public class StyleMediaTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 @Alerts(DEFAULT = {"[object StyleMedia]", "screen"},
34 FF = "undefined",
35 FF_ESR = "undefined")
36 public void type() 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(window.styleMedia);\n"
43 + " if (window.styleMedia) {\n"
44 + " log(window.styleMedia.type);\n"
45 + " }\n"
46 + " }\n"
47 + "</script></head><body onload='test()'>\n"
48 + "</body></html>";
49
50 loadPageVerifyTitle2(html);
51 }
52
53
54
55
56 @Test
57 @Alerts(DEFAULT = {"true", "true", "true", "false"},
58 FF = {},
59 FF_ESR = {})
60 public void matchMedium() throws Exception {
61 final String html = DOCTYPE_HTML
62 + "<html><head>\n"
63 + "<script>\n"
64 + LOG_TITLE_FUNCTION
65 + " function test() {\n"
66 + " if (window.styleMedia) {\n"
67 + " log(window.styleMedia.matchMedium('screen'));\n"
68 + " log(window.styleMedia.matchMedium('SCREEN'));\n"
69 + " log(window.styleMedia.matchMedium('screen, handheld'));\n"
70 + " log(window.styleMedia.matchMedium('handheld'));\n"
71 + " }\n"
72 + " }\n"
73 + "</script></head><body onload='test()'>\n"
74 + "</body></html>";
75
76 loadPageVerifyTitle2(html);
77 }
78
79
80
81
82 @Test
83 @Alerts(DEFAULT = {"true", "[object StyleMedia]", "[object StyleMedia]", "undefined", "[object StyleMedia]",
84 "false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
85 FF = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
86 "false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
87 FF_ESR = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
88 "false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"})
89 public void windowScope() throws Exception {
90 final String html = DOCTYPE_HTML
91 + "<html></body>\n"
92 + "<script>\n"
93 + LOG_TITLE_FUNCTION
94 + " log('styleMedia' in window);\n"
95 + " log(window.styleMedia);\n"
96 + " try { log(styleMedia); } catch(e) { logEx(e); };\n"
97 + " try { log(styleMedia.prototype); } catch(e) { logEx(e); };\n"
98 + " try { log(styleMedia.__proto__); } catch(e) { logEx(e); };\n"
99
100 + " log('StyleMedia' in window);\n"
101 + " log(window.StyleMedia);\n"
102 + " try { log(StyleMedia); } catch(e) { logEx(e); };\n"
103 + " try { log(StyleMedia.prototype); } catch(e) { logEx(e); };\n"
104 + " try { log(StyleMedia.__proto__); } catch(e) { logEx(e); };\n"
105 + "</script>\n"
106 + "</body></html>";
107
108 loadPageVerifyTitle2(html);
109 }
110 }