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
|
// META: title=Event constructors
test(function() {
assert_throws_js(
TypeError,
() => Event(""),
"Calling Event constructor without 'new' must throw")
})
test(function() {
assert_throws_js(TypeError, function() {
new Event()
})
})
test(function() {
var test_error = { name: "test" }
assert_throws_exactly(test_error, function() {
new Event({ toString: function() { throw test_error; } })
})
})
test(function() {
var ev = new Event("")
assert_equals(ev.type, "")
assert_equals(ev.target, null)
assert_equals(ev.srcElement, null)
assert_equals(ev.currentTarget, null)
assert_equals(ev.eventPhase, Event.NONE)
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, false)
assert_equals(ev.defaultPrevented, false)
assert_equals(ev.returnValue, true)
assert_equals(ev.isTrusted, false)
assert_true(ev.timeStamp > 0)
assert_true("initEvent" in ev)
})
test(function() {
var ev = new Event("test")
assert_equals(ev.type, "test")
assert_equals(ev.target, null)
assert_equals(ev.srcElement, null)
assert_equals(ev.currentTarget, null)
assert_equals(ev.eventPhase, Event.NONE)
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, false)
assert_equals(ev.defaultPrevented, false)
assert_equals(ev.returnValue, true)
assert_equals(ev.isTrusted, false)
assert_true(ev.timeStamp > 0)
assert_true("initEvent" in ev)
})
test(function() {
assert_throws_js(TypeError, function() { Event("test") },
'Calling Event constructor without "new" must throw');
})
test(function() {
var ev = new Event("I am an event", { bubbles: true, cancelable: false})
assert_equals(ev.type, "I am an event")
assert_equals(ev.bubbles, true)
assert_equals(ev.cancelable, false)
})
test(function() {
var ev = new Event("@", { bubblesIGNORED: true, cancelable: true})
assert_equals(ev.type, "@")
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, true)
})
test(function() {
var ev = new Event("@", { "bubbles\0IGNORED": true, cancelable: true})
assert_equals(ev.type, "@")
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, true)
})
test(function() {
var ev = new Event("Xx", { cancelable: true})
assert_equals(ev.type, "Xx")
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, true)
})
test(function() {
var ev = new Event("Xx", {})
assert_equals(ev.type, "Xx")
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, false)
})
test(function() {
var ev = new Event("Xx", {bubbles: true, cancelable: false, sweet: "x"})
assert_equals(ev.type, "Xx")
assert_equals(ev.bubbles, true)
assert_equals(ev.cancelable, false)
assert_equals(ev.sweet, undefined)
})
test(function() {
var called = []
var ev = new Event("Xx", {
get cancelable() {
called.push("cancelable")
return false
},
get bubbles() {
called.push("bubbles")
return true;
},
get sweet() {
called.push("sweet")
return "x"
}
})
assert_array_equals(called, ["bubbles", "cancelable"])
assert_equals(ev.type, "Xx")
assert_equals(ev.bubbles, true)
assert_equals(ev.cancelable, false)
assert_equals(ev.sweet, undefined)
})
test(function() {
var ev = new CustomEvent("$", {detail: 54, sweet: "x", sweet2: "x", cancelable:true})
assert_equals(ev.type, "$")
assert_equals(ev.bubbles, false)
assert_equals(ev.cancelable, true)
assert_equals(ev.sweet, undefined)
assert_equals(ev.detail, 54)
})
|