blob: 541fef525df527d0225a1ab4a8b32c33cb76b1af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<html>
<head>
<link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler">
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="div"></div>
<script>
description("This test checks that EventHandler attributes only accept JS functions as input.");
var div = document.getElementById("div");
var callbackCount = 0;
function callback() {
++callbackCount;
}
function dispatchKeyEvent()
{
var event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, view: null, keyIdentifier: 'Enter' });
div.dispatchEvent(event);
}
// Input is a JS function, this should work.
shouldBeNull('div.onkeydown');
shouldNotThrow('div.onkeydown = callback');
shouldBe('div.onkeydown', 'callback');
shouldBe('callbackCount', '0');
dispatchKeyEvent();
shouldBe('callbackCount', '1');
// Non callable input should be treated as null.
var o = { handleEvent: callback };
shouldNotBe('div.onkeydown', 'null');
shouldNotThrow('div.onkeydown = o');
shouldBe('div.onkeydown', 'o');
dispatchKeyEvent();
shouldBe('callbackCount', '1');
// Test non-object assignment.
shouldNotThrow('div.onkeydown = callback');
shouldBe('div.onkeydown', 'callback');
shouldNotThrow('div.onkeydown = "non-object"');
shouldBeNull('div.onkeydown');
// Test null assignment.
shouldNotThrow('div.onkeydown = callback');
shouldBe('div.onkeydown', 'callback');
shouldNotThrow('div.onkeydown = null');
shouldBeNull('div.onkeydown');
</script>
</body>
</html>
|