1 module("Touch Events");
3 if ( !document.createEvent ){
4 test("Touch Simulation Not Supported",function(){
5 ok( true, 'This browser does not support "document.createEvent" and cannot simulate touch events.');
10 // test each of the following events
12 "touchstart","touchmove","touchend"
13 ],function( i, type ){
14 // test each event type
15 test( '"'+ type +'"', function(){
18 // custom event properties
20 pageX: Math.round( Math.random() * 500 ),
21 pageY: Math.round( Math.random() * 500 ),
22 ctrlKey: Math.round( Math.random() ) ? true : false,
23 altKey: Math.round( Math.random() ) ? true : false,
24 shiftKey: Math.round( Math.random() ) ? true : false,
25 button: Math.round( Math.random() * 2 )
28 $div = $('<div/>').appendTo( document.body );
29 // test the document too for bubbling
30 $div.add( document ).bind( type, function( ev ){
32 equals( ev.currentTarget, this, "event.currentTarget");
33 equals( ev.target, $div[0], "event.target" );
34 equals( ev.type, type, "event.type" );
35 equals( ev.pageX, props.pageX, "event.pageX" );
36 equals( ev.pageY, props.pageY, "event.pageY" );
37 equals( ev.ctrlKey, props.ctrlKey, "event.ctrlKey" );
38 equals( ev.altKey, props.altKey, "event.altKey" );
39 equals( ev.shiftKey, props.shiftKey, "event.shiftKey" );
40 equals( ev.metaKey, props.metaKey, "event.metaKey" );
41 equals( ev.button, props.button, "event.button" );
42 equals( ev.bubbles, props.bubbles, "event.bubbles" );
45 // make sure that metaKey and ctrlKey are equal
46 props.metaKey = props.ctrlKey;
47 // fire the event with bubbling
49 $div.fire( type, props );
51 // fire the event without bubbling
52 props.bubbles = false;
53 $div.fire( type, props );
56 $( document ).unbind( type );