OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <meta charset=utf-8> | |
3 <title>Document.createEvent</title> | |
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createevent"> | |
5 <script src="../../../../resources/testharness.js"></script> | |
6 <script src="../../../../resources/testharnessreport.js"></script> | |
7 <script src="Document-createEvent.js"></script> | |
8 <div id="log"></div> | |
9 <script> | |
10 function testAlias(arg, iface) { | |
11 var ev; | |
12 test(function() { | |
13 ev = document.createEvent(arg); | |
14 assert_true(ev instanceof window[iface]); | |
15 assert_true(ev instanceof Event); | |
16 }, arg + " should be an alias for " + iface + "."); | |
17 test(function() { | |
18 assert_equals(ev.type, "", | |
19 "type should be initialized to the empty string"); | |
20 assert_equals(ev.target, null, | |
21 "target should be initialized to null"); | |
22 assert_equals(ev.currentTarget, null, | |
23 "currentTarget should be initialized to null"); | |
24 assert_equals(ev.eventPhase, 0, | |
25 "eventPhase should be initialized to NONE (0)"); | |
26 assert_equals(ev.bubbles, false, | |
27 "bubbles should be initialized to false"); | |
28 assert_equals(ev.cancelable, false, | |
29 "cancelable should be initialized to false"); | |
30 assert_equals(ev.defaultPrevented, false, | |
31 "defaultPrevented should be initialized to false"); | |
32 assert_equals(ev.isTrusted, false, | |
33 "isTrusted should be initialized to false"); | |
34 }, "createEvent('" + arg + "') should be initialized correctly."); | |
35 } | |
36 for (var alias in aliases) { | |
37 var iface = aliases[alias]; | |
38 testAlias(alias, iface); | |
39 testAlias(alias.toLowerCase(), iface); | |
40 testAlias(alias.toUpperCase(), iface); | |
41 | |
42 if (alias[alias.length - 1] != "s") { | |
43 var plural = alias + "s"; | |
44 if (!(plural in aliases)) { | |
45 test(function () { | |
46 assert_throws("NOT_SUPPORTED_ERR", function () { | |
47 var evt = document.createEvent(plural); | |
48 }); | |
49 }, 'Should throw NOT_SUPPORTED_ERR for pluralized legacy event interface "
' + plural + '"'); | |
50 } | |
51 } | |
52 } | |
53 | |
54 test(function() { | |
55 assert_throws("NOT_SUPPORTED_ERR", function() { | |
56 var evt = document.createEvent("foo"); | |
57 }); | |
58 assert_throws("NOT_SUPPORTED_ERR", function() { | |
59 // 'LATIN CAPITAL LETTER I WITH DOT ABOVE' (U+0130) | |
60 var evt = document.createEvent("U\u0130Event"); | |
61 }); | |
62 assert_throws("NOT_SUPPORTED_ERR", function() { | |
63 // 'LATIN SMALL LETTER DOTLESS I' (U+0131) | |
64 var evt = document.createEvent("U\u0131Event"); | |
65 }); | |
66 }, "Should throw NOT_SUPPORTED_ERR for unrecognized arguments"); | |
67 | |
68 /* | |
69 * The following are event interfaces which do actually exist, but must still | |
70 * throw since they're absent from the table in the spec for | |
71 * document.createEvent(). This list is not exhaustive, but includes all | |
72 * interfaces that it is known some UA does or did not throw for. | |
73 */ | |
74 var someNonCreateableEvents = [ | |
75 "AnimationPlayerEvent", | |
76 "ApplicationCacheErrorEvent", | |
77 "AudioProcessingEvent", | |
78 "AutocompleteErrorEvent", | |
79 "BeforeInstallPromptEvent", | |
80 "BlobEvent", | |
81 "ClipboardEvent", | |
82 "CommandEvent", | |
83 "DataContainerEvent", | |
84 "DeviceLightEvent", | |
85 "ExtendableEvent", | |
86 "ExtendableMessageEvent", | |
87 "FetchEvent", | |
88 "FontFaceSetLoadEvent", | |
89 "GamepadEvent", | |
90 "GeofencingEvent", | |
91 "InstallEvent", | |
92 "KeyEvent", | |
93 "MIDIConnectionEvent", | |
94 "MIDIMessageEvent", | |
95 "MediaEncryptedEvent", | |
96 "MediaKeyEvent", | |
97 "MediaKeyMessageEvent", | |
98 "MediaQueryListEvent", | |
99 "MediaStreamEvent", | |
100 "MediaStreamTrackEvent", | |
101 "MouseScrollEvent", | |
102 "MutationEvent", | |
103 "NotificationEvent", | |
104 "NotifyPaintEvent", | |
105 "OfflineAudioCompletionEvent", | |
106 "OrientationEvent", | |
107 "PageTransition", // Yes, with no "Event" | |
108 "PointerEvent", | |
109 "PopUpEvent", | |
110 "PresentationConnectionAvailableEvent", | |
111 "PresentationConnectionCloseEvent", | |
112 "PromiseRejectionEvent", | |
113 "PushEvent", | |
114 "RTCDTMFToneChangeEvent", | |
115 "RTCDataChannelEvent", | |
116 "RTCIceCandidateEvent", | |
117 "RelatedEvent", | |
118 "ResourceProgressEvent", | |
119 "SVGEvent", | |
120 "ScrollAreaEvent", | |
121 "SecurityPolicyViolationEvent", | |
122 "ServicePortConnectEvent", | |
123 "ServiceWorkerMessageEvent", | |
124 "SimpleGestureEvent", | |
125 "SpeechRecognitionError", | |
126 "SpeechRecognitionEvent", | |
127 "SpeechSynthesisEvent", | |
128 "SyncEvent", | |
129 "TimeEvent", | |
130 "WebKitAnimationEvent", | |
131 "WebKitTransitionEvent", | |
132 "XULCommandEvent", | |
133 ]; | |
134 someNonCreateableEvents.forEach(function (eventInterface) { | |
135 // SVGEvents is allowed, but not SVGEvent. Make sure we only test if it's | |
136 // not whitelisted. | |
137 if (!(eventInterface in aliases)) { | |
138 test(function () { | |
139 assert_throws("NOT_SUPPORTED_ERR", function () { | |
140 var evt = document.createEvent(eventInterface); | |
141 }); | |
142 }, 'Should throw NOT_SUPPORTED_ERR for non-legacy event interface "' + event
Interface + '"'); | |
143 } | |
144 | |
145 if (!(eventInterface + "s" in aliases)) { | |
146 test(function () { | |
147 assert_throws("NOT_SUPPORTED_ERR", function () { | |
148 var evt = document.createEvent(eventInterface + "s"); | |
149 }); | |
150 }, 'Should throw NOT_SUPPORTED_ERR for pluralized non-legacy event interface
"' + eventInterface + 's"'); | |
151 } | |
152 }); | |
153 </script> | |
OLD | NEW |