2013-07-02 02:17:45 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util */
|
|
|
|
|
2013-03-22 00:44:22 +04:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
window.Util = {
|
|
|
|
// ----------
|
|
|
|
simulateViewerClick: function(viewer, widthFactor, heightFactor) {
|
|
|
|
if (widthFactor === undefined) {
|
|
|
|
widthFactor = 0.5;
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-31 05:53:22 +04:00
|
|
|
//TODO Redefine to be the middle by default
|
2013-03-22 00:44:22 +04:00
|
|
|
if (heightFactor === undefined) {
|
|
|
|
heightFactor = 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
widthFactor = Math.min(1, Math.max(0, widthFactor));
|
2013-03-31 05:53:22 +04:00
|
|
|
//TODO Fix this. The max height should be 1/AR
|
2013-03-22 00:44:22 +04:00
|
|
|
heightFactor = Math.min(1, Math.max(0, heightFactor));
|
|
|
|
|
|
|
|
var $canvas = $(viewer.element).find('.openseadragon-canvas').not('.navigator .openseadragon-canvas');
|
|
|
|
var offset = $canvas.offset();
|
|
|
|
var event = {
|
|
|
|
clientX: offset.left + Math.floor($canvas.width() * widthFactor),
|
|
|
|
clientY: offset.top + Math.floor($canvas.height() * heightFactor)
|
|
|
|
};
|
|
|
|
|
|
|
|
$canvas
|
|
|
|
.simulate('mouseover', event)
|
|
|
|
.simulate('mousedown', event)
|
|
|
|
.simulate('mouseup', event);
|
2013-04-05 06:30:59 +04:00
|
|
|
},
|
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
initializeTestDOM: function () {
|
|
|
|
$("#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
|
|
|
},
|
|
|
|
|
|
|
|
equalsWithVariance: function (value1, value2, variance) {
|
|
|
|
return Math.abs(value1 - value2) <= variance;
|
|
|
|
},
|
|
|
|
|
|
|
|
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-05-10 22:53:49 +04:00
|
|
|
timeWatcher: function(time) {
|
|
|
|
time = time || 2000;
|
|
|
|
var finished = false;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
if (!finished) {
|
|
|
|
finished = true;
|
|
|
|
ok(false, 'finishes in ' + time + 'ms');
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
}, time);
|
|
|
|
|
|
|
|
return {
|
|
|
|
done: function() {
|
|
|
|
if (!finished) {
|
|
|
|
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
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
var testConsole = window.testConsole = {},
|
|
|
|
testLog = window.testLog = {
|
|
|
|
log: [],
|
|
|
|
debug: [],
|
|
|
|
info: [],
|
|
|
|
warn: [],
|
|
|
|
error: [],
|
|
|
|
reset: function () {
|
|
|
|
for (var i in testLog) {
|
2013-07-03 00:09:19 +04:00
|
|
|
if (testLog.hasOwnProperty(i) && 'length' in testLog[i] && 'push' in testLog[i]) {
|
2013-07-02 23:12:16 +04:00
|
|
|
testLog[i].length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i in testLog) {
|
|
|
|
if (testLog.hasOwnProperty(i) && testLog[i].push) {
|
|
|
|
testConsole[i] = (function (arr) {
|
|
|
|
return function () {
|
|
|
|
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
|
|
|
|
};
|
|
|
|
})(testLog[i]);
|
|
|
|
|
|
|
|
testLog[i].contains = function (needle) {
|
|
|
|
return this.indexOf(needle) > -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenSeadragon.console = testConsole;
|
2013-04-09 04:59:16 +04:00
|
|
|
})();
|
|
|
|
|