OLD | NEW |
---|---|
(Empty) | |
1 <html> | |
2 <head> | |
3 <link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipa ge/webappapis.html#eventhandler"> | |
4 <script src="../js/resources/js-test-pre.js"></script> | |
5 </head> | |
6 <body> | |
7 <div id="div"></div> | |
8 <script> | |
9 description("This test checks that EventHandler attributes only accept JS functi ons as input."); | |
10 | |
11 var div = document.getElementById("div"); | |
12 var wasCallbackCalled = false; | |
arv (Not doing code reviews)
2013/08/08 14:41:28
A general tip for cases like this is to use a coun
| |
13 | |
14 function callback() { | |
15 wasCallbackCalled = true; | |
16 } | |
17 | |
18 function dispatchKeyEvent() | |
19 { | |
20 var event = document.createEvent("KeyboardEvent"); | |
arv (Not doing code reviews)
2013/08/08 14:41:28
I always prefer new FooEvent since the initFooEven
| |
21 event.initKeyboardEvent("keydown", true, true, null, "Enter", ""); | |
22 div.dispatchEvent(event); | |
23 } | |
24 | |
25 // Input is a JS function, this should work. | |
26 shouldBeNull('div.onkeydown'); | |
27 shouldNotThrow('div.onkeydown = callback'); | |
28 shouldBe('div.onkeydown', 'callback'); | |
29 dispatchKeyEvent(); | |
30 shouldBeTrue('wasCallbackCalled'); | |
31 | |
32 // Non callable input should be treated as null. | |
33 var o = {}; | |
34 Object.defineProperty(o, 'handleEvent', callback); | |
arv (Not doing code reviews)
2013/08/08 14:41:28
This is incorrect usage of the defineProperty API.
| |
35 shouldNotBe('div.onkeydown', 'null'); | |
36 shouldNotThrow('div.onkeydown = o'); | |
37 shouldBeNull('div.onkeydown'); | |
38 wasCallbackCalled = false; | |
39 dispatchKeyEvent(); | |
40 shouldBeFalse('wasCallbackCalled'); | |
41 | |
42 // Test null assignment. | |
43 shouldNotThrow('div.onkeydown = callback'); | |
44 shouldBe('div.onkeydown', 'callback'); | |
45 shouldNotThrow('div.onkeydown = null'); | |
46 shouldBeNull('div.onkeydown'); | |
47 </script> | |
48 <script src="../js/resources/js-test-post.js"></script> | |
49 </body> | |
50 </html> | |
OLD | NEW |