2013-07-02 23:12:31 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
2013-06-27 00:54:37 +04:00
|
|
|
|
2013-02-14 22:21:07 +04:00
|
|
|
(function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
var viewer;
|
2013-02-14 22:21:07 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
module('Basic', {
|
|
|
|
setup: function () {
|
|
|
|
var example = $('<div id="example"></div>').appendTo("#qunit-fixture");
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-07-02 23:12:31 +04:00
|
|
|
testLog.reset();
|
|
|
|
|
2013-03-07 23:52:01 +04:00
|
|
|
viewer = OpenSeadragon({
|
2013-03-07 22:44:08 +04:00
|
|
|
id: 'example',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2013-06-18 22:08:16 +04:00
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
2013-03-07 22:44:08 +04:00
|
|
|
});
|
2013-07-02 02:17:45 +04:00
|
|
|
},
|
|
|
|
teardown: function () {
|
2013-07-02 21:56:55 +04:00
|
|
|
if (viewer && viewer.close) {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest('Open', function() {
|
|
|
|
ok(viewer, 'Viewer exists');
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var openHandler = function(event) {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
ok(true, 'Open event was sent');
|
2013-10-11 04:00:15 +04:00
|
|
|
ok(event, 'Handler received event data');
|
|
|
|
equal(event.eventSource, viewer, 'Sender of open event was viewer');
|
2013-07-02 02:17:45 +04:00
|
|
|
ok(viewer.viewport, 'Viewport exists');
|
|
|
|
ok(viewer.source, 'source exists');
|
|
|
|
ok(viewer._updateRequestId, 'timer is on');
|
|
|
|
start();
|
|
|
|
};
|
2013-03-07 22:44:08 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
asyncTest('Open Error Handling', function() {
|
|
|
|
ok(viewer, 'Viewer exists');
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
viewer.addHandler('open', function(event) {
|
2013-07-02 02:17:45 +04:00
|
|
|
ok(false, "The open event should not fire for failed opens");
|
|
|
|
start();
|
2013-03-07 22:44:08 +04:00
|
|
|
});
|
2013-07-02 02:17:45 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
viewer.addHandler('open-failed', function(event) {
|
2013-07-02 02:17:45 +04:00
|
|
|
ok(true, "The open-failed event should be fired when the source 404s");
|
|
|
|
|
|
|
|
equal($(".openseadragon-message").length, 1, "Open failures should display a message");
|
|
|
|
|
2014-04-15 20:55:32 +04:00
|
|
|
ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
|
2013-07-02 23:12:31 +04:00
|
|
|
"AJAX failures should be logged to the console");
|
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.open('/test/data/not-a-real-file');
|
2013-03-07 23:52:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest('Zoom', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
var viewport = viewer.viewport;
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
|
|
|
|
|
|
|
var zoomHandler = function() {
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.removeHandler('animation-finish', zoomHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
equal(viewport.getZoom(), 2, 'Zoomed correctly');
|
|
|
|
start();
|
|
|
|
};
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.addHandler('animation-finish', zoomHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
viewport.zoomTo(2);
|
|
|
|
});
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-03-07 23:52:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest('Pan', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
var viewport = viewer.viewport,
|
|
|
|
center = viewport.getCenter();
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
|
|
|
|
|
|
|
var panHandler = function() {
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.removeHandler('animation-finish', panHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
center = viewport.getCenter();
|
2014-11-04 04:14:17 +03:00
|
|
|
Util.assessNumericValue(center.x, 0.1, 0.00001, 'panned horizontally');
|
|
|
|
Util.assessNumericValue(center.y, 0.1, 0.00001, 'panned vertically');
|
2013-07-02 02:17:45 +04:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.addHandler('animation-finish', panHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
|
|
|
|
});
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-03-07 23:52:01 +04:00
|
|
|
});
|
|
|
|
|
2013-03-22 00:44:22 +04:00
|
|
|
// ----------
|
|
|
|
asyncTest('Home', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
// Test setup:
|
|
|
|
function opener() {
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
|
|
|
|
viewport.zoomTo(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stage1() {
|
|
|
|
var viewport = viewer.viewport,
|
|
|
|
center = viewport.getCenter();
|
|
|
|
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.removeHandler('animation-finish', stage1);
|
2013-07-02 02:17:45 +04:00
|
|
|
|
|
|
|
ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned');
|
|
|
|
notEqual(viewport.getZoom(), 1, 'We start out zoomed');
|
|
|
|
|
|
|
|
var homeHandler = function() {
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.removeHandler('animation-finish', homeHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
center = viewport.getCenter();
|
|
|
|
ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned');
|
|
|
|
equal(viewport.getZoom(), 1, 'We end up unzoomed');
|
|
|
|
start();
|
|
|
|
};
|
2013-03-22 00:44:22 +04:00
|
|
|
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.addHandler('animation-finish', homeHandler);
|
2014-08-19 03:32:21 +04:00
|
|
|
viewer.viewport.goHome(true);
|
2013-07-02 02:17:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
viewer.addHandler("open", opener);
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.addHandler("animation-finish", stage1);
|
2013-03-22 00:44:22 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-03-22 00:44:22 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
asyncTest('Click', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
var viewport = viewer.viewport,
|
2013-06-27 00:54:37 +04:00
|
|
|
center = viewport.getCenter();
|
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
|
|
|
|
equal(viewport.getZoom(), 1, 'We start out unzoomed');
|
2013-03-22 00:44:22 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
var clickHandler = function() {
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.removeHandler('animation-finish', clickHandler);
|
2013-07-02 02:17:45 +04:00
|
|
|
center = viewport.getCenter();
|
|
|
|
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');
|
|
|
|
start();
|
|
|
|
};
|
2013-03-22 00:44:22 +04:00
|
|
|
|
2013-09-30 21:22:06 +04:00
|
|
|
viewer.addHandler('animation-finish', clickHandler);
|
2013-08-30 00:01:07 +04:00
|
|
|
Util.simulateViewerClickWithDrag( {
|
|
|
|
viewer: viewer,
|
|
|
|
widthFactor: 0.25,
|
|
|
|
heightFactor: 0.25,
|
|
|
|
dragCount: 0,
|
|
|
|
dragDx: 0,
|
|
|
|
dragDy: 0
|
|
|
|
} );
|
|
|
|
} );
|
2013-07-02 02:17:45 +04:00
|
|
|
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-03-22 00:44:22 +04:00
|
|
|
});
|
|
|
|
|
2013-05-14 06:35:27 +04:00
|
|
|
// ----------
|
2013-11-03 05:01:04 +04:00
|
|
|
asyncTest('FullPage', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
ok(!viewer.isFullPage(), 'Started out not fullpage');
|
|
|
|
ok(!$(viewer.element).hasClass('fullpage'),
|
|
|
|
'No fullpage class on div');
|
|
|
|
|
2013-11-02 01:37:19 +04:00
|
|
|
var checkEnteringPreFullPage = function(event) {
|
|
|
|
viewer.removeHandler('pre-full-page', checkEnteringPreFullPage);
|
|
|
|
ok(event.fullPage, 'Switching to fullpage');
|
|
|
|
ok(!viewer.isFullPage(), 'Not yet fullpage');
|
|
|
|
};
|
2013-07-02 02:17:45 +04:00
|
|
|
|
2013-11-02 01:37:19 +04:00
|
|
|
var checkEnteringFullPage = function(event) {
|
|
|
|
viewer.removeHandler('full-page', checkEnteringFullPage);
|
|
|
|
ok(event.fullPage, 'Switched to fullpage');
|
|
|
|
ok(viewer.isFullPage(), 'Enabled fullpage');
|
|
|
|
ok($(viewer.element).hasClass('fullpage'),
|
|
|
|
'Fullpage class added to div');
|
|
|
|
|
|
|
|
var checkExitingPreFullPage = function(event) {
|
|
|
|
viewer.removeHandler('pre-full-page', checkExitingPreFullPage);
|
|
|
|
ok(!event.fullPage, 'Exiting fullpage');
|
|
|
|
ok(viewer.isFullPage(), 'Still fullpage');
|
|
|
|
};
|
|
|
|
|
|
|
|
var checkExitingFullPage = function(event) {
|
|
|
|
viewer.removeHandler('full-page', checkExitingFullPage);
|
|
|
|
ok(!event.fullPage, 'Exiting fullpage');
|
|
|
|
ok(!viewer.isFullPage(), 'Disabled fullpage');
|
|
|
|
ok(!$(viewer.element).hasClass('fullpage'),
|
|
|
|
'Fullpage class removed from div');
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler("pre-full-page", checkExitingPreFullPage);
|
|
|
|
viewer.addHandler("full-page", checkExitingFullPage);
|
|
|
|
viewer.setFullPage(false);
|
|
|
|
};
|
|
|
|
viewer.addHandler("pre-full-page", checkEnteringPreFullPage);
|
|
|
|
viewer.addHandler("full-page", checkEnteringFullPage);
|
|
|
|
viewer.setFullPage(true);
|
2013-07-02 02:17:45 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-05-14 06:35:27 +04:00
|
|
|
});
|
|
|
|
|
2013-11-03 05:01:04 +04:00
|
|
|
asyncTest('FullScreen', function() {
|
|
|
|
|
|
|
|
if (!OpenSeadragon.supportsFullScreen) {
|
|
|
|
expect(0);
|
|
|
|
start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen');
|
|
|
|
|
|
|
|
var checkEnteringPreFullScreen = function(event) {
|
|
|
|
viewer.removeHandler('pre-full-screen', checkEnteringPreFullScreen);
|
|
|
|
ok(event.fullScreen, 'Switching to fullscreen');
|
|
|
|
ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen');
|
|
|
|
};
|
|
|
|
|
|
|
|
// The fullscreen mode is always denied during tests so we are
|
|
|
|
// exiting directly.
|
|
|
|
var checkExitingFullScreen = function(event) {
|
|
|
|
viewer.removeHandler('full-screen', checkExitingFullScreen);
|
|
|
|
ok(!event.fullScreen, 'Exiting fullscreen');
|
|
|
|
ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen');
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler("pre-full-screen", checkEnteringPreFullScreen);
|
|
|
|
viewer.addHandler("full-screen", checkExitingFullScreen);
|
|
|
|
viewer.setFullScreen(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
2013-03-07 23:52:01 +04:00
|
|
|
// ----------
|
|
|
|
asyncTest('Close', function() {
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
var closeHandler = function() {
|
|
|
|
viewer.removeHandler('close', closeHandler);
|
|
|
|
ok(!viewer.source, 'no source');
|
|
|
|
ok(true, 'Close event was sent');
|
|
|
|
setTimeout(function() {
|
2014-11-04 04:14:17 +03:00
|
|
|
ok(!viewer._updateRequestId, 'timer is off');
|
2013-07-02 02:17:45 +04:00
|
|
|
start();
|
|
|
|
}, 100);
|
|
|
|
};
|
2013-03-07 23:52:01 +04:00
|
|
|
|
2013-07-02 02:17:45 +04:00
|
|
|
viewer.addHandler('close', closeHandler);
|
|
|
|
viewer.close();
|
|
|
|
});
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2013-03-07 23:52:01 +04:00
|
|
|
});
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-08-12 10:38:37 +04:00
|
|
|
// ----------
|
|
|
|
asyncTest('Destroy', function() {
|
|
|
|
viewer.addHandler("open", function () {
|
|
|
|
// Check that the DOM has been modified
|
|
|
|
notEqual(0, $('#example').children().length);
|
|
|
|
|
2013-08-13 04:33:12 +04:00
|
|
|
var closeCalled = false;
|
2013-08-12 10:38:37 +04:00
|
|
|
var closeHandler = function() {
|
|
|
|
viewer.removeHandler('close', closeHandler);
|
2013-08-13 04:33:12 +04:00
|
|
|
closeCalled = true;
|
2013-08-12 10:38:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('close', closeHandler);
|
|
|
|
viewer.destroy();
|
|
|
|
|
|
|
|
// Check that the DOM has been cleaned up
|
|
|
|
equal(0, $('#example').children().length);
|
|
|
|
equal(null, viewer.canvas);
|
|
|
|
equal(null, viewer.keyboardCommandArea);
|
|
|
|
equal(null, viewer.container);
|
|
|
|
equal(null, viewer.element);
|
2013-08-13 04:33:12 +04:00
|
|
|
equal(true, closeCalled);
|
2014-06-18 21:35:23 +04:00
|
|
|
viewer = null;
|
2013-08-13 04:33:12 +04:00
|
|
|
start();
|
2013-08-12 10:38:37 +04:00
|
|
|
});
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
2015-02-27 22:07:42 +03:00
|
|
|
|
|
|
|
// The Wikipedia logo has CORS enabled
|
|
|
|
var corsImg = 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png';
|
|
|
|
|
|
|
|
// PhantomJS always taint the canvas, so we only run some tests on browsers
|
|
|
|
// supporting CORS images.
|
|
|
|
function browserSupportsImgCrossOrigin(callback) {
|
|
|
|
var img = new Image();
|
|
|
|
img.crossOrigin = 'anonymous';
|
|
|
|
img.onload = function() {
|
|
|
|
var canvas = document.createElement("canvas");
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(img, 0, 0);
|
2015-11-05 01:49:13 +03:00
|
|
|
callback(!OpenSeadragon.isCanvasTainted(canvas));
|
2015-02-27 22:07:42 +03:00
|
|
|
};
|
|
|
|
img.src = corsImg;
|
|
|
|
}
|
|
|
|
|
2015-02-27 01:57:31 +03:00
|
|
|
asyncTest( 'CrossOriginPolicyMissing', function () {
|
|
|
|
|
|
|
|
viewer.crossOriginPolicy = false;
|
|
|
|
viewer.open( {
|
|
|
|
type: 'legacy-image-pyramid',
|
|
|
|
levels: [ {
|
2015-02-27 22:07:42 +03:00
|
|
|
url: corsImg,
|
2015-02-27 01:57:31 +03:00
|
|
|
width: 135,
|
|
|
|
height: 155
|
|
|
|
} ]
|
|
|
|
} );
|
|
|
|
viewer.addHandler('tile-drawn', function() {
|
2015-11-05 01:49:13 +03:00
|
|
|
ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
|
|
|
"Canvas should be tainted.");
|
2015-02-27 01:57:31 +03:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
asyncTest( 'CrossOriginPolicyAnonymous', function () {
|
|
|
|
|
2015-02-27 22:07:42 +03:00
|
|
|
browserSupportsImgCrossOrigin(function(supported) {
|
|
|
|
if (!supported) {
|
|
|
|
expect(0);
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
viewer.crossOriginPolicy = 'Anonymous';
|
|
|
|
viewer.open( {
|
|
|
|
type: 'legacy-image-pyramid',
|
|
|
|
levels: [ {
|
|
|
|
url: corsImg,
|
|
|
|
width: 135,
|
|
|
|
height: 155
|
|
|
|
} ]
|
|
|
|
} );
|
|
|
|
viewer.addHandler('tile-drawn', function() {
|
2015-11-05 01:49:13 +03:00
|
|
|
ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
|
|
|
"Canvas should not be tainted.");
|
2015-02-27 22:07:42 +03:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
}
|
2015-02-27 01:57:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
2013-02-14 22:21:07 +04:00
|
|
|
})();
|