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 <body> | |
haraken
2013/08/08 13:57:35
Super Nit: </head> is missing.
do-not-use
2013/08/08 14:05:48
Done.
| |
6 <div id="div"></div> | |
7 <script> | |
8 description("This test checks that EventHandler attributes only accept JS functi ons as input."); | |
9 | |
10 var div = document.getElementById("div"); | |
11 var wasCallbackCalled = false; | |
12 | |
13 function callback() { | |
14 wasCallbackCalled = true; | |
15 } | |
16 | |
17 function dispatchKeyEvent() | |
18 { | |
19 var event = document.createEvent("KeyboardEvent"); | |
20 event.initKeyboardEvent("keydown", true, true, null, "Enter", ""); | |
21 div.dispatchEvent(event); | |
22 } | |
23 | |
24 // Input is a JS function, this should work. | |
25 shouldBeNull('div.onkeydown'); | |
26 shouldNotThrow('div.onkeydown = callback'); | |
27 shouldBe('div.onkeydown', 'callback'); | |
28 dispatchKeyEvent(); | |
29 shouldBeTrue('wasCallbackCalled'); | |
30 | |
31 // Non callable input should be treated as null. | |
32 var o = {}; | |
33 o.__defineGetter__("handleEvent", callback); | |
haraken
2013/08/08 13:55:47
We want to use Object.defineProperty()
do-not-use
2013/08/08 14:05:48
Done.
| |
34 shouldNotBe('div.onkeydown', 'null'); | |
35 shouldNotThrow('div.onkeydown = o'); | |
36 shouldBeNull('div.onkeydown'); | |
37 wasCallbackCalled = false; | |
38 dispatchKeyEvent(); | |
39 shouldBeFalse('wasCallbackCalled'); | |
40 | |
haraken
2013/08/08 13:55:47
We might want to add a test case for 'div.onkeydow
do-not-use
2013/08/08 14:05:48
Done.
| |
41 </script> | |
42 <script src="../js/resources/js-test-post.js"></script> | |
43 </body> | |
44 </html> | |
OLD | NEW |