2013-07-02 02:17:45 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util */
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
(function () {
|
2013-03-22 00:44:22 +04:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
window.Util = {
|
|
|
|
// ----------
|
2013-08-30 00:01:07 +04:00
|
|
|
simulateViewerClickWithDrag: function ( args ) {
|
|
|
|
// args = { viewer, widthFactor, heightFactor, dragCount, dragDx, dragDy }
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-08-30 00:01:07 +04:00
|
|
|
if ( args.hasOwnProperty( 'dragCount' ) ) {
|
|
|
|
args.dragDx = args.dragDx || 1;
|
|
|
|
args.dragDy = args.dragDy || 1;
|
2013-03-22 00:44:22 +04:00
|
|
|
}
|
2013-08-30 00:01:07 +04:00
|
|
|
else {
|
|
|
|
args.dragCount = 0;
|
2013-08-28 22:33:41 +04:00
|
|
|
}
|
|
|
|
|
2013-08-30 00:01:07 +04:00
|
|
|
if ( args.widthFactor === undefined ) {
|
|
|
|
args.widthFactor = 0.5;
|
2013-08-28 22:33:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO Redefine to be the middle by default
|
2013-08-30 00:01:07 +04:00
|
|
|
if ( args.heightFactor === undefined ) {
|
|
|
|
args.heightFactor = 0.5;
|
2013-08-28 22:33:41 +04:00
|
|
|
}
|
|
|
|
|
2013-08-30 00:01:07 +04:00
|
|
|
args.widthFactor = Math.min( 1, Math.max( 0, args.widthFactor ) );
|
2013-08-28 22:33:41 +04:00
|
|
|
//TODO Fix this. The max height should be 1/AR
|
2013-08-30 00:01:07 +04:00
|
|
|
args.heightFactor = Math.min( 1, Math.max( 0, args.heightFactor ) );
|
2013-08-28 22:33:41 +04:00
|
|
|
|
2013-08-30 00:01:07 +04:00
|
|
|
var $canvas = $( args.viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' );
|
2013-08-28 22:33:41 +04:00
|
|
|
var offset = $canvas.offset();
|
|
|
|
var event = {
|
2013-08-30 00:01:07 +04:00
|
|
|
clientX: offset.left + Math.floor( $canvas.width() * args.widthFactor ),
|
|
|
|
clientY: offset.top + Math.floor( $canvas.height() * args.heightFactor )
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$canvas
|
2014-04-16 01:16:10 +04:00
|
|
|
.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseenter' : 'mouseover', event )
|
2013-08-28 22:33:41 +04:00
|
|
|
.simulate( 'mousedown', event );
|
2013-08-30 00:01:07 +04:00
|
|
|
for ( var i = 0; i < args.dragCount; i++ ) {
|
|
|
|
event.clientX += args.dragDx;
|
|
|
|
event.clientY += args.dragDy;
|
2013-08-28 22:33:41 +04:00
|
|
|
$canvas
|
|
|
|
.simulate( "mousemove", event );
|
|
|
|
}
|
|
|
|
$canvas
|
2013-09-20 20:17:48 +04:00
|
|
|
.simulate( 'mouseup', event )
|
2014-04-16 01:16:10 +04:00
|
|
|
.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', event );
|
2013-04-05 06:30:59 +04:00
|
|
|
},
|
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
initializeTestDOM: function () {
|
2013-08-28 22:33:41 +04:00
|
|
|
$( "#qunit-fixture" )
|
|
|
|
.append( '<div><div id="example"></div><div id="exampleNavigator"></div></div>' )
|
|
|
|
.append( '<div id="wideexample"></div>' )
|
|
|
|
.append( '<div id="tallexample"></div>' );
|
2013-04-05 06:30:59 +04:00
|
|
|
},
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
equalsWithVariance: function ( value1, value2, variance ) {
|
|
|
|
return Math.abs( value1 - value2 ) <= variance;
|
2013-04-05 06:30:59 +04:00
|
|
|
},
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
assessNumericValue: function ( value1, value2, variance, message ) {
|
|
|
|
ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance );
|
2013-05-18 06:29:08 +04:00
|
|
|
},
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
timeWatcher: function ( time ) {
|
2013-05-10 22:53:49 +04:00
|
|
|
time = time || 2000;
|
|
|
|
var finished = false;
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
setTimeout( function () {
|
|
|
|
if ( !finished ) {
|
2013-05-10 22:53:49 +04:00
|
|
|
finished = true;
|
2013-08-28 22:33:41 +04:00
|
|
|
ok( false, 'finishes in ' + time + 'ms' );
|
2013-05-10 22:53:49 +04:00
|
|
|
start();
|
|
|
|
}
|
2013-08-28 22:33:41 +04:00
|
|
|
}, time );
|
2013-05-10 22:53:49 +04:00
|
|
|
|
|
|
|
return {
|
2013-08-28 22:33:41 +04:00
|
|
|
done: function () {
|
|
|
|
if ( !finished ) {
|
2013-05-10 22:53:49 +04:00
|
|
|
finished = true;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-03-22 00:44:22 +04:00
|
|
|
}
|
2013-03-31 05:53:22 +04:00
|
|
|
|
2013-03-22 00:44:22 +04:00
|
|
|
};
|
|
|
|
|
2013-07-02 23:12:16 +04:00
|
|
|
/*
|
2013-08-28 22:33:41 +04:00
|
|
|
Test console log capture
|
|
|
|
|
|
|
|
1. Only the OpenSeadragon.console logger is touched
|
|
|
|
2. All log messages are stored in window.testLog in arrays keyed on the logger name (e.g. log,
|
|
|
|
warning, error, etc.) as JSON-serialized strings to simplify comparisons
|
|
|
|
3. The captured log arrays have a custom contains() method for ease of testing
|
|
|
|
4. testLog.reset() will clear all of the message arrays, intended for use in test setup routines
|
|
|
|
*/
|
2013-07-02 23:12:16 +04:00
|
|
|
var testConsole = window.testConsole = {},
|
|
|
|
testLog = window.testLog = {
|
2013-08-28 22:33:41 +04:00
|
|
|
log: [],
|
|
|
|
debug: [],
|
|
|
|
info: [],
|
|
|
|
warn: [],
|
|
|
|
error: [],
|
2013-07-02 23:12:16 +04:00
|
|
|
reset: function () {
|
2013-08-28 22:33:41 +04:00
|
|
|
for ( var i in testLog ) {
|
|
|
|
if ( testLog.hasOwnProperty( i ) && 'length' in testLog[i] && 'push' in testLog[i] ) {
|
2013-07-02 23:12:16 +04:00
|
|
|
testLog[i].length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
for ( var i in testLog ) {
|
|
|
|
if ( testLog.hasOwnProperty( i ) && testLog[i].push ) {
|
|
|
|
testConsole[i] = ( function ( arr ) {
|
2013-07-02 23:12:16 +04:00
|
|
|
return function () {
|
2013-08-28 22:33:41 +04:00
|
|
|
var args = Array.prototype.slice.call( arguments, 0 ); // Coerce to true Array
|
|
|
|
arr.push( JSON.stringify( args ) ); // Store as JSON to avoid tedious array-equality tests
|
2013-07-02 23:12:16 +04:00
|
|
|
};
|
2013-08-28 22:33:41 +04:00
|
|
|
} )( testLog[i] );
|
2013-07-02 23:12:16 +04:00
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
testLog[i].contains = function ( needle ) {
|
|
|
|
for ( var i = 0; i < this.length; i++ ) {
|
|
|
|
if ( this[i] == needle ) {
|
2013-07-03 00:20:56 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-02 23:12:16 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenSeadragon.console = testConsole;
|
2013-08-28 22:33:41 +04:00
|
|
|
} )();
|
2013-04-09 04:59:16 +04:00
|
|
|
|