31ba7e281c11e96d5275a03b24bda9ac30d8f1f8
[WebKit-https.git] / LayoutTests / fast / events / event-creation.html
1 <head>
2 <script src="../js/resources/js-test-pre.js"></script>
3 </head>
4 <body>
5 <script>
6     description("This tests that document.createEvent is hooked up for all Event interfaces (and alternatives) and creates the right instance.")
7
8     // Event
9     shouldBeTrue("document.createEvent('Event') instanceof window.Event");
10     shouldBeTrue("document.createEvent('Event').constructor === window.Event");
11
12     // Events (Event alternative)
13     shouldBeTrue("document.createEvent('Events') instanceof window.Event");
14     shouldBeTrue("document.createEvent('Events').constructor === window.Event");
15
16     // HTMLEvents (Event alternative)
17     shouldBeTrue("document.createEvent('HTMLEvents') instanceof window.Event");
18     shouldBeTrue("document.createEvent('HTMLEvents').constructor === window.Event");
19
20     // BeforeLoadEvent
21     shouldBeTrue("document.createEvent('BeforeLoadEvent') instanceof window.BeforeLoadEvent");
22     shouldBeTrue("document.createEvent('BeforeLoadEvent') instanceof window.Event");
23     shouldBeTrue("document.createEvent('BeforeLoadEvent').constructor === window.BeforeLoadEvent");
24
25     // CompositionEvent
26     shouldBeTrue("document.createEvent('CompositionEvent') instanceof window.CompositionEvent");
27     shouldBeTrue("document.createEvent('CompositionEvent') instanceof window.Event");
28     shouldBeTrue("document.createEvent('CompositionEvent').constructor === window.CompositionEvent");
29
30     // CustomEvent
31     shouldBeTrue("document.createEvent('CustomEvent') instanceof window.CustomEvent");
32     shouldBeTrue("document.createEvent('CustomEvent') instanceof window.Event");
33     shouldBeTrue("document.createEvent('CustomEvent').constructor === window.CustomEvent");
34
35     // ErrorEvent
36     shouldBeTrue("document.createEvent('ErrorEvent') instanceof window.ErrorEvent");
37     shouldBeTrue("document.createEvent('ErrorEvent') instanceof window.Event");
38     shouldBeTrue("document.createEvent('ErrorEvent').constructor === window.ErrorEvent");
39
40     // HashChangeEvent
41     shouldBeTrue("document.createEvent('HashChangeEvent') instanceof window.HashChangeEvent");
42     shouldBeTrue("document.createEvent('HashChangeEvent') instanceof window.Event");
43     shouldBeTrue("document.createEvent('HashChangeEvent').constructor === window.HashChangeEvent");
44
45     // KeyboardEvent
46     shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.KeyboardEvent");
47     shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.UIEvent");
48     shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.Event");
49     shouldBeTrue("document.createEvent('KeyboardEvent').constructor === window.KeyboardEvent");
50
51     // KeyboardEvents (KeyboardEvent alternative)
52     shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.KeyboardEvent");
53     shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.UIEvent");
54     shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.Event");
55     shouldBeTrue("document.createEvent('KeyboardEvents').constructor === window.KeyboardEvent");
56
57     // MessageEvent
58     shouldBeTrue("document.createEvent('MessageEvent') instanceof window.MessageEvent");
59     shouldBeTrue("document.createEvent('MessageEvent') instanceof window.Event");
60     shouldBeTrue("document.createEvent('MessageEvent').constructor === window.MessageEvent");
61
62     // MouseEvent
63     shouldBeTrue("document.createEvent('MouseEvent') instanceof window.MouseEvent");
64     shouldBeTrue("document.createEvent('MouseEvent') instanceof window.UIEvent");
65     shouldBeTrue("document.createEvent('MouseEvent') instanceof window.Event");
66     shouldBeTrue("document.createEvent('MouseEvent').constructor === window.MouseEvent");
67
68     // MouseEvents (MouseEvent alternative)
69     shouldBeTrue("document.createEvent('MouseEvents') instanceof window.MouseEvent");
70     shouldBeTrue("document.createEvent('MouseEvents') instanceof window.UIEvent");
71     shouldBeTrue("document.createEvent('MouseEvents') instanceof window.Event");
72     shouldBeTrue("document.createEvent('MouseEvents').constructor === window.MouseEvent");
73
74     // MutationEvent
75     shouldBeTrue("document.createEvent('MutationEvent') instanceof window.MutationEvent");
76     shouldBeTrue("document.createEvent('MutationEvent') instanceof window.Event");
77     shouldBeTrue("document.createEvent('MutationEvent').constructor === window.MutationEvent");
78
79     // MutationEvents (MutationEvent alternative)
80     shouldBeTrue("document.createEvent('MutationEvents') instanceof window.MutationEvent");
81     shouldBeTrue("document.createEvent('MutationEvents') instanceof window.Event");
82     shouldBeTrue("document.createEvent('MutationEvents').constructor === window.MutationEvent");
83
84     // OverflowEvent
85     shouldBeTrue("document.createEvent('OverflowEvent') instanceof window.OverflowEvent");
86     shouldBeTrue("document.createEvent('OverflowEvent') instanceof window.Event");
87     shouldBeTrue("document.createEvent('OverflowEvent').constructor === window.OverflowEvent");
88
89     // PageTransitionEvent
90     shouldBeTrue("document.createEvent('PageTransitionEvent') instanceof window.PageTransitionEvent");
91     shouldBeTrue("document.createEvent('PageTransitionEvent') instanceof window.Event");
92     shouldBeTrue("document.createEvent('PageTransitionEvent').constructor === window.PageTransitionEvent");
93
94     // PopStateEvent
95     shouldBeTrue("document.createEvent('PopStateEvent') instanceof window.PopStateEvent");
96     shouldBeTrue("document.createEvent('PopStateEvent') instanceof window.Event");
97     shouldBeTrue("document.createEvent('PopStateEvent').constructor === window.PopStateEvent");
98
99     // ProgressEvent
100     shouldBeTrue("document.createEvent('ProgressEvent') instanceof window.ProgressEvent");
101     shouldBeTrue("document.createEvent('ProgressEvent') instanceof window.Event");
102     shouldBeTrue("document.createEvent('ProgressEvent').constructor === window.ProgressEvent");
103
104     // TextEvent
105     shouldBeTrue("document.createEvent('TextEvent') instanceof window.TextEvent");
106     shouldBeTrue("document.createEvent('TextEvent') instanceof window.UIEvent");
107     shouldBeTrue("document.createEvent('TextEvent') instanceof window.Event");
108     shouldBeTrue("document.createEvent('TextEvent').constructor === window.TextEvent");
109
110     // UIEvent
111     shouldBeTrue("document.createEvent('UIEvent') instanceof window.UIEvent");
112     shouldBeTrue("document.createEvent('UIEvent') instanceof window.Event");
113     shouldBeTrue("document.createEvent('UIEvent').constructor === window.UIEvent");
114
115     // UIEvents (UIEvent alternative)
116     shouldBeTrue("document.createEvent('UIEvents') instanceof window.UIEvent");
117     shouldBeTrue("document.createEvent('UIEvents') instanceof window.Event");
118     shouldBeTrue("document.createEvent('UIEvents').constructor === window.UIEvent");
119
120     // TransitionEvent
121     shouldBeTrue("document.createEvent('TransitionEvent') instanceof window.TransitionEvent");
122     shouldBeTrue("document.createEvent('TransitionEvent') instanceof window.Event");
123     shouldBeTrue("document.createEvent('TransitionEvent').constructor === window.TransitionEvent");
124
125     // WebKitAnimationEvent
126     shouldBeTrue("document.createEvent('WebKitAnimationEvent') instanceof window.WebKitAnimationEvent");
127     shouldBeTrue("document.createEvent('WebKitAnimationEvent') instanceof window.Event");
128     shouldBeTrue("document.createEvent('WebKitAnimationEvent').constructor === window.WebKitAnimationEvent");
129
130     // WebKitTransitionEvent
131     shouldBeTrue("document.createEvent('WebKitTransitionEvent') instanceof window.WebKitTransitionEvent");
132     shouldBeTrue("document.createEvent('WebKitTransitionEvent') instanceof window.Event");
133     shouldBeTrue("document.createEvent('WebKitTransitionEvent').constructor === window.WebKitTransitionEvent");
134
135     // WheelEvent
136     shouldBeTrue("document.createEvent('WheelEvent') instanceof window.WheelEvent");
137     shouldBeTrue("document.createEvent('WheelEvent') instanceof window.MouseEvent");
138     shouldBeTrue("document.createEvent('WheelEvent') instanceof window.UIEvent");
139     shouldBeTrue("document.createEvent('WheelEvent') instanceof window.Event");
140     shouldBeTrue("document.createEvent('WheelEvent').constructor === window.WheelEvent");
141
142     // XMLHttpRequestProgressEvent
143     shouldBeTrue("document.createEvent('XMLHttpRequestProgressEvent') instanceof window.XMLHttpRequestProgressEvent");
144     shouldBeTrue("document.createEvent('XMLHttpRequestProgressEvent') instanceof window.ProgressEvent");
145     shouldBeTrue("document.createEvent('XMLHttpRequestProgressEvent') instanceof window.Event");
146     shouldBeTrue("document.createEvent('XMLHttpRequestProgressEvent').constructor === window.XMLHttpRequestProgressEvent");
147
148     // StorageEvent
149     shouldBeTrue("document.createEvent('StorageEvent') instanceof window.StorageEvent");
150     shouldBeTrue("document.createEvent('StorageEvent') instanceof window.Event");
151     shouldBeTrue("document.createEvent('StorageEvent').constructor === window.StorageEvent");
152
153     // #if ENABLE(SVG)
154     // SVGEvents (Event alternative)
155     shouldBeTrue("document.createEvent('SVGEvents') instanceof window.Event");
156     shouldBeTrue("document.createEvent('SVGEvents').constructor === window.Event");
157
158     // #if ENABLE(SVG)
159     // SVGZoomEvent
160     shouldBeTrue("document.createEvent('SVGZoomEvent') instanceof window.SVGZoomEvent");
161     shouldBeTrue("document.createEvent('SVGZoomEvent') instanceof window.Event");
162     shouldBeTrue("document.createEvent('SVGZoomEvent').constructor === window.SVGZoomEvent");
163
164     // #if ENABLE(SVG)
165     // SVGZoomEvents (SVGZoomEvent alternative)
166     shouldBeTrue("document.createEvent('SVGZoomEvents') instanceof window.SVGZoomEvent");
167     shouldBeTrue("document.createEvent('SVGZoomEvents') instanceof window.Event");
168     shouldBeTrue("document.createEvent('SVGZoomEvents').constructor === window.SVGZoomEvent");
169
170     // #if ENABLE(WEB_SOCKETS)
171     // CloseEvent
172     shouldBeTrue("document.createEvent('CloseEvent') instanceof window.CloseEvent");
173     shouldBeTrue("document.createEvent('CloseEvent') instanceof window.Event");
174     shouldBeTrue("document.createEvent('CloseEvent').constructor === window.CloseEvent");
175
176     // The following are here for completeness, but won't until there is more widespread support for them.
177
178     // #if ENABLE(WEB_AUDIO)
179     // AudioProcessingEvent
180     // shouldBeTrue("document.createEvent('AudioProcessingEvent') instanceof window.AudioProcessingEvent");
181     // shouldBeTrue("document.createEvent('AudioProcessingEvent') instanceof window.Event");
182     // shouldBeTrue("document.createEvent('AudioProcessingEvent').constructor === window.AudioProcessingEvent");
183
184     // #if ENABLE(WEB_AUDIO)
185     // OfflineAudioCompletionEvent
186     // shouldBeTrue("document.createEvent('OfflineAudioCompletionEvent') instanceof window.OfflineAudioCompletionEvent");
187     // shouldBeTrue("document.createEvent('OfflineAudioCompletionEvent') instanceof window.Event");
188     // shouldBeTrue("document.createEvent('OfflineAudioCompletionEvent').constructor === window.OfflineAudioCompletionEvent");
189
190     // #if ENABLE(INPUT_SPEECH)
191     // MediaStreamEvent
192     // shouldBeTrue("document.createEvent('MediaStreamEvent') instanceof window.MediaStreamEvent");
193     // shouldBeTrue("document.createEvent('MediaStreamEvent') instanceof window.Event");
194     // shouldBeTrue("document.createEvent('MediaStreamEvent').constructor === window.MediaStreamEvent");
195
196     // #if ENABLE(INPUT_SPEECH)
197     // SpeechInputEvent
198     // shouldBeTrue("document.createEvent('SpeechInputEvent') instanceof window.SpeechInputEvent");
199     // shouldBeTrue("document.createEvent('SpeechInputEvent') instanceof window.Event");
200     // shouldBeTrue("document.createEvent('SpeechInputEvent').constructor === window.SpeechInputEvent");
201
202     // #if ENABLE(WEBGL)
203     // WebGLContextEvent
204     // shouldBeTrue("document.createEvent('WebGLContextEvent') instanceof window.WebGLContextEvent");
205     // shouldBeTrue("document.createEvent('WebGLContextEvent') instanceof window.Event");
206     // shouldBeTrue("document.createEvent('WebGLContextEvent').constructor === window.WebGLContextEvent");
207
208     // #if ENABLE(TOUCH_EVENTS)
209     // TouchEvent
210     // shouldBeTrue("document.createEvent('TouchEvent') instanceof window.TouchEvent");
211     // shouldBeTrue("document.createEvent('TouchEvent') instanceof window.Event");
212     // shouldBeTrue("document.createEvent('TouchEvent').constructor === window.TouchEvent");
213
214     // #if ENABLE(DEVICE_ORIENTATION)
215     // DeviceMotionEvent
216     // shouldBeTrue("document.createEvent('DeviceMotionEvent') instanceof window.DeviceMotionEvent");
217     // shouldBeTrue("document.createEvent('DeviceMotionEvent') instanceof window.Event");
218     // shouldBeTrue("document.createEvent('DeviceMotionEvent').constructor === window.DeviceMotionEvent");
219
220     // #if ENABLE(DEVICE_ORIENTATION)
221     // DeviceOrientationEvent
222     // shouldBeTrue("document.createEvent('DeviceOrientationEvent') instanceof window.DeviceOrientationEvent");
223     // shouldBeTrue("document.createEvent('DeviceOrientationEvent') instanceof window.Event");
224     // shouldBeTrue("document.createEvent('DeviceOrientationEvent').constructor === window.DeviceOrientationEvent");
225
226     // #if ENABLE(ORIENTATION_EVENTS)
227     // OrientationEvent (Event alternative)
228     // shouldBeTrue("document.createEvent('OrientationEvent') instanceof window.Event");
229     // shouldBeTrue("document.createEvent('OrientationEvent').constructor === window.Event");
230
231     // We test both a hard coded set and the automated set below (using enumeration) to ensure that a constructor being removed
232     // from the window is caught a regression.
233
234     var allEventInterfacesCreateEvents = true;
235     for (var propertyName in window) {
236         if (propertyName.match(/Event$/) && window[propertyName].toString().match(/EventConstructor\]$/)) {
237             try {
238                 if (!(document.createEvent(propertyName) instanceof window.Event)) {
239                     allEventInterfacesCreateEvents = false;
240                     debug("'document.createEvent(propertyName) instanceof window.Event' with propertyName: " + propertyName + " should be true but isn't");
241                 }
242             } catch (e) {
243                 allEventInterfacesCreateEvents = false;
244                 debug("'document.createEvent(propertyName) instanceof window.Event' with propertyName: " + propertyName + " threw an exception: " + e);
245             }
246
247             try {
248                 if (!(document.createEvent(propertyName) instanceof window[propertyName])) {
249                     allEventInterfacesCreateEvents = false;
250                     debug("'document.createEvent(propertyName) instanceof window[propertyName]' with propertyName: " + propertyName + " should be true but isn't");
251                 }
252             } catch (e) {
253                 allEventInterfacesCreateEvents = false;
254                 debug("'document.createEvent(propertyName) instanceof window[propertyName]' with propertyName: " + propertyName + " threw an exception: " + e);
255             }
256
257             try {
258                 if (!(document.createEvent(propertyName).constructor === window[propertyName])) {
259                     allEventInterfacesCreateEvents = false;
260                     debug("'document.createEvent(propertyName).constructor === window[propertyName]' with propertyName: " + propertyName + " should be true but isn't");
261                 }
262             } catch (e) {
263                 allEventInterfacesCreateEvents = false;
264                 debug("'document.createEvent(propertyName).constructor === window[propertyName]' with propertyName: " + propertyName + " threw an exception: " + e);
265             }
266         }
267     }
268     shouldBeTrue('allEventInterfacesCreateEvents');
269 </script>
270
271
272
273 <script src="../js/resources/js-test-post.js"></script>
274 </body>