2017-12-05 03:51:16 +03:00
|
|
|
/* global QUnit, Util */
|
2013-07-03 00:28:59 +04:00
|
|
|
|
2013-05-14 06:24:04 +04:00
|
|
|
(function() {
|
2013-05-21 21:39:23 +04:00
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.module("utils");
|
2013-05-14 06:24:04 +04:00
|
|
|
|
2013-05-21 21:39:23 +04:00
|
|
|
// ----------
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("addRemoveClass", function(assert) {
|
2013-05-14 06:24:04 +04:00
|
|
|
var div = OpenSeadragon.makeNeutralElement('div');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, '',
|
2013-05-14 06:24:04 +04:00
|
|
|
"makeNeutralElement set no classes");
|
|
|
|
|
|
|
|
OpenSeadragon.addClass(div, 'foo');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Added first class");
|
|
|
|
OpenSeadragon.addClass(div, 'bar');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Added second class");
|
|
|
|
OpenSeadragon.addClass(div, 'baz');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Added third class");
|
|
|
|
OpenSeadragon.addClass(div, 'plugh');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Added fourth class");
|
|
|
|
|
|
|
|
OpenSeadragon.addClass(div, 'foo');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Re-added first class");
|
|
|
|
OpenSeadragon.addClass(div, 'bar');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Re-added middle class");
|
|
|
|
OpenSeadragon.addClass(div, 'plugh');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Re-added last class");
|
|
|
|
|
|
|
|
OpenSeadragon.removeClass(div, 'xyzzy');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed nonexistent class");
|
|
|
|
OpenSeadragon.removeClass(div, 'ba');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed nonexistent class with existent substring");
|
|
|
|
|
|
|
|
OpenSeadragon.removeClass(div, 'bar');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo baz plugh',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed middle class");
|
|
|
|
OpenSeadragon.removeClass(div, 'plugh');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'foo baz',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed last class");
|
|
|
|
OpenSeadragon.removeClass(div, 'foo');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, 'baz',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed first class");
|
|
|
|
OpenSeadragon.removeClass(div, 'baz');
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(div.className, '',
|
2013-05-14 06:24:04 +04:00
|
|
|
"Removed only class");
|
|
|
|
});
|
2013-05-21 21:39:23 +04:00
|
|
|
|
|
|
|
// ----------
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("makeAjaxRequest", function(assert) {
|
|
|
|
var timeWatcher = Util.timeWatcher(assert);
|
2013-05-21 21:39:23 +04:00
|
|
|
|
2013-07-03 00:28:59 +04:00
|
|
|
OpenSeadragon.makeAjaxRequest('data/testpattern.dzi',
|
|
|
|
function(xhr) {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(xhr.status, 200, 'Success callback called for HTTP 200');
|
|
|
|
assert.ok(/deepzoom/.test(xhr.responseText), 'Success function called');
|
2013-07-03 00:28:59 +04:00
|
|
|
timeWatcher.done();
|
|
|
|
},
|
|
|
|
function(xhr) {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.ok(false, 'Error callback should not be called');
|
2013-07-03 00:28:59 +04:00
|
|
|
timeWatcher.done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("makeAjaxRequest for invalid file", function(assert) {
|
|
|
|
var timeWatcher = Util.timeWatcher(assert);
|
2013-07-03 00:28:59 +04:00
|
|
|
|
|
|
|
OpenSeadragon.makeAjaxRequest('not-a-real-dzi-file',
|
|
|
|
function(xhr) {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.ok(false, 'Success function should not be called for errors');
|
2013-07-03 00:28:59 +04:00
|
|
|
timeWatcher.done();
|
|
|
|
},
|
|
|
|
function(xhr) {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(xhr.status, 404, 'Error callback called for HTTP 404');
|
|
|
|
assert.ok(true, 'Error function should be called for errors');
|
2013-07-03 00:28:59 +04:00
|
|
|
timeWatcher.done();
|
|
|
|
}
|
|
|
|
);
|
2013-05-21 21:39:23 +04:00
|
|
|
});
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("getUrlProtocol", function(assert) {
|
2014-04-15 20:55:32 +04:00
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol,
|
2014-04-15 20:55:32 +04:00
|
|
|
"'test' url protocol should be window.location.protocol");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol,
|
2014-04-15 20:55:32 +04:00
|
|
|
"'/test' url protocol should be window.location.protocol");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol,
|
2014-04-15 20:55:32 +04:00
|
|
|
"'//test' url protocol should be window.location.protocol");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("http://test"), "http:",
|
2014-04-15 20:55:32 +04:00
|
|
|
"'http://test' url protocol should be http:");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("https://test"), "https:",
|
2014-04-15 20:55:32 +04:00
|
|
|
"'https://test' url protocol should be https:");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("file://test"), "file:",
|
2014-04-15 20:55:32 +04:00
|
|
|
"'file://test' url protocol should be file:");
|
|
|
|
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:",
|
2014-04-15 20:55:32 +04:00
|
|
|
"'FTP://test' url protocol should be ftp:");
|
|
|
|
});
|
|
|
|
|
2013-05-23 20:48:53 +04:00
|
|
|
// ----------
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("requestAnimationFrame", function(assert) {
|
|
|
|
var timeWatcher = Util.timeWatcher(assert);
|
2013-05-23 20:48:53 +04:00
|
|
|
|
|
|
|
OpenSeadragon.requestAnimationFrame(function() {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.ok(true, 'frame fired');
|
2013-05-23 20:48:53 +04:00
|
|
|
timeWatcher.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 03:51:16 +03:00
|
|
|
QUnit.test("cancelAnimationFrame", function(assert) {
|
|
|
|
var done = assert.async();
|
2013-05-23 20:48:53 +04:00
|
|
|
var frameFired = false;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2017-12-05 03:51:16 +03:00
|
|
|
assert.strictEqual(frameFired, false, 'the frame never fired');
|
|
|
|
done();
|
2013-05-23 20:48:53 +04:00
|
|
|
}, 150);
|
|
|
|
|
|
|
|
var frameId = OpenSeadragon.requestAnimationFrame(function() {
|
|
|
|
frameFired = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
OpenSeadragon.cancelAnimationFrame(frameId);
|
|
|
|
});
|
|
|
|
|
2013-05-14 06:24:04 +04:00
|
|
|
})();
|