blob: 81231f158dd8de666c230370795dd4cdfb99b7e8 [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001<body>
2<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=3387">bug 3387</a>:
3Redundant keydown, keypress, keyup events sent for arrow keys.</p>
4
5<p>Try pressing arrow keys, PgUp/PgDown/Home/End, Esc, or function keys.
6The test passes if the box below doesn't turn red.<p>
7
8<div id="result" style="width:100px; height:100px; background-color:blue;"></div>
9
10<script>
11
12 var console_messages = document.createElement("ol");
13 document.body.appendChild(console_messages);
14
15 window.onkeydown = registerWindow;
16 window.onkeypress = registerWindow;
17 window.onkeyup = registerWindow;
18
19 document.onkeydown = registerDocument;
20 document.onkeypress = registerDocument;
21 document.onkeyup = registerDocument;
22
23 document.body.onkeydown = registerBody;
24 document.body.onkeypress = registerBody;
25 document.body.onkeyup = registerBody;
26
27 document.documentElement.onkeydown = registerDocumentElement;
28 document.documentElement.onkeypress = registerDocumentElement;
29 document.documentElement.onkeyup = registerDocumentElement;
30
31 var bodyKeyDownCount = 0;
32 var documentElementKeyDownCount = 0;
33 var windowKeyDownCount = 0;
34 var documentKeyDownCount = 0;
35
36 function log(message)
37 {
38 var item = document.createElement("li");
39 item.appendChild(document.createTextNode(message));
40 item.style.fontSize = '8px';
41 console_messages.appendChild(item);
42 }
43
44 function registerBody(e)
45 {
46 if ((e.type == "keydown" && ++bodyKeyDownCount != 1)
47 || (e.type == "keyup" && --bodyKeyDownCount != 0))
48 document.getElementById("result").style.backgroundColor = "red";
49
50 if (!e)
51 e = window.event;
52 log("body: " + e.type);
53 return true;
54 }
55
56 function registerDocumentElement(e)
57 {
58 if ((e.type == "keydown" && ++documentElementKeyDownCount != 1)
59 || (e.type == "keyup" && --documentElementKeyDownCount != 0))
60 document.getElementById("result").style.backgroundColor = "red";
61
62 if (!e)
63 e = window.event;
64 log(" documentElement: " + e.type);
65 return true;
66 }
67
68 function registerDocument(e)
69 {
70 if ((e.type == "keydown" && ++documentKeyDownCount != 1)
71 || (e.type == "keyup" && --documentKeyDownCount != 0))
72 document.getElementById("result").style.backgroundColor = "red";
73
74 if (!e)
75 e = window.event;
76 log("  document: " + e.type);
77 return true;
78 }
79
80 function registerWindow(e)
81 {
82 if ((e.type == "keydown" && ++windowKeyDownCount != 1)
83 || (e.type == "keyup" && --windowKeyDownCount != 0))
84 document.getElementById("result").style.backgroundColor = "red";
85
86 if (!e)
87 e = window.event;
88 log("   window: " + e.type);
89 return true;
90 }
91
92</script>
93</body>