2 <p>Test for
<a href=
"http://bugs.webkit.org/show_bug.cgi?id=3387">bug
3387</a>:
3 Redundant keydown, keypress, keyup events sent for arrow keys.
</p>
5 <p>Try pressing arrow keys, PgUp/PgDown/Home/End, Esc, or function keys.
6 The test passes if the box below doesn't turn red.
<p>
8 <div id=
"result" style=
"width:100px; height:100px; background-color:blue;"></div>
12 var console_messages
= document
.createElement("ol");
13 document
.body
.appendChild(console_messages
);
15 window
.onkeydown
= registerWindow
;
16 window
.onkeypress
= registerWindow
;
17 window
.onkeyup
= registerWindow
;
19 document
.onkeydown
= registerDocument
;
20 document
.onkeypress
= registerDocument
;
21 document
.onkeyup
= registerDocument
;
23 document
.body
.onkeydown
= registerBody
;
24 document
.body
.onkeypress
= registerBody
;
25 document
.body
.onkeyup
= registerBody
;
27 document
.documentElement
.onkeydown
= registerDocumentElement
;
28 document
.documentElement
.onkeypress
= registerDocumentElement
;
29 document
.documentElement
.onkeyup
= registerDocumentElement
;
31 var bodyKeyDownCount
= 0;
32 var documentElementKeyDownCount
= 0;
33 var windowKeyDownCount
= 0;
34 var documentKeyDownCount
= 0;
38 var item
= document
.createElement("li");
39 item
.appendChild(document
.createTextNode(message
));
40 item
.style
.fontSize
= '8px';
41 console_messages
.appendChild(item
);
44 function registerBody(e
)
46 if ((e
.type
== "keydown" && ++bodyKeyDownCount
!= 1)
47 || (e
.type
== "keyup" && --bodyKeyDownCount
!= 0))
48 document
.getElementById("result").style
.backgroundColor
= "red";
52 log("body: " + e
.type
);
56 function registerDocumentElement(e
)
58 if ((e
.type
== "keydown" && ++documentElementKeyDownCount
!= 1)
59 || (e
.type
== "keyup" && --documentElementKeyDownCount
!= 0))
60 document
.getElementById("result").style
.backgroundColor
= "red";
64 log(" documentElement: " + e
.type
);
68 function registerDocument(e
)
70 if ((e
.type
== "keydown" && ++documentKeyDownCount
!= 1)
71 || (e
.type
== "keyup" && --documentKeyDownCount
!= 0))
72 document
.getElementById("result").style
.backgroundColor
= "red";
76 log(" document: " + e
.type
);
80 function registerWindow(e
)
82 if ((e
.type
== "keydown" && ++windowKeyDownCount
!= 1)
83 || (e
.type
== "keyup" && --windowKeyDownCount
!= 0))
84 document
.getElementById("result").style
.backgroundColor
= "red";
88 log(" window: " + e
.type
);