1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.event;
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 public class OfflineAudioCompletionEventTest extends WebDriverTestCase {
27
28 private static final String DUMP_EVENT_FUNCTION = " function dump(event) {\n"
29 + " log(event);\n"
30 + " log(event.type);\n"
31 + " log(event.bubbles);\n"
32 + " log(event.cancelable);\n"
33 + " log(event.composed);\n"
34
35
36 + " }\n";
37
38
39
40
41 @Test
42 @Alerts("TypeError")
43 public void create_ctor() throws Exception {
44 final String html = DOCTYPE_HTML
45 + "<html><head><script>\n"
46 + LOG_TITLE_FUNCTION
47 + " function test() {\n"
48 + " try {\n"
49 + " var event = new OfflineAudioCompletionEvent('oac');\n"
50 + " dump(event);\n"
51 + " } catch(e) { logEx(e) }\n"
52 + " }\n"
53 + DUMP_EVENT_FUNCTION
54 + "</script></head><body onload='test()'>\n"
55 + "</body></html>";
56
57 loadPageVerifyTitle2(html);
58 }
59
60
61
62
63 @Test
64 @Alerts("TypeError")
65 public void create_ctorWithoutType() throws Exception {
66 final String html = DOCTYPE_HTML
67 + "<html><head><script>\n"
68 + LOG_TITLE_FUNCTION
69 + " function test() {\n"
70 + " try {\n"
71 + " var event = new OfflineAudioCompletionEvent();\n"
72 + " dump(event);\n"
73 + " } catch(e) { logEx(e) }\n"
74 + " }\n"
75 + DUMP_EVENT_FUNCTION
76 + "</script></head><body onload='test()'>\n"
77 + "</body></html>";
78
79 loadPageVerifyTitle2(html);
80 }
81
82
83
84
85 @Test
86 @Alerts("TypeError")
87 public void create_ctorNumericType() throws Exception {
88 final String html = DOCTYPE_HTML
89 + "<html><head><script>\n"
90 + LOG_TITLE_FUNCTION
91 + " function test() {\n"
92 + " try {\n"
93 + " var event = new OfflineAudioCompletionEvent(42);\n"
94 + " dump(event);\n"
95 + " } catch(e) { logEx(e) }\n"
96 + " }\n"
97 + DUMP_EVENT_FUNCTION
98 + "</script></head><body onload='test()'>\n"
99 + "</body></html>";
100
101 loadPageVerifyTitle2(html);
102 }
103
104
105
106
107 @Test
108 @Alerts("TypeError")
109 public void create_ctorNullType() throws Exception {
110 final String html = DOCTYPE_HTML
111 + "<html><head><script>\n"
112 + LOG_TITLE_FUNCTION
113 + " function test() {\n"
114 + " try {\n"
115 + " var event = new OfflineAudioCompletionEvent(null);\n"
116 + " dump(event);\n"
117 + " } catch(e) { logEx(e) }\n"
118 + " }\n"
119 + DUMP_EVENT_FUNCTION
120 + "</script></head><body onload='test()'>\n"
121 + "</body></html>";
122
123 loadPageVerifyTitle2(html);
124 }
125
126
127
128
129 @Test
130 @Alerts("ReferenceError")
131 public void create_ctorUnknownType() throws Exception {
132 final String html = DOCTYPE_HTML
133 + "<html><head><script>\n"
134 + LOG_TITLE_FUNCTION
135 + " function test() {\n"
136 + " try {\n"
137 + " var event = new OfflineAudioCompletionEvent(unknown);\n"
138 + " dump(event);\n"
139 + " } catch(e) { logEx(e) }\n"
140 + " }\n"
141 + DUMP_EVENT_FUNCTION
142 + "</script></head><body onload='test()'>\n"
143 + "</body></html>";
144
145 loadPageVerifyTitle2(html);
146 }
147
148
149
150
151 @Test
152 @Alerts("TypeError")
153 public void create_ctorArbitraryType() throws Exception {
154 final String html = DOCTYPE_HTML
155 + "<html><head><script>\n"
156 + LOG_TITLE_FUNCTION
157 + " function test() {\n"
158 + " try {\n"
159 + " var event = new OfflineAudioCompletionEvent('HtmlUnitEvent');\n"
160 + " dump(event);\n"
161 + " } catch(e) { logEx(e) }\n"
162 + " }\n"
163 + DUMP_EVENT_FUNCTION
164 + "</script></head><body onload='test()'>\n"
165 + "</body></html>";
166
167 loadPageVerifyTitle2(html);
168 }
169
170
171
172
173 @Test
174 @Alerts("TypeError")
175 public void create_ctorAllDetails() throws Exception {
176 final String html = DOCTYPE_HTML
177 + "<html><head><script>\n"
178 + LOG_TITLE_FUNCTION
179 + " function test() {\n"
180 + " try {\n"
181 + " var event = new OfflineAudioCompletionEvent('oac', {\n"
182
183 + " });\n"
184 + " dump(event);\n"
185 + " } catch(e) { logEx(e) }\n"
186 + " }\n"
187 + DUMP_EVENT_FUNCTION
188 + "</script></head><body onload='test()'>\n"
189 + "</body></html>";
190
191 loadPageVerifyTitle2(html);
192 }
193
194
195
196
197 @Test
198 @Alerts("TypeError")
199 public void create_ctorAllDetailsMissingData() throws Exception {
200 final String html = DOCTYPE_HTML
201 + "<html><head><script>\n"
202 + LOG_TITLE_FUNCTION
203 + " function test() {\n"
204 + " try {\n"
205 + " var event = new OfflineAudioCompletionEvent('oac', {\n"
206 + " });\n"
207 + " dump(event);\n"
208 + " } catch(e) { logEx(e) }\n"
209 + " }\n"
210 + DUMP_EVENT_FUNCTION
211 + "</script></head><body onload='test()'>\n"
212 + "</body></html>";
213
214 loadPageVerifyTitle2(html);
215 }
216
217
218
219
220 @Test
221 @Alerts("TypeError")
222 public void create_ctorAllDetailsWrongData() throws Exception {
223 final String html = DOCTYPE_HTML
224 + "<html><head><script>\n"
225 + LOG_TITLE_FUNCTION
226 + " function test() {\n"
227 + " try {\n"
228 + " var event = new OfflineAudioCompletionEvent('oac', {\n"
229 + " 'data': ['Html', 'Unit']\n"
230 + " });\n"
231 + " dump(event);\n"
232 + " } catch(e) { logEx(e) }\n"
233 + " }\n"
234 + DUMP_EVENT_FUNCTION
235 + "</script></head><body onload='test()'>\n"
236 + "</body></html>";
237
238 loadPageVerifyTitle2(html);
239 }
240
241
242
243
244 @Test
245 @Alerts("true")
246 public void inWindow() throws Exception {
247 final String html = DOCTYPE_HTML
248 + "<html>\n"
249 + "<head>\n"
250 + " <script>\n"
251 + LOG_TITLE_FUNCTION
252 + " function test() {\n"
253 + " log('OfflineAudioCompletionEvent' in window);\n"
254 + " }\n"
255 + " </script>\n"
256 + "</head>\n"
257 + "<body onload='test()'>\n"
258 + "</body>\n"
259 + "</html>";
260
261 loadPageVerifyTitle2(html);
262 }
263 }