Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / html / eventhandler-attribute-non-callable.html
blob541fef525df527d0225a1ab4a8b32c33cb76b1af
1 <html>
2 <head>
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>
5 </head>
6 <body>
7 <div id="div"></div>
8 <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;
14 function callback() {
15 ++callbackCount;
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');
29 dispatchKeyEvent();
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');
37 dispatchKeyEvent();
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');
51 </script>
52 </body>
53 </html>