Chromium Code Reviews| 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 callbackCount = 0; | |
| 13 | |
| 14 function callback() { | |
| 15 ++callbackCount; | |
| 16 } | |
| 17 | |
| 18 function dispatchKeyEvent() | |
| 19 { | |
| 20 var event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, view: null, keyIdentifier: '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 shouldBe('callbackCount', '0'); | |
| 29 dispatchKeyEvent(); | |
| 30 shouldBe('callbackCount', '1'); | |
| 31 | |
| 32 // Non callable input should be treated as null. | |
| 33 var o = { 'handleEvent': callback }; | |
|
arv (Not doing code reviews)
2013/08/08 19:45:11
No need for quotes if the property name is a valid
do-not-use
2013/08/08 19:53:28
Done.
| |
| 34 shouldNotBe('div.onkeydown', 'null'); | |
| 35 shouldNotThrow('div.onkeydown = o'); | |
| 36 shouldBeNull('div.onkeydown'); | |
| 37 dispatchKeyEvent(); | |
| 38 shouldBe('callbackCount', '1'); | |
| 39 | |
| 40 // Test null assignment. | |
| 41 shouldNotThrow('div.onkeydown = callback'); | |
| 42 shouldBe('div.onkeydown', 'callback'); | |
| 43 shouldNotThrow('div.onkeydown = null'); | |
| 44 shouldBeNull('div.onkeydown'); | |
| 45 </script> | |
| 46 <script src="../js/resources/js-test-post.js"></script> | |
| 47 </body> | |
| 48 </html> | |
| OLD | NEW |