openseadragon/test/test.js
Chris Adams 59a254bea6 Tests: add open failure tests, overhaul test framework
* Add tests for open failures
* Refactor tests to avoid tests depending on implied status from
  previous tests:
  1. The viewer is now created and destroyed for each
     test to avoid pollution and simplify error handling: nothing
     starts until you request it.
  2. Some tests like Basic: Homepage depended on the Zoom & Pan tests;
     now this is handled explicitly as part of the test setup
  3. All basic tests are now properly async tests (since they needed
     the viewer to load, they really were in the past except that
     they were relying on the viewer state left behind from previous
     tests)
* All tests now run inside the qunit-fixture to prevent masking
  failures. Util.resetDom() has been refactored to use the
  qunit-fixture and the teardown logic only used in the navigator
  tests has been moved into the navigator test teardown method
* Fixed undeclared mainViewerElement variable in optional path in
  the navigator tests
* JSHint cleanup
2013-07-01 18:26:44 -04:00

76 lines
2.4 KiB
JavaScript

/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util */
(function() {
// ----------
window.Util = {
// ----------
simulateViewerClick: function(viewer, widthFactor, heightFactor) {
if (widthFactor === undefined) {
widthFactor = 0.5;
}
//TODO Redefine to be the middle by default
if (heightFactor === undefined) {
heightFactor = 0.5;
}
widthFactor = Math.min(1, Math.max(0, widthFactor));
//TODO Fix this. The max height should be 1/AR
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);
},
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>');
},
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);
},
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();
}
}
};
}
};
})();