mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 20:56:09 +03:00
MouseTracker Original Events in Handlers
MouseTracker Unit Tests
This commit is contained in:
parent
56ef12e850
commit
4adeacdc5e
125
test/events.js
125
test/events.js
@ -61,19 +61,49 @@
|
||||
} );
|
||||
|
||||
// ----------
|
||||
asyncTest( 'canvas-drag canvas-release canvas-click', function () {
|
||||
var dragCount = 10,
|
||||
dragMovesHandled = 0,
|
||||
releasesHandled = 0,
|
||||
releasesExpected = 1;
|
||||
asyncTest( 'MouseTracker, EventHandler canvas-drag canvas-release canvas-click', function () {
|
||||
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,
|
||||
dragsHandledEventHandler = 0,
|
||||
releasesHandledEventHandler = 0,
|
||||
clicksHandledEventHandler = 0,
|
||||
eventsHandledMouseTracker = 0,
|
||||
originalEventsPassedMouseTracker = 0,
|
||||
releasesExpected = 1,
|
||||
clicksExpected = 1;
|
||||
|
||||
var openHandler = function ( eventSender, eventData ) {
|
||||
viewer.removeHandler( 'open', openHandler );
|
||||
var onOpen = function ( eventSender, eventData ) {
|
||||
viewer.removeHandler( 'open', onOpen );
|
||||
|
||||
viewer.addHandler( 'canvas-drag', canvasDragHandler );
|
||||
viewer.addHandler( 'canvas-release', canvasReleaseHandler );
|
||||
viewer.addHandler( 'canvas-click', canvasClickHandler );
|
||||
viewer.addHandler( 'canvas-drag', onEventHandlerDrag );
|
||||
viewer.addHandler( 'canvas-release', onEventHandlerRelease );
|
||||
viewer.addHandler( 'canvas-click', onEventHandlerClick );
|
||||
|
||||
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 );
|
||||
Util.simulateViewerClickWithDrag( {
|
||||
viewer: viewer,
|
||||
widthFactor: 0.25,
|
||||
@ -82,27 +112,80 @@
|
||||
dragDx: 1,
|
||||
dragDy: 1
|
||||
} );
|
||||
$canvas.simulate( 'blur', event );
|
||||
};
|
||||
|
||||
var canvasDragHandler = function ( eventSender, eventData ) {
|
||||
dragMovesHandled++;
|
||||
var onEventHandlerDrag = function ( eventSender, eventData ) {
|
||||
dragsHandledEventHandler++;
|
||||
};
|
||||
|
||||
var canvasReleaseHandler = function ( eventSender, eventData ) {
|
||||
releasesHandled++;
|
||||
var onEventHandlerRelease = function ( eventSender, eventData ) {
|
||||
releasesHandledEventHandler++;
|
||||
};
|
||||
|
||||
var canvasClickHandler = function ( eventSender, eventData ) {
|
||||
viewer.removeHandler( 'canvas-drag', canvasDragHandler );
|
||||
viewer.removeHandler( 'canvas-release', canvasReleaseHandler );
|
||||
viewer.removeHandler( 'canvas-click', canvasClickHandler );
|
||||
equal( dragMovesHandled, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
|
||||
equal( releasesHandled, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
|
||||
var onEventHandlerClick = function ( eventSender, eventData ) {
|
||||
clicksHandledEventHandler++;
|
||||
};
|
||||
|
||||
var checkOriginalEventReceived = function ( eventData ) {
|
||||
eventsHandledMouseTracker++;
|
||||
if ( eventData && eventData.originalEvent ) {
|
||||
originalEventsPassedMouseTracker++;
|
||||
}
|
||||
};
|
||||
|
||||
var onMouseTrackerFocus = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerBlur = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerEnter = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerPress = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerMove = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerDrag = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerRelease = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerClick = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
};
|
||||
|
||||
var onMouseTrackerExit = function ( tracker, eventData ) {
|
||||
checkOriginalEventReceived( eventData );
|
||||
|
||||
mouseTracker.destroy();
|
||||
viewer.removeHandler( 'canvas-drag', onEventHandlerDrag );
|
||||
viewer.removeHandler( 'canvas-release', onEventHandlerRelease );
|
||||
viewer.removeHandler( 'canvas-click', onEventHandlerClick );
|
||||
|
||||
equal( dragsHandledEventHandler, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
|
||||
equal( releasesHandledEventHandler, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
|
||||
equal( clicksHandledEventHandler, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" );
|
||||
|
||||
equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" );
|
||||
deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' );
|
||||
|
||||
viewer.close();
|
||||
start();
|
||||
};
|
||||
|
||||
viewer.addHandler( 'open', openHandler );
|
||||
viewer.addHandler( 'open', onOpen );
|
||||
viewer.open( '/test/data/testpattern.dzi' );
|
||||
} );
|
||||
|
||||
|
@ -46,7 +46,8 @@
|
||||
.simulate( "mousemove", event );
|
||||
}
|
||||
$canvas
|
||||
.simulate( 'mouseup', event );
|
||||
.simulate( 'mouseup', event )
|
||||
.simulate( 'mouseout', event );
|
||||
},
|
||||
|
||||
initializeTestDOM: function () {
|
||||
|
Loading…
Reference in New Issue
Block a user