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