| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipa
ge/webappapis.html#eventhandler"> | 3 <link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipa
ge/webappapis.html#eventhandler"> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <div id="div"></div> | 7 <div id="div"></div> |
| 8 <script> | 8 <script> |
| 9 description("This test checks that EventHandler attributes only accept JS functi
ons as input."); | 9 description("This test checks that EventHandler attributes only accept JS functi
ons as input."); |
| 10 | 10 |
| 11 var div = document.getElementById("div"); | 11 var div = document.getElementById("div"); |
| 12 var callbackCount = 0; | 12 var callbackCount = 0; |
| 13 | 13 |
| 14 function callback() { | 14 function callback() { |
| 15 ++callbackCount; | 15 ++callbackCount; |
| 16 } | 16 } |
| 17 | 17 |
| 18 function dispatchKeyEvent() | 18 function dispatchKeyEvent() |
| 19 { | 19 { |
| 20 var event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true,
view: null, keyIdentifier: 'Enter' }); | 20 var event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true,
view: null, key: 'Enter' }); |
| 21 div.dispatchEvent(event); | 21 div.dispatchEvent(event); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Input is a JS function, this should work. | 24 // Input is a JS function, this should work. |
| 25 shouldBeNull('div.onkeydown'); | 25 shouldBeNull('div.onkeydown'); |
| 26 shouldNotThrow('div.onkeydown = callback'); | 26 shouldNotThrow('div.onkeydown = callback'); |
| 27 shouldBe('div.onkeydown', 'callback'); | 27 shouldBe('div.onkeydown', 'callback'); |
| 28 shouldBe('callbackCount', '0'); | 28 shouldBe('callbackCount', '0'); |
| 29 dispatchKeyEvent(); | 29 dispatchKeyEvent(); |
| 30 shouldBe('callbackCount', '1'); | 30 shouldBe('callbackCount', '1'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 shouldBeNull('div.onkeydown'); | 44 shouldBeNull('div.onkeydown'); |
| 45 | 45 |
| 46 // Test null assignment. | 46 // Test null assignment. |
| 47 shouldNotThrow('div.onkeydown = callback'); | 47 shouldNotThrow('div.onkeydown = callback'); |
| 48 shouldBe('div.onkeydown', 'callback'); | 48 shouldBe('div.onkeydown', 'callback'); |
| 49 shouldNotThrow('div.onkeydown = null'); | 49 shouldNotThrow('div.onkeydown = null'); |
| 50 shouldBeNull('div.onkeydown'); | 50 shouldBeNull('div.onkeydown'); |
| 51 </script> | 51 </script> |
| 52 </body> | 52 </body> |
| 53 </html> | 53 </html> |
| OLD | NEW |