3 // test each of the following events
5 "keydown","keyup","keypress"
7 // test each event type
8 test( '"'+ type +'"', function(){
9 expect( i < 2 ? 27 : 30 );
11 // custom event properties
13 keyCode: Math.round( Math.random() * 256 ),
14 charCode: Math.round( Math.random() * 256 ),
15 ctrlKey: Math.round( Math.random() ) ? true : false,
16 altKey: Math.round( Math.random() ) ? true : false,
17 shiftKey: Math.round( Math.random() ) ? true : false
20 $div = $('<div/>').appendTo( document.body );
21 // test the document too for bubbling
22 $div.add( document ).bind( type, function( ev ){
24 equals( ev.currentTarget, this, "event.currentTarget");
25 equals( ev.target, $div[0], "event.target" );
26 equals( ev.type, type, "event.type" );
27 equals( ev.keyCode, props.keyCode, "event.keyCode" );
28 if ( type == "keypress" ){
29 equals( ev.charCode, props.charCode, "event.charCode" );
31 equals( ev.ctrlKey, props.ctrlKey, "event.ctrlKey" );
32 equals( ev.altKey, props.altKey, "event.altKey" );
33 equals( ev.shiftKey, props.shiftKey, "event.shiftKey" );
34 equals( ev.metaKey, props.metaKey, "event.metaKey" );
35 equals( ev.bubbles, props.bubbles, "event.bubbles" );
38 // make sure that metaKey and ctrlKey are equal
39 props.metaKey = props.ctrlKey;
40 // fire the event with bubbling
42 $div.fire( type, props );
44 // fire the event without bubbling
45 props.bubbles = false;
46 $div.fire( type, props );
49 $( document ).unbind( type );