2013-08-28 16:50:22 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
var viewer;
|
|
|
|
|
|
|
|
module( 'Events', {
|
|
|
|
setup: function () {
|
2013-08-28 22:33:41 +04:00
|
|
|
var example = $( '<div id="eventsexample"></div>' ).appendTo( "#qunit-fixture" );
|
2013-08-28 16:50:22 +04:00
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
|
|
|
|
viewer = OpenSeadragon( {
|
2013-08-28 22:33:41 +04:00
|
|
|
id: 'eventsexample',
|
2013-08-28 16:50:22 +04:00
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
teardown: function () {
|
|
|
|
if ( viewer && viewer.close ) {
|
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest( 'addHandler without userData', function () {
|
2013-10-11 04:00:15 +04:00
|
|
|
var openHandler = function ( event ) {
|
2013-08-28 16:50:22 +04:00
|
|
|
viewer.removeHandler( 'open', openHandler );
|
2013-10-11 04:00:15 +04:00
|
|
|
ok( event, 'Event handler received event data' );
|
|
|
|
if ( event ) {
|
|
|
|
strictEqual( event.eventSource, viewer, 'eventSource sent, eventSource is viewer' );
|
|
|
|
strictEqual( event.userData, null, 'User data defaulted to null' );
|
2013-08-28 16:50:22 +04:00
|
|
|
}
|
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler( 'open', openHandler );
|
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest( 'addHandler with userData', function () {
|
2013-08-30 21:09:22 +04:00
|
|
|
var userData = { item1: 'Test user data', item2: Math.random() },
|
|
|
|
originalUserData = { item1: userData.item1, item2: userData.item2 };
|
2013-08-28 16:50:22 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var openHandler = function ( event ) {
|
2013-08-28 16:50:22 +04:00
|
|
|
viewer.removeHandler( 'open', openHandler );
|
2013-10-11 04:00:15 +04:00
|
|
|
ok( event, 'Event handler received event data' );
|
|
|
|
ok( event && event.userData, 'Event handler received user data' );
|
|
|
|
if ( event && event.userData ) {
|
|
|
|
deepEqual( event.userData, originalUserData, 'User data was untouched' );
|
2013-08-28 16:50:22 +04:00
|
|
|
}
|
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler( 'open', openHandler, userData );
|
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
// ----------
|
2013-09-25 00:36:13 +04:00
|
|
|
asyncTest( 'MouseTracker, EventSource canvas-drag canvas-release canvas-click', function () {
|
2013-09-20 20:17:48 +04:00
|
|
|
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
|
|
|
mouseTracker = null,
|
|
|
|
userData = { item1: 'Test user data', item2: Math.random() },
|
|
|
|
originalUserData = { item1: userData.item1, item2: userData.item2 },
|
|
|
|
dragCount = 10,
|
2013-09-25 00:36:13 +04:00
|
|
|
dragsHandledEventSource = 0,
|
|
|
|
releasesHandledEventSource = 0,
|
|
|
|
clicksHandledEventSource = 0,
|
2013-09-20 20:17:48 +04:00
|
|
|
eventsHandledMouseTracker = 0,
|
2013-10-11 04:00:15 +04:00
|
|
|
eventSourcePassedMouseTracker = 0,
|
2013-09-20 20:17:48 +04:00
|
|
|
originalEventsPassedMouseTracker = 0,
|
2013-10-15 22:27:21 +04:00
|
|
|
eventsHandledViewer = 0,
|
|
|
|
originalEventsPassedViewer = 0,
|
2013-09-20 20:17:48 +04:00
|
|
|
releasesExpected = 1,
|
|
|
|
clicksExpected = 1;
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onOpen = function ( event ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
viewer.removeHandler( 'open', onOpen );
|
|
|
|
|
2013-09-25 00:36:13 +04:00
|
|
|
viewer.addHandler( 'canvas-drag', onEventSourceDrag );
|
|
|
|
viewer.addHandler( 'canvas-release', onEventSourceRelease );
|
|
|
|
viewer.addHandler( 'canvas-click', onEventSourceClick );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
|
|
|
mouseTracker = new OpenSeadragon.MouseTracker( {
|
|
|
|
element: $canvas[0],
|
|
|
|
userData: userData,
|
|
|
|
clickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
|
|
|
|
focusHandler: onMouseTrackerFocus,
|
|
|
|
blurHandler: onMouseTrackerBlur,
|
|
|
|
enterHandler: onMouseTrackerEnter,
|
|
|
|
pressHandler: onMouseTrackerPress,
|
|
|
|
moveHandler: onMouseTrackerMove,
|
|
|
|
dragHandler: onMouseTrackerDrag,
|
|
|
|
releaseHandler: onMouseTrackerRelease,
|
|
|
|
clickHandler: onMouseTrackerClick,
|
|
|
|
exitHandler: onMouseTrackerExit
|
|
|
|
} ).setTracking( true );
|
|
|
|
|
|
|
|
var event = {
|
|
|
|
clientX:1,
|
|
|
|
clientY:1
|
|
|
|
};
|
|
|
|
|
|
|
|
$canvas.simulate( 'focus', event );
|
2013-08-30 21:09:22 +04:00
|
|
|
Util.simulateViewerClickWithDrag( {
|
|
|
|
viewer: viewer,
|
|
|
|
widthFactor: 0.25,
|
|
|
|
heightFactor: 0.25,
|
|
|
|
dragCount: dragCount,
|
|
|
|
dragDx: 1,
|
|
|
|
dragDy: 1
|
2013-08-30 00:01:07 +04:00
|
|
|
} );
|
2013-09-20 20:17:48 +04:00
|
|
|
$canvas.simulate( 'blur', event );
|
|
|
|
};
|
|
|
|
|
2013-10-15 22:27:21 +04:00
|
|
|
var checkOriginalEventReceivedViewer = function ( event ) {
|
|
|
|
eventsHandledViewer++;
|
|
|
|
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
|
|
|
|
// with arbitrary user data.
|
|
|
|
if ( event && event.originalEvent ) {
|
|
|
|
originalEventsPassedViewer++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceDrag = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
dragsHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceRelease = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
releasesHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceClick = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
clicksHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var checkOriginalEventReceived = function ( event ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
eventsHandledMouseTracker++;
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( event && event.eventSource === mouseTracker ) {
|
|
|
|
eventSourcePassedMouseTracker++;
|
|
|
|
}
|
2013-09-25 00:36:13 +04:00
|
|
|
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
|
|
|
|
// with arbitrary user data.
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( event && event.originalEvent ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
originalEventsPassedMouseTracker++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerFocus = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerBlur = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerEnter = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerPress = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerMove = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerDrag = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerRelease = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerClick = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerExit = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
|
|
|
mouseTracker.destroy();
|
2013-09-25 00:36:13 +04:00
|
|
|
viewer.removeHandler( 'canvas-drag', onEventSourceDrag );
|
|
|
|
viewer.removeHandler( 'canvas-release', onEventSourceRelease );
|
|
|
|
viewer.removeHandler( 'canvas-click', onEventSourceClick );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-09-25 00:36:13 +04:00
|
|
|
equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
|
|
|
|
equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
|
|
|
|
equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" );
|
2013-10-15 22:27:21 +04:00
|
|
|
equal( originalEventsPassedViewer, eventsHandledViewer, "Original event received count matches expected (" + eventsHandledViewer + ")" );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" );
|
2013-09-20 20:17:48 +04:00
|
|
|
equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" );
|
2013-10-11 04:00:15 +04:00
|
|
|
deepEqual( event.userData, originalUserData, 'MouseTracker userData was untouched' );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2013-09-20 20:17:48 +04:00
|
|
|
viewer.addHandler( 'open', onOpen );
|
2013-08-28 22:33:41 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2013-08-28 16:50:22 +04:00
|
|
|
} )();
|