3 <link rel=
"help" href=
"http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler">
4 <script src=
"../../resources/js-test.js"></script>
9 description("This test checks that EventHandler attributes only accept JS functions as input.");
11 var div
= document
.getElementById("div");
12 var callbackCount
= 0;
18 function dispatchKeyEvent()
20 var event
= new KeyboardEvent('keydown', { bubbles
: true, cancelable
: true, view
: null, keyIdentifier
: 'Enter' });
21 div
.dispatchEvent(event
);
24 // Input is a JS function, this should work.
25 shouldBeNull('div.onkeydown');
26 shouldNotThrow('div.onkeydown = callback');
27 shouldBe('div.onkeydown', 'callback');
28 shouldBe('callbackCount', '0');
30 shouldBe('callbackCount', '1');
32 // Non callable input should be treated as null.
33 var o
= { handleEvent
: callback
};
34 shouldNotBe('div.onkeydown', 'null');
35 shouldNotThrow('div.onkeydown = o');
36 shouldBe('div.onkeydown', 'o');
38 shouldBe('callbackCount', '1');
40 // Test non-object assignment.
41 shouldNotThrow('div.onkeydown = callback');
42 shouldBe('div.onkeydown', 'callback');
43 shouldNotThrow('div.onkeydown = "non-object"');
44 shouldBeNull('div.onkeydown');
46 // Test null assignment.
47 shouldNotThrow('div.onkeydown = callback');
48 shouldBe('div.onkeydown', 'callback');
49 shouldNotThrow('div.onkeydown = null');
50 shouldBeNull('div.onkeydown');