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.general;
16  
17  import java.util.ArrayList;
18  import java.util.Collection;
19  import java.util.Collections;
20  import java.util.List;
21  import java.util.Set;
22  
23  import org.htmlunit.TestCaseTest;
24  import org.htmlunit.WebDriverTestCase;
25  import org.htmlunit.junit.annotation.Alerts;
26  import org.junit.jupiter.api.Disabled;
27  import org.junit.jupiter.params.ParameterizedTest;
28  import org.junit.jupiter.params.provider.Arguments;
29  import org.junit.jupiter.params.provider.MethodSource;
30  
31  /**
32   * Test the host class constructors.
33   *
34   * @author Ronald Brill
35   */
36  @Disabled("Work in progress")
37  public class HostConstructorTest extends WebDriverTestCase {
38  
39      /**
40       * Returns the parameterized data.
41       * @return the parameterized data
42       * @throws Exception if an error occurs
43       */
44      public static Collection<Arguments> data() throws Exception {
45          final List<Arguments> list = new ArrayList<>();
46          final Set<String> classNames = TestCaseTest.getAllConfiguredJsClassNames();
47          final ArrayList<String> classNamesSorted = new ArrayList<>(classNames);
48          Collections.sort(classNamesSorted);
49  
50          for (final String className : classNamesSorted) {
51              list.add(Arguments.of(className));
52          }
53          return list;
54      }
55  
56      /**
57       * The default test.
58       * @throws Exception if an error occurs
59       */
60      @ParameterizedTest(name = "_{0}")
61      @MethodSource("data")
62      @Alerts("TypeError")
63      void test(final String className) throws Exception {
64          final String html = DOCTYPE_HTML
65                  + "<html>\n"
66                  + "<body>"
67                  + "<script>\n"
68                  + LOG_TITLE_FUNCTION
69  
70                  + "  try {\n"
71                  + "    log(new " + className + "());\n"
72                  + "  } catch(e) { logEx(e) }\n"
73                  + "</script>\n"
74                  + "</body></html>";
75  
76          loadPageVerifyTitle2(html);
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      protected boolean isWebClientCached() {
84          return true;
85      }
86  
87      @Alerts("[object AbortController]")
88      void _AbortController() throws Exception {
89          test("AbortController");
90      }
91  
92      @Alerts("[object Animation]")
93      void _Animation() throws Exception {
94          test("Animation");
95      }
96  
97      @Alerts("[object HTMLAudioElement]")
98      void _Audio() throws Exception {
99          test("Audio");
100     }
101 
102     @Alerts("[object AudioContext]")
103     void _AudioContext() throws Exception {
104         test("AudioContext");
105     }
106 
107     @Alerts(DEFAULT = "TypeError",
108             FF = "ReferenceError",
109             FF_ESR = "ReferenceError")
110     void _BatteryManager() throws Exception {
111         test("BatteryManager");
112     }
113 
114     @Alerts(DEFAULT = "TypeError",
115             FF = "ReferenceError",
116             FF_ESR = "ReferenceError")
117     void _BeforeInstallPromptEvent() throws Exception {
118         test("BeforeInstallPromptEvent");
119     }
120 
121     @Alerts("[object Blob]")
122     void _Blob() throws Exception {
123         test("Blob");
124     }
125 
126     @Alerts(DEFAULT = "ReferenceError",
127             FF = "TypeError",
128             FF_ESR = "TypeError")
129     void _CanvasCaptureMediaStream() throws Exception {
130         test("CanvasCaptureMediaStream");
131     }
132 
133     @Alerts(DEFAULT = "TypeError",
134             FF = "ReferenceError",
135             FF_ESR = "ReferenceError")
136     void _CanvasCaptureMediaStreamTrack() throws Exception {
137         test("CanvasCaptureMediaStreamTrack");
138     }
139 
140     @Alerts("[object Comment]")
141     void _Comment() throws Exception {
142         test("Comment");
143     }
144 
145     @Alerts(DEFAULT = "ReferenceError",
146             FF = "TypeError",
147             FF_ESR = "TypeError")
148     void _CSS2Properties() throws Exception {
149         test("CSS2Properties");
150     }
151 
152     @Alerts("[object CSSStyleSheet]")
153     void _CSSStyleSheet() throws Exception {
154         test("CSSStyleSheet");
155     }
156 
157     @Alerts("[object DataTransfer]")
158     void _DataTransfer() throws Exception {
159         test("DataTransfer");
160     }
161 
162     @Alerts("[object Document]")
163     void _Document() throws Exception {
164         test("Document");
165     }
166 
167     @Alerts("[object DocumentFragment]")
168     void _DocumentFragment() throws Exception {
169         test("DocumentFragment");
170     }
171 
172     @Alerts(DEFAULT = "TypeError",
173             FF = "ReferenceError",
174             FF_ESR = "ReferenceError")
175     void _DOMError() throws Exception {
176         test("DOMError");
177     }
178 
179     @Alerts("Error")
180     void _DOMException() throws Exception {
181         test("DOMException");
182     }
183 
184     @Alerts("matrix(1, 0, 0, 1, 0, 0)")
185     void _DOMMatrix() throws Exception {
186         test("DOMMatrix");
187     }
188 
189     @Alerts("matrix(1, 0, 0, 1, 0, 0)")
190     void _DOMMatrixReadOnly() throws Exception {
191         test("DOMMatrixReadOnly");
192     }
193 
194     @Alerts("[object DOMParser]")
195     void _DOMParser() throws Exception {
196         test("DOMParser");
197     }
198 
199     @Alerts("[object DOMPoint]")
200     void _DOMPoint() throws Exception {
201         test("DOMPoint");
202     }
203 
204     @Alerts("[object DOMPointReadOnly]")
205     void _DOMPointReadOnly() throws Exception {
206         test("DOMPointReadOnly");
207     }
208 
209     @Alerts("[object DOMRect]")
210     void _DOMRect() throws Exception {
211         test("DOMRect");
212     }
213 
214     @Alerts("[object DOMRectReadOnly]")
215     void _DOMRectReadOnly() throws Exception {
216         test("DOMRectReadOnly");
217     }
218 
219     @Alerts("[object EventTarget]")
220     void _EventTarget() throws Exception {
221         test("EventTarget");
222     }
223 
224     @Alerts(DEFAULT = "TypeError",
225             FF = "ReferenceError",
226             FF_ESR = "ReferenceError")
227     void _External() throws Exception {
228         test("External");
229     }
230 
231     @Alerts(DEFAULT = "TypeError",
232             FF = "ReferenceError",
233             FF_ESR = "ReferenceError")
234     void _FederatedCredential() throws Exception {
235         test("FederatedCredential");
236     }
237 
238     @Alerts("[object FileReader]")
239     void _FileReader() throws Exception {
240         test("FileReader");
241     }
242 
243     @Alerts(DEFAULT = "ReferenceError",
244             FF = "TypeError",
245             FF_ESR = "TypeError")
246     void _FileSystem() throws Exception {
247         test("FileSystem");
248     }
249 
250     @Alerts(DEFAULT = "ReferenceError",
251             FF = "TypeError",
252             FF_ESR = "TypeError")
253     void _FileSystemDirectoryEntry() throws Exception {
254         test("FileSystemDirectoryEntry");
255     }
256 
257     @Alerts(DEFAULT = "ReferenceError",
258             FF = "TypeError",
259             FF_ESR = "TypeError")
260     void _FileSystemDirectoryReader() throws Exception {
261         test("FileSystemDirectoryReader");
262     }
263 
264     @Alerts(DEFAULT = "ReferenceError",
265             FF = "TypeError",
266             FF_ESR = "TypeError")
267     void _FileSystemEntry() throws Exception {
268         test("FileSystemEntry");
269     }
270 
271     @Alerts(DEFAULT = "ReferenceError",
272             FF = "TypeError",
273             FF_ESR = "TypeError")
274     void _FileSystemFileEntry() throws Exception {
275         test("FileSystemFileEntry");
276     }
277 
278     @Alerts(DEFAULT = "ReferenceError",
279             FF = "TypeError",
280             FF_ESR = "TypeError")
281     void _FontFaceSet() throws Exception {
282         test("FontFaceSet");
283     }
284 
285     @Alerts("[object FormData]")
286     void _FormData() throws Exception {
287         test("FormData");
288     }
289 
290     @Alerts("[object Headers]")
291     void _Headers() throws Exception {
292         test("Headers");
293     }
294 
295     @Alerts(DEFAULT = "[object InputDeviceCapabilities]",
296             FF = "ReferenceError",
297             FF_ESR = "ReferenceError")
298     void _InputDeviceCapabilities() throws Exception {
299         test("InputDeviceCapabilities");
300     }
301 
302     @Alerts(DEFAULT = "ReferenceError",
303             FF = "TypeError",
304             FF_ESR = "TypeError")
305     void _MediaKeyError() throws Exception {
306         test("MediaKeyError");
307     }
308 
309     @Alerts("[object MediaSource]")
310     void _MediaSource() throws Exception {
311         test("MediaSource");
312     }
313 
314     @Alerts("[object MediaStream]")
315     void _MediaStream() throws Exception {
316         test("MediaStream");
317     }
318 
319     @Alerts("[object MessageChannel]")
320     void _MessageChannel() throws Exception {
321         test("MessageChannel");
322     }
323 
324     @Alerts(DEFAULT = "ReferenceError",
325             FF = "TypeError",
326             FF_ESR = "TypeError")
327     void _MouseScrollEvent() throws Exception {
328         test("MouseScrollEvent");
329     }
330 
331     @Alerts(DEFAULT = "ReferenceError",
332             FF_ESR = "TypeError")
333     void _MutationEvent() throws Exception {
334         test("MutationEvent");
335     }
336 
337     @Alerts("ReferenceError")
338     void _NativeXPathNSResolver() throws Exception {
339         test("NativeXPathNSResolver");
340     }
341 
342     @Alerts(DEFAULT = "TypeError",
343             FF = "ReferenceError",
344             FF_ESR = "ReferenceError")
345     void _NetworkInformation() throws Exception {
346         test("NetworkInformation");
347     }
348 
349     @Alerts(DEFAULT = "TypeError",
350             FF = "ReferenceError",
351             FF_ESR = "ReferenceError")
352     void _PasswordCredential() throws Exception {
353         test("PasswordCredential");
354     }
355 
356     @Alerts("[object Path2D]")
357     void _Path2D() throws Exception {
358         test("Path2D");
359     }
360 
361     @Alerts(DEFAULT = "TypeError",
362             FF = "ReferenceError",
363             FF_ESR = "ReferenceError")
364     void _PaymentAddress() throws Exception {
365         test("PaymentAddress");
366     }
367 
368     @Alerts(DEFAULT = "TypeError",
369             FF = "ReferenceError",
370             FF_ESR = "ReferenceError")
371     void _PaymentRequest() throws Exception {
372         test("PaymentRequest");
373     }
374 
375     @Alerts(DEFAULT = "TypeError",
376             FF = "ReferenceError",
377             FF_ESR = "ReferenceError")
378     void _PaymentResponse() throws Exception {
379         test("PaymentResponse");
380     }
381 
382     @Alerts(DEFAULT = "TypeError",
383             FF = "ReferenceError",
384             FF_ESR = "ReferenceError")
385     void _PeriodicSyncManager() throws Exception {
386         test("PeriodicSyncManager");
387     }
388 
389     @Alerts(DEFAULT = "TypeError",
390             FF = "ReferenceError",
391             FF_ESR = "ReferenceError")
392     void _Presentation() throws Exception {
393         test("Presentation");
394     }
395 
396     @Alerts(DEFAULT = "TypeError",
397             FF = "ReferenceError",
398             FF_ESR = "ReferenceError")
399     void _PresentationAvailability() throws Exception {
400         test("PresentationAvailability");
401     }
402 
403     @Alerts(DEFAULT = "TypeError",
404             FF = "ReferenceError",
405             FF_ESR = "ReferenceError")
406     void _PresentationConnection() throws Exception {
407         test("PresentationConnection");
408     }
409 
410     @Alerts(DEFAULT = "TypeError",
411             FF = "ReferenceError",
412             FF_ESR = "ReferenceError")
413     void _PresentationConnectionAvailableEvent() throws Exception {
414         test("PresentationConnectionAvailableEvent");
415     }
416 
417     @Alerts(DEFAULT = "TypeError",
418             FF = "ReferenceError",
419             FF_ESR = "ReferenceError")
420     void _PresentationConnectionCloseEvent() throws Exception {
421         test("PresentationConnectionCloseEvent");
422     }
423 
424     @Alerts(DEFAULT = "TypeError",
425             FF = "ReferenceError",
426             FF_ESR = "ReferenceError")
427     void _PresentationRequest() throws Exception {
428         test("PresentationRequest");
429     }
430 
431     @Alerts("")
432     void _Range() throws Exception {
433         test("Range");
434     }
435 
436     @Alerts("[object ReadableStream]")
437     void _ReadableStream() throws Exception {
438         test("ReadableStream");
439     }
440 
441     @Alerts(DEFAULT = "TypeError",
442             FF = "ReferenceError",
443             FF_ESR = "ReferenceError")
444     void _RemotePlayback() throws Exception {
445         test("RemotePlayback");
446     }
447 
448     @Alerts("[object Response]")
449     void _Response() throws Exception {
450         test("Response");
451     }
452 
453     @Alerts("[object RTCPeerConnection]")
454     void _RTCPeerConnection() throws Exception {
455         test("RTCPeerConnection");
456     }
457 
458     @Alerts(DEFAULT = "[object RTCSessionDescription]",
459             FF = "TypeError",
460             FF_ESR = "TypeError")
461     void _RTCSessionDescription() throws Exception {
462         test("RTCSessionDescription");
463     }
464 
465     @Alerts("[object SpeechSynthesisUtterance]")
466     void _SpeechSynthesisUtterance() throws Exception {
467         test("SpeechSynthesisUtterance");
468     }
469 
470     @Alerts("ReferenceError")
471     void _StyleMedia() throws Exception {
472         test("StyleMedia");
473     }
474 
475     @Alerts(DEFAULT = "TypeError",
476             FF = "ReferenceError",
477             FF_ESR = "ReferenceError")
478     void _SyncManager() throws Exception {
479         test("SyncManager");
480     }
481 
482     @Alerts("[object Text]")
483     void _Text() throws Exception {
484         test("Text");
485     }
486 
487     @Alerts("[object TextDecoder]")
488     void _TextDecoder() throws Exception {
489         test("TextDecoder");
490     }
491 
492     @Alerts("[object TextEncoder]")
493     void _TextEncoder() throws Exception {
494         test("TextEncoder");
495     }
496 
497     @Alerts(DEFAULT = "TypeError",
498             FF_ESR = "ReferenceError")
499     void _TextEvent() throws Exception {
500         test("TextEvent");
501     }
502 
503     @Alerts(DEFAULT = "ReferenceError",
504             FF = "TypeError",
505             FF_ESR = "TypeError")
506     void _TimeEvent() throws Exception {
507         test("TimeEvent");
508     }
509 
510     @Alerts(DEFAULT = "TypeError",
511             FF = "ReferenceError",
512             FF_ESR = "ReferenceError")
513     void _Touch() throws Exception {
514         test("Touch");
515     }
516 
517     @Alerts(DEFAULT = "TypeError",
518             FF = "ReferenceError",
519             FF_ESR = "ReferenceError")
520     void _TouchEvent() throws Exception {
521         test("TouchEvent");
522     }
523 
524     @Alerts(DEFAULT = "TypeError",
525             FF = "ReferenceError",
526             FF_ESR = "ReferenceError")
527     void _TouchList() throws Exception {
528         test("TouchList");
529     }
530 
531     @Alerts("")
532     void _URLSearchParams() throws Exception {
533         test("URLSearchParams");
534     }
535 
536     @Alerts(DEFAULT = "[object SpeechGrammar]",
537             FF = "ReferenceError",
538             FF_ESR = "ReferenceError")
539     void _webkitSpeechGrammar() throws Exception {
540         test("webkitSpeechGrammar");
541     }
542 
543     @Alerts(DEFAULT = "[object SpeechGrammarList]",
544             FF = "ReferenceError",
545             FF_ESR = "ReferenceError")
546     void _webkitSpeechGrammarList() throws Exception {
547         test("webkitSpeechGrammarList");
548     }
549 
550     @Alerts(DEFAULT = "[object SpeechRecognition]",
551             FF = "ReferenceError",
552             FF_ESR = "ReferenceError")
553     void _webkitSpeechRecognition() throws Exception {
554         test("webkitSpeechRecognition");
555     }
556 
557     @Alerts(DEFAULT = "TypeError",
558             FF = "ReferenceError",
559             FF_ESR = "ReferenceError")
560     void _webkitSpeechRecognitionError() throws Exception {
561         test("webkitSpeechRecognitionError");
562     }
563 
564     @Alerts(DEFAULT = "TypeError",
565             FF = "ReferenceError",
566             FF_ESR = "ReferenceError")
567     void _webkitSpeechRecognitionEvent() throws Exception {
568         test("WebkitSpeechRecognitionEvent");
569     }
570 
571     @Alerts("[object XMLHttpRequest]")
572     void _XMLHttpRequest() throws Exception {
573         test("XMLHttpRequest");
574     }
575 
576     @Alerts("[object XMLSerializer]")
577     void _XMLSerializer() throws Exception {
578         test("XMLSerializer");
579     }
580 
581     @Alerts("[object XPathEvaluator]")
582     void _XPathEvaluator() throws Exception {
583         test("XPathEvaluator");
584     }
585 
586     @Alerts("[object XSLTProcessor]")
587     void _XSLTProcessor() throws Exception {
588         test("XSLTProcessor");
589     }
590 }