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