mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
Update test helpers, basic tests, and polyfill tests
This commit is contained in:
parent
bfb00656cc
commit
2af7db43a4
@ -1,4 +1,4 @@
|
|||||||
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util */
|
/* global QUnit, $, Util */
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
@ -64,14 +64,14 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
assessNumericValue: function ( value1, value2, variance, message ) {
|
assessNumericValue: function ( value1, value2, variance, message, assert ) {
|
||||||
ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance );
|
assert.ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance );
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
assertPointsEquals: function (pointA, pointB, precision, message) {
|
assertPointsEquals: function (pointA, pointB, precision, message, assert) {
|
||||||
Util.assessNumericValue(pointA.x, pointB.x, precision, message + " x: ");
|
Util.assessNumericValue(pointA.x, pointB.x, precision, message + " x: ", assert);
|
||||||
Util.assessNumericValue(pointA.y, pointB.y, precision, message + " y: ");
|
Util.assessNumericValue(pointA.y, pointB.y, precision, message + " y: ", assert);
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
@ -87,15 +87,16 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
timeWatcher: function ( time ) {
|
timeWatcher: function ( time, assert ) {
|
||||||
|
var done = assert.async();
|
||||||
time = time || 2000;
|
time = time || 2000;
|
||||||
var finished = false;
|
var finished = false;
|
||||||
|
|
||||||
setTimeout( function () {
|
setTimeout( function () {
|
||||||
if ( !finished ) {
|
if ( !finished ) {
|
||||||
finished = true;
|
finished = true;
|
||||||
ok( false, 'finishes in ' + time + 'ms' );
|
assert.ok( false, 'finishes in ' + time + 'ms' );
|
||||||
start();
|
done();
|
||||||
}
|
}
|
||||||
}, time );
|
}, time );
|
||||||
|
|
||||||
@ -103,7 +104,7 @@
|
|||||||
done: function () {
|
done: function () {
|
||||||
if ( !finished ) {
|
if ( !finished ) {
|
||||||
finished = true;
|
finished = true;
|
||||||
start();
|
done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -124,7 +125,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
testDeprecation: function(obj0, member0, obj1, member1) {
|
testDeprecation: function(obj0, member0, obj1, member1, assert) {
|
||||||
var called = false;
|
var called = false;
|
||||||
var errored = false;
|
var errored = false;
|
||||||
|
|
||||||
@ -144,8 +145,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
obj0[member0]();
|
obj0[member0]();
|
||||||
equal(called, true, 'called through for ' + member0);
|
assert.equal(called, true, 'called through for ' + member0);
|
||||||
equal(errored, true, 'errored for ' + member0);
|
assert.equal(errored, true, 'errored for ' + member0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
/* global QUnit, $, Util, testLog */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var viewer;
|
var viewer;
|
||||||
|
|
||||||
module('Basic', {
|
QUnit.module('Basic', {
|
||||||
setup: function () {
|
beforeEach: function () {
|
||||||
var example = $('<div id="example"></div>').appendTo("#qunit-fixture");
|
$('<div id="example"></div>').appendTo("#qunit-fixture");
|
||||||
|
|
||||||
testLog.reset();
|
testLog.reset();
|
||||||
|
|
||||||
@ -15,7 +15,7 @@
|
|||||||
springStiffness: 100 // Faster animation = faster tests
|
springStiffness: 100 // Faster animation = faster tests
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
teardown: function () {
|
afterEach: function () {
|
||||||
if (viewer && viewer.close) {
|
if (viewer && viewer.close) {
|
||||||
viewer.close();
|
viewer.close();
|
||||||
}
|
}
|
||||||
@ -25,57 +25,59 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest('Open', function() {
|
QUnit.test('Open', function(assert) {
|
||||||
ok(viewer, 'Viewer exists');
|
var done = assert.async();
|
||||||
|
assert.ok(viewer, 'Viewer exists');
|
||||||
|
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
viewer.removeHandler('open', openHandler);
|
viewer.removeHandler('open', openHandler);
|
||||||
ok(true, 'Open event was sent');
|
assert.ok(true, 'Open event was sent');
|
||||||
ok(event, 'Handler received event data');
|
assert.ok(event, 'Handler received event data');
|
||||||
equal(event.eventSource, viewer, 'Sender of open event was viewer');
|
assert.equal(event.eventSource, viewer, 'Sender of open event was viewer');
|
||||||
ok(viewer.viewport, 'Viewport exists');
|
assert.ok(viewer.viewport, 'Viewport exists');
|
||||||
ok(viewer.source, 'source exists');
|
assert.ok(viewer.source, 'source exists');
|
||||||
ok(viewer._updateRequestId, 'timer is on');
|
assert.ok(viewer._updateRequestId, 'timer is on');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('open', openHandler);
|
viewer.addHandler('open', openHandler);
|
||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('Open Error Handling', function() {
|
QUnit.test('Open Error Handling', function(assert) {
|
||||||
ok(viewer, 'Viewer exists');
|
var done = assert.async();
|
||||||
|
assert.ok(viewer, 'Viewer exists');
|
||||||
|
|
||||||
viewer.addHandler('open', function(event) {
|
viewer.addHandler('open', function(event) {
|
||||||
ok(false, "The open event should not fire for failed opens");
|
assert.ok(false, "The open event should not fire for failed opens");
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
viewer.addHandler('open-failed', function(event) {
|
viewer.addHandler('open-failed', function(event) {
|
||||||
ok(true, "The open-failed event should be fired when the source 404s");
|
assert.ok(true, "The open-failed event should be fired when the source 404s");
|
||||||
|
|
||||||
equal($(".openseadragon-message").length, 1, "Open failures should display a message");
|
assert.equal($(".openseadragon-message").length, 1, "Open failures should display a message");
|
||||||
|
|
||||||
ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
|
assert.ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
|
||||||
"AJAX failures should be logged to the console");
|
"AJAX failures should be logged to the console");
|
||||||
|
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
viewer.open('/test/data/not-a-real-file');
|
viewer.open('/test/data/not-a-real-file');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Zoom', function(assert) {
|
||||||
asyncTest('Zoom', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
var viewport = viewer.viewport;
|
var viewport = viewer.viewport;
|
||||||
|
|
||||||
equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
assert.equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
||||||
|
|
||||||
var zoomHandler = function() {
|
var zoomHandler = function() {
|
||||||
viewer.removeHandler('animation-finish', zoomHandler);
|
viewer.removeHandler('animation-finish', zoomHandler);
|
||||||
equal(viewport.getZoom(), 2, 'Zoomed correctly');
|
assert.equal(viewport.getZoom(), 2, 'Zoomed correctly');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('animation-finish', zoomHandler);
|
viewer.addHandler('animation-finish', zoomHandler);
|
||||||
@ -84,20 +86,20 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Pan', function(assert) {
|
||||||
asyncTest('Pan', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
var viewport = viewer.viewport,
|
var viewport = viewer.viewport,
|
||||||
center = viewport.getCenter();
|
center = viewport.getCenter();
|
||||||
|
|
||||||
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
assert.ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
||||||
|
|
||||||
var panHandler = function() {
|
var panHandler = function() {
|
||||||
viewer.removeHandler('animation-finish', panHandler);
|
viewer.removeHandler('animation-finish', panHandler);
|
||||||
center = viewport.getCenter();
|
center = viewport.getCenter();
|
||||||
Util.assessNumericValue(center.x, 0.1, 0.00001, 'panned horizontally');
|
Util.assessNumericValue(center.x, 0.1, 0.00001, 'panned horizontally', assert);
|
||||||
Util.assessNumericValue(center.y, 0.1, 0.00001, 'panned vertically');
|
Util.assessNumericValue(center.y, 0.1, 0.00001, 'panned vertically', assert);
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('animation-finish', panHandler);
|
viewer.addHandler('animation-finish', panHandler);
|
||||||
@ -107,9 +109,9 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Home', function(assert) {
|
||||||
asyncTest('Home', function() {
|
var done = assert.async();
|
||||||
// Test setup:
|
// Test beforeEach:
|
||||||
function opener() {
|
function opener() {
|
||||||
var viewport = viewer.viewport;
|
var viewport = viewer.viewport;
|
||||||
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
|
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
|
||||||
@ -122,15 +124,15 @@
|
|||||||
|
|
||||||
viewer.removeHandler('animation-finish', stage1);
|
viewer.removeHandler('animation-finish', stage1);
|
||||||
|
|
||||||
ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned');
|
assert.ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned');
|
||||||
notEqual(viewport.getZoom(), 1, 'We start out zoomed');
|
assert.notEqual(viewport.getZoom(), 1, 'We start out zoomed');
|
||||||
|
|
||||||
var homeHandler = function() {
|
var homeHandler = function() {
|
||||||
viewer.removeHandler('animation-finish', homeHandler);
|
viewer.removeHandler('animation-finish', homeHandler);
|
||||||
center = viewport.getCenter();
|
center = viewport.getCenter();
|
||||||
ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned');
|
assert.ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned');
|
||||||
equal(viewport.getZoom(), 1, 'We end up unzoomed');
|
assert.equal(viewport.getZoom(), 1, 'We end up unzoomed');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('animation-finish', homeHandler);
|
viewer.addHandler('animation-finish', homeHandler);
|
||||||
@ -143,21 +145,21 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Click', function(assert) {
|
||||||
asyncTest('Click', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
var viewport = viewer.viewport,
|
var viewport = viewer.viewport,
|
||||||
center = viewport.getCenter();
|
center = viewport.getCenter();
|
||||||
|
|
||||||
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
assert.ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
||||||
equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
assert.equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
||||||
|
|
||||||
var clickHandler = function() {
|
var clickHandler = function() {
|
||||||
viewer.removeHandler('animation-finish', clickHandler);
|
viewer.removeHandler('animation-finish', clickHandler);
|
||||||
center = viewport.getCenter();
|
center = viewport.getCenter();
|
||||||
ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly');
|
assert.ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly');
|
||||||
equal(viewport.getZoom(), 2, 'Zoomed correctly');
|
assert.equal(viewport.getZoom(), 2, 'Zoomed correctly');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('animation-finish', clickHandler);
|
viewer.addHandler('animation-finish', clickHandler);
|
||||||
@ -174,39 +176,39 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('FullPage', function(assert) {
|
||||||
asyncTest('FullPage', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
ok(!viewer.isFullPage(), 'Started out not fullpage');
|
assert.ok(!viewer.isFullPage(), 'Started out not fullpage');
|
||||||
ok(!$(viewer.element).hasClass('fullpage'),
|
assert.ok(!$(viewer.element).hasClass('fullpage'),
|
||||||
'No fullpage class on div');
|
'No fullpage class on div');
|
||||||
|
|
||||||
var checkEnteringPreFullPage = function(event) {
|
var checkEnteringPreFullPage = function(event) {
|
||||||
viewer.removeHandler('pre-full-page', checkEnteringPreFullPage);
|
viewer.removeHandler('pre-full-page', checkEnteringPreFullPage);
|
||||||
ok(event.fullPage, 'Switching to fullpage');
|
assert.ok(event.fullPage, 'Switching to fullpage');
|
||||||
ok(!viewer.isFullPage(), 'Not yet fullpage');
|
assert.ok(!viewer.isFullPage(), 'Not yet fullpage');
|
||||||
};
|
};
|
||||||
|
|
||||||
var checkEnteringFullPage = function(event) {
|
var checkEnteringFullPage = function(event) {
|
||||||
viewer.removeHandler('full-page', checkEnteringFullPage);
|
viewer.removeHandler('full-page', checkEnteringFullPage);
|
||||||
ok(event.fullPage, 'Switched to fullpage');
|
assert.ok(event.fullPage, 'Switched to fullpage');
|
||||||
ok(viewer.isFullPage(), 'Enabled fullpage');
|
assert.ok(viewer.isFullPage(), 'Enabled fullpage');
|
||||||
ok($(viewer.element).hasClass('fullpage'),
|
assert.ok($(viewer.element).hasClass('fullpage'),
|
||||||
'Fullpage class added to div');
|
'Fullpage class added to div');
|
||||||
|
|
||||||
var checkExitingPreFullPage = function(event) {
|
var checkExitingPreFullPage = function(event) {
|
||||||
viewer.removeHandler('pre-full-page', checkExitingPreFullPage);
|
viewer.removeHandler('pre-full-page', checkExitingPreFullPage);
|
||||||
ok(!event.fullPage, 'Exiting fullpage');
|
assert.ok(!event.fullPage, 'Exiting fullpage');
|
||||||
ok(viewer.isFullPage(), 'Still fullpage');
|
assert.ok(viewer.isFullPage(), 'Still fullpage');
|
||||||
};
|
};
|
||||||
|
|
||||||
var checkExitingFullPage = function(event) {
|
var checkExitingFullPage = function(event) {
|
||||||
viewer.removeHandler('full-page', checkExitingFullPage);
|
viewer.removeHandler('full-page', checkExitingFullPage);
|
||||||
ok(!event.fullPage, 'Exiting fullpage');
|
assert.ok(!event.fullPage, 'Exiting fullpage');
|
||||||
ok(!viewer.isFullPage(), 'Disabled fullpage');
|
assert.ok(!viewer.isFullPage(), 'Disabled fullpage');
|
||||||
ok(!$(viewer.element).hasClass('fullpage'),
|
assert.ok(!$(viewer.element).hasClass('fullpage'),
|
||||||
'Fullpage class removed from div');
|
'Fullpage class removed from div');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler("pre-full-page", checkExitingPreFullPage);
|
viewer.addHandler("pre-full-page", checkExitingPreFullPage);
|
||||||
@ -221,30 +223,30 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('FullScreen', function() {
|
QUnit.test('FullScreen', function(assert) {
|
||||||
|
var done = assert.async();
|
||||||
if (!OpenSeadragon.supportsFullScreen) {
|
if (!OpenSeadragon.supportsFullScreen) {
|
||||||
expect(0);
|
assert.expect(0);
|
||||||
start();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen');
|
assert.ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen');
|
||||||
|
|
||||||
var checkEnteringPreFullScreen = function(event) {
|
var checkEnteringPreFullScreen = function(event) {
|
||||||
viewer.removeHandler('pre-full-screen', checkEnteringPreFullScreen);
|
viewer.removeHandler('pre-full-screen', checkEnteringPreFullScreen);
|
||||||
ok(event.fullScreen, 'Switching to fullscreen');
|
assert.ok(event.fullScreen, 'Switching to fullscreen');
|
||||||
ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen');
|
assert.ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen');
|
||||||
};
|
};
|
||||||
|
|
||||||
// The fullscreen mode is always denied during tests so we are
|
// The fullscreen mode is always denied during tests so we are
|
||||||
// exiting directly.
|
// exiting directly.
|
||||||
var checkExitingFullScreen = function(event) {
|
var checkExitingFullScreen = function(event) {
|
||||||
viewer.removeHandler('full-screen', checkExitingFullScreen);
|
viewer.removeHandler('full-screen', checkExitingFullScreen);
|
||||||
ok(!event.fullScreen, 'Exiting fullscreen');
|
assert.ok(!event.fullScreen, 'Exiting fullscreen');
|
||||||
ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen');
|
assert.ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen');
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
viewer.addHandler("pre-full-screen", checkEnteringPreFullScreen);
|
viewer.addHandler("pre-full-screen", checkEnteringPreFullScreen);
|
||||||
viewer.addHandler("full-screen", checkExitingFullScreen);
|
viewer.addHandler("full-screen", checkExitingFullScreen);
|
||||||
@ -254,16 +256,16 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Close', function(assert) {
|
||||||
asyncTest('Close', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
var closeHandler = function() {
|
var closeHandler = function() {
|
||||||
viewer.removeHandler('close', closeHandler);
|
viewer.removeHandler('close', closeHandler);
|
||||||
ok(!viewer.source, 'no source');
|
assert.ok(!viewer.source, 'no source');
|
||||||
ok(true, 'Close event was sent');
|
assert.ok(true, 'Close event was sent');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok(!viewer._updateRequestId, 'timer is off');
|
assert.ok(!viewer._updateRequestId, 'timer is off');
|
||||||
start();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -273,11 +275,11 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
QUnit.test('Destroy', function(assert) {
|
||||||
asyncTest('Destroy', function() {
|
var done = assert.async();
|
||||||
viewer.addHandler("open", function () {
|
viewer.addHandler("open", function () {
|
||||||
// Check that the DOM has been modified
|
// Check that the DOM has been modified
|
||||||
notEqual(0, $('#example').children().length);
|
assert.notEqual(0, $('#example').children().length);
|
||||||
|
|
||||||
var closeCalled = false;
|
var closeCalled = false;
|
||||||
var closeHandler = function() {
|
var closeHandler = function() {
|
||||||
@ -289,14 +291,14 @@
|
|||||||
viewer.destroy();
|
viewer.destroy();
|
||||||
|
|
||||||
// Check that the DOM has been cleaned up
|
// Check that the DOM has been cleaned up
|
||||||
equal(0, $('#example').children().length);
|
assert.equal(0, $('#example').children().length);
|
||||||
equal(null, viewer.canvas);
|
assert.equal(null, viewer.canvas);
|
||||||
equal(null, viewer.keyboardCommandArea);
|
assert.equal(null, viewer.keyboardCommandArea);
|
||||||
equal(null, viewer.container);
|
assert.equal(null, viewer.container);
|
||||||
equal(null, viewer.element);
|
assert.equal(null, viewer.element);
|
||||||
equal(true, closeCalled);
|
assert.equal(true, closeCalled);
|
||||||
viewer = null;
|
viewer = null;
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
@ -319,8 +321,8 @@
|
|||||||
img.src = corsImg;
|
img.src = corsImg;
|
||||||
}
|
}
|
||||||
|
|
||||||
asyncTest( 'CrossOriginPolicyMissing', function () {
|
QUnit.test( 'CrossOriginPolicyMissing', function (assert) {
|
||||||
|
var done = assert.async();
|
||||||
viewer.crossOriginPolicy = false;
|
viewer.crossOriginPolicy = false;
|
||||||
viewer.smoothTileEdgesMinZoom = Infinity;
|
viewer.smoothTileEdgesMinZoom = Infinity;
|
||||||
viewer.open( {
|
viewer.open( {
|
||||||
@ -332,19 +334,19 @@
|
|||||||
} ]
|
} ]
|
||||||
} );
|
} );
|
||||||
viewer.addOnceHandler('tile-drawn', function() {
|
viewer.addOnceHandler('tile-drawn', function() {
|
||||||
ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
assert.ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||||
"Canvas should be tainted.");
|
"Canvas should be tainted.");
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
asyncTest( 'CrossOriginPolicyAnonymous', function () {
|
QUnit.test( 'CrossOriginPolicyAnonymous', function (assert) {
|
||||||
|
var done = assert.async();
|
||||||
browserSupportsImgCrossOrigin(function(supported) {
|
browserSupportsImgCrossOrigin(function(supported) {
|
||||||
if (!supported) {
|
if (!supported) {
|
||||||
expect(0);
|
assert.expect(0);
|
||||||
start();
|
done();
|
||||||
} else {
|
} else {
|
||||||
viewer.crossOriginPolicy = 'Anonymous';
|
viewer.crossOriginPolicy = 'Anonymous';
|
||||||
viewer.open( {
|
viewer.open( {
|
||||||
@ -356,21 +358,21 @@
|
|||||||
} ]
|
} ]
|
||||||
} );
|
} );
|
||||||
viewer.addOnceHandler('tile-drawn', function() {
|
viewer.addOnceHandler('tile-drawn', function() {
|
||||||
ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
assert.ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||||
"Canvas should not be tainted.");
|
"Canvas should not be tainted.");
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
asyncTest( 'CrossOriginPolicyOption', function () {
|
QUnit.test( 'CrossOriginPolicyOption', function (assert) {
|
||||||
|
var done = assert.async();
|
||||||
browserSupportsImgCrossOrigin(function(supported) {
|
browserSupportsImgCrossOrigin(function(supported) {
|
||||||
if (!supported) {
|
if (!supported) {
|
||||||
expect(0);
|
assert.expect(0);
|
||||||
start();
|
done();
|
||||||
} else {
|
} else {
|
||||||
viewer.crossOriginPolicy = "Anonymous";
|
viewer.crossOriginPolicy = "Anonymous";
|
||||||
viewer.smoothTileEdgesMinZoom = Infinity;
|
viewer.smoothTileEdgesMinZoom = Infinity;
|
||||||
@ -386,20 +388,21 @@
|
|||||||
crossOriginPolicy : false
|
crossOriginPolicy : false
|
||||||
} );
|
} );
|
||||||
viewer.addOnceHandler('tile-drawn', function() {
|
viewer.addOnceHandler('tile-drawn', function() {
|
||||||
ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
assert.ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||||
"Canvas should be tainted.");
|
"Canvas should be tainted.");
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} );
|
} );
|
||||||
asyncTest( 'CrossOriginPolicyTileSource', function () {
|
|
||||||
|
|
||||||
|
QUnit.test( 'CrossOriginPolicyTileSource', function (assert) {
|
||||||
|
var done = assert.async();
|
||||||
browserSupportsImgCrossOrigin(function(supported) {
|
browserSupportsImgCrossOrigin(function(supported) {
|
||||||
if (!supported) {
|
if (!supported) {
|
||||||
expect(0);
|
assert.expect(0);
|
||||||
start();
|
done();
|
||||||
} else {
|
} else {
|
||||||
viewer.crossOriginPolicy = false;
|
viewer.crossOriginPolicy = false;
|
||||||
viewer.smoothTileEdgesMinZoom = Infinity;
|
viewer.smoothTileEdgesMinZoom = Infinity;
|
||||||
@ -415,9 +418,9 @@
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
viewer.addOnceHandler('tile-drawn', function() {
|
viewer.addOnceHandler('tile-drawn', function() {
|
||||||
ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
assert.ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||||
"Canvas should not be tainted.");
|
"Canvas should not be tainted.");
|
||||||
start();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -425,8 +428,9 @@
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
asyncTest('SetDebugMode', function() {
|
QUnit.test('SetDebugMode', function(assert) {
|
||||||
ok(viewer, 'Viewer exists');
|
var done = assert.async();
|
||||||
|
assert.ok(viewer, 'Viewer exists');
|
||||||
|
|
||||||
var checkImageTilesDebugState = function (expectedState) {
|
var checkImageTilesDebugState = function (expectedState) {
|
||||||
|
|
||||||
@ -443,15 +447,15 @@
|
|||||||
|
|
||||||
//Ensure we start with debug mode turned off
|
//Ensure we start with debug mode turned off
|
||||||
viewer.setDebugMode(false);
|
viewer.setDebugMode(false);
|
||||||
ok(checkImageTilesDebugState(false), "All image tiles have debug mode turned off.");
|
assert.ok(checkImageTilesDebugState(false), "All image tiles have debug mode turned off.");
|
||||||
ok(!viewer.debugMode, "Viewer debug mode is turned off.");
|
assert.ok(!viewer.debugMode, "Viewer debug mode is turned off.");
|
||||||
|
|
||||||
//Turn debug mode on and check that the Viewer and all tiled images are in debug mode.
|
//Turn debug mode on and check that the Viewer and all tiled images are in debug mode.
|
||||||
viewer.setDebugMode(true);
|
viewer.setDebugMode(true);
|
||||||
ok(checkImageTilesDebugState(true), "All image tiles have debug mode turned on.");
|
assert.ok(checkImageTilesDebugState(true), "All image tiles have debug mode turned on.");
|
||||||
ok(viewer.debugMode, "Viewer debug mode is turned on.");
|
assert.ok(viewer.debugMode, "Viewer debug mode is turned on.");
|
||||||
|
|
||||||
start();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('open', openHandler);
|
viewer.addHandler('open', openHandler);
|
||||||
@ -460,11 +464,11 @@
|
|||||||
|
|
||||||
//Version numbers are injected by the build process, so skip version tests if we are only running code coverage
|
//Version numbers are injected by the build process, so skip version tests if we are only running code coverage
|
||||||
if(!window.isCoverageTest ){
|
if(!window.isCoverageTest ){
|
||||||
test('version object', function() {
|
QUnit.test('version object', function(assert) {
|
||||||
equal(typeof OpenSeadragon.version.versionStr, "string", "versionStr should be a string");
|
assert.equal(typeof OpenSeadragon.version.versionStr, "string", "versionStr should be a string");
|
||||||
ok(OpenSeadragon.version.major >= 0, "major should be a positive number");
|
assert.ok(OpenSeadragon.version.major >= 0, "major should be a positive number");
|
||||||
ok(OpenSeadragon.version.minor >= 0, "minor should be a positive number");
|
assert.ok(OpenSeadragon.version.minor >= 0, "minor should be a positive number");
|
||||||
ok(OpenSeadragon.version.revision >= 0, "revision should be a positive number");
|
assert.ok(OpenSeadragon.version.revision >= 0, "revision should be a positive number");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
/* global QUnit, $, testLog */
|
||||||
|
|
||||||
( function() {
|
( function() {
|
||||||
|
|
||||||
module( 'Polyfills', {
|
QUnit.module( 'Polyfills', {
|
||||||
setup: function() {
|
beforeEach: function() {
|
||||||
testLog.reset();
|
testLog.reset();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
test( 'pageScroll', function() {
|
QUnit.test( 'pageScroll', function(assert) {
|
||||||
// Setup
|
// Setup
|
||||||
var origWidth = $( "body" ).width(),
|
var origWidth = $( "body" ).width(),
|
||||||
origHeight = $( "body" ).height();
|
origHeight = $( "body" ).height();
|
||||||
@ -23,17 +23,17 @@
|
|||||||
var originalGetPageScroll = OpenSeadragon.getPageScroll;
|
var originalGetPageScroll = OpenSeadragon.getPageScroll;
|
||||||
|
|
||||||
var scroll = OpenSeadragon.getPageScroll();
|
var scroll = OpenSeadragon.getPageScroll();
|
||||||
equal( scroll.x, 0, "Scroll should be 0 at beginning." );
|
assert.equal( scroll.x, 0, "Scroll should be 0 at beginning." );
|
||||||
equal( scroll.y, 0, "Scroll should be 0 at beginning." );
|
assert.equal( scroll.y, 0, "Scroll should be 0 at beginning." );
|
||||||
|
|
||||||
// If window.pageXOffset is not supported, the getPageScroll method should
|
// If window.pageXOffset is not supported, the getPageScroll method should
|
||||||
// not have been redefined
|
// not have been redefined
|
||||||
if ( typeof ( window.pageXOffset ) != "number" ) {
|
if ( typeof ( window.pageXOffset ) != "number" ) {
|
||||||
equal( originalGetPageScroll, OpenSeadragon.getPageScroll,
|
assert.equal( originalGetPageScroll, OpenSeadragon.getPageScroll,
|
||||||
"OpenSeadragon.getPageScroll must not be redefined when on 0,0" +
|
"OpenSeadragon.getPageScroll must not be redefined when on 0,0" +
|
||||||
" and window API is not supported." );
|
" and window API is not supported." );
|
||||||
} else {
|
} else {
|
||||||
notEqual( originalGetPageScroll, OpenSeadragon.getPageScroll,
|
assert.notEqual( originalGetPageScroll, OpenSeadragon.getPageScroll,
|
||||||
"OpenSeadragon.getPageScroll must be redefined when window API " +
|
"OpenSeadragon.getPageScroll must be redefined when window API " +
|
||||||
"is supported." );
|
"is supported." );
|
||||||
}
|
}
|
||||||
@ -41,14 +41,14 @@
|
|||||||
$( document ).scrollLeft( 200 );
|
$( document ).scrollLeft( 200 );
|
||||||
$( document ).scrollTop( 100 );
|
$( document ).scrollTop( 100 );
|
||||||
scroll = originalGetPageScroll();
|
scroll = originalGetPageScroll();
|
||||||
equal( scroll.x, 200, "First call to getScroll." );
|
assert.equal( scroll.x, 200, "First call to getScroll." );
|
||||||
equal( scroll.y, 100, "First call to getScroll." );
|
assert.equal( scroll.y, 100, "First call to getScroll." );
|
||||||
|
|
||||||
$( document ).scrollLeft( 500 );
|
$( document ).scrollLeft( 500 );
|
||||||
$( document ).scrollTop( 600 );
|
$( document ).scrollTop( 600 );
|
||||||
scroll = OpenSeadragon.getPageScroll();
|
scroll = OpenSeadragon.getPageScroll();
|
||||||
equal( scroll.x, 500, "Second call to getScroll." );
|
assert.equal( scroll.x, 500, "Second call to getScroll." );
|
||||||
equal( scroll.y, 600, "Second call to getScroll." );
|
assert.equal( scroll.y, 600, "Second call to getScroll." );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -60,16 +60,16 @@
|
|||||||
$( document ).scrollTop( 0 );
|
$( document ).scrollTop( 0 );
|
||||||
var scroll = new OpenSeadragon.Point( 0, 0 );
|
var scroll = new OpenSeadragon.Point( 0, 0 );
|
||||||
OpenSeadragon.setPageScroll( scroll );
|
OpenSeadragon.setPageScroll( scroll );
|
||||||
equal( $( document ).scrollLeft(), 0, "First call to 0,0 while already on 0,0." );
|
assert.equal( $( document ).scrollLeft(), 0, "First call to 0,0 while already on 0,0." );
|
||||||
equal( $( document ).scrollTop(), 0, "First call to 0,0 while already on 0,0." );
|
assert.equal( $( document ).scrollTop(), 0, "First call to 0,0 while already on 0,0." );
|
||||||
|
|
||||||
// If window.pageXOffset is not supported, the getPageScroll method should
|
// If window.pageXOffset is not supported, the getPageScroll method should
|
||||||
// not have been redefined
|
// not have been redefined
|
||||||
if ( typeof ( window.scrollTo ) === "undefined" ) {
|
if ( typeof ( window.scrollTo ) === "undefined" ) {
|
||||||
equal( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.equal( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"OpenSeadragon.setPageScroll must not be redefined when not moving." );
|
"OpenSeadragon.setPageScroll must not be redefined when not moving." );
|
||||||
} else {
|
} else {
|
||||||
notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"OpenSeadragon.setPageScroll must be redefined when window API is supported." );
|
"OpenSeadragon.setPageScroll must be redefined when window API is supported." );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,16 +79,16 @@
|
|||||||
$( document ).scrollTop( 200 );
|
$( document ).scrollTop( 200 );
|
||||||
var scroll = new OpenSeadragon.Point( 100, 200 );
|
var scroll = new OpenSeadragon.Point( 100, 200 );
|
||||||
OpenSeadragon.setPageScroll( scroll );
|
OpenSeadragon.setPageScroll( scroll );
|
||||||
equal( $( document ).scrollLeft(), 100, "First call to 100,200 while already on 100,200." );
|
assert.equal( $( document ).scrollLeft(), 100, "First call to 100,200 while already on 100,200." );
|
||||||
equal( $( document ).scrollTop(), 200, "First call to 100,200 while already on 100,200." );
|
assert.equal( $( document ).scrollTop(), 200, "First call to 100,200 while already on 100,200." );
|
||||||
|
|
||||||
// If window.pageXOffset is not supported, the getPageScroll method should
|
// If window.pageXOffset is not supported, the getPageScroll method should
|
||||||
// not have been redefined
|
// not have been redefined
|
||||||
if ( typeof ( window.scrollTo ) === "undefined" ) {
|
if ( typeof ( window.scrollTo ) === "undefined" ) {
|
||||||
equal( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.equal( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"OpenSeadragon.setPageScroll must not be redefined when not moving." );
|
"OpenSeadragon.setPageScroll must not be redefined when not moving." );
|
||||||
} else {
|
} else {
|
||||||
notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"OpenSeadragon.setPageScroll must be redefined when window API is supported." );
|
"OpenSeadragon.setPageScroll must be redefined when window API is supported." );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +102,9 @@
|
|||||||
$( document ).scrollTop( 0 );
|
$( document ).scrollTop( 0 );
|
||||||
var scroll = new OpenSeadragon.Point( 20000, 20000 );
|
var scroll = new OpenSeadragon.Point( 20000, 20000 );
|
||||||
OpenSeadragon.setPageScroll( scroll );
|
OpenSeadragon.setPageScroll( scroll );
|
||||||
equal( $( document ).scrollLeft(), actualScrollLeft, "First call to position above limits." );
|
assert.equal( $( document ).scrollLeft(), actualScrollLeft, "First call to position above limits." );
|
||||||
equal( $( document ).scrollTop(), actualScrollTop, "First call to position above limits." );
|
assert.equal( $( document ).scrollTop(), actualScrollTop, "First call to position above limits." );
|
||||||
notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"Even if outside scroll limits, OpenSeadragon.setPageScroll can be " +
|
"Even if outside scroll limits, OpenSeadragon.setPageScroll can be " +
|
||||||
"reassigned on first call." );
|
"reassigned on first call." );
|
||||||
|
|
||||||
@ -112,9 +112,9 @@
|
|||||||
var currentSetPageScroll = OpenSeadragon.setPageScroll;
|
var currentSetPageScroll = OpenSeadragon.setPageScroll;
|
||||||
var scroll = new OpenSeadragon.Point( 200, 200 );
|
var scroll = new OpenSeadragon.Point( 200, 200 );
|
||||||
OpenSeadragon.setPageScroll( scroll );
|
OpenSeadragon.setPageScroll( scroll );
|
||||||
equal( $( document ).scrollLeft(), 200, "Second call." );
|
assert.equal( $( document ).scrollLeft(), 200, "Second call." );
|
||||||
equal( $( document ).scrollTop(), 200, "Second call." );
|
assert.equal( $( document ).scrollTop(), 200, "Second call." );
|
||||||
equal( currentSetPageScroll, OpenSeadragon.setPageScroll,
|
assert.equal( currentSetPageScroll, OpenSeadragon.setPageScroll,
|
||||||
"OpenSeadragon.setPageScroll must not be reassigned after first call." );
|
"OpenSeadragon.setPageScroll must not be reassigned after first call." );
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user