View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
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   * Tests for {@link OfflineAudioCompletionEvent}.
23   *
24   * @author Ronald Brill
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              // TODO all properties
36              + "  }\n";
37  
38      /**
39       * @throws Exception if the test fails
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       * @throws Exception if the test fails
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       * @throws Exception if the test fails
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      * @throws Exception if the test fails
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      * @throws Exception if the test fails
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      * @throws Exception if the test fails
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      * @throws Exception if the test fails
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             // + "        'data': 'mozart'\n"
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      * @throws Exception if the test fails
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      * @throws Exception if the test fails
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      * @throws Exception if the test fails
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 }