mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-29 00:26:10 +03:00
Make timeWatcher args make more sense, add utils tests
This commit is contained in:
parent
73be93b995
commit
b4b1ec8825
@ -87,7 +87,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
timeWatcher: function ( time, assert ) {
|
timeWatcher: function ( assert, time ) {
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
time = time || 2000;
|
time = time || 2000;
|
||||||
var finished = false;
|
var finished = false;
|
||||||
|
@ -1,133 +1,134 @@
|
|||||||
/* global module, asyncTest, $, ok, equal, strictEqual, notEqual, start, test, Util, testLog */
|
/* global QUnit, Util */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
module("utils");
|
QUnit.module("utils");
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
test("addRemoveClass", function() {
|
QUnit.test("addRemoveClass", function(assert) {
|
||||||
var div = OpenSeadragon.makeNeutralElement('div');
|
var div = OpenSeadragon.makeNeutralElement('div');
|
||||||
strictEqual(div.className, '',
|
assert.strictEqual(div.className, '',
|
||||||
"makeNeutralElement set no classes");
|
"makeNeutralElement set no classes");
|
||||||
|
|
||||||
OpenSeadragon.addClass(div, 'foo');
|
OpenSeadragon.addClass(div, 'foo');
|
||||||
strictEqual(div.className, 'foo',
|
assert.strictEqual(div.className, 'foo',
|
||||||
"Added first class");
|
"Added first class");
|
||||||
OpenSeadragon.addClass(div, 'bar');
|
OpenSeadragon.addClass(div, 'bar');
|
||||||
strictEqual(div.className, 'foo bar',
|
assert.strictEqual(div.className, 'foo bar',
|
||||||
"Added second class");
|
"Added second class");
|
||||||
OpenSeadragon.addClass(div, 'baz');
|
OpenSeadragon.addClass(div, 'baz');
|
||||||
strictEqual(div.className, 'foo bar baz',
|
assert.strictEqual(div.className, 'foo bar baz',
|
||||||
"Added third class");
|
"Added third class");
|
||||||
OpenSeadragon.addClass(div, 'plugh');
|
OpenSeadragon.addClass(div, 'plugh');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Added fourth class");
|
"Added fourth class");
|
||||||
|
|
||||||
OpenSeadragon.addClass(div, 'foo');
|
OpenSeadragon.addClass(div, 'foo');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Re-added first class");
|
"Re-added first class");
|
||||||
OpenSeadragon.addClass(div, 'bar');
|
OpenSeadragon.addClass(div, 'bar');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Re-added middle class");
|
"Re-added middle class");
|
||||||
OpenSeadragon.addClass(div, 'plugh');
|
OpenSeadragon.addClass(div, 'plugh');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Re-added last class");
|
"Re-added last class");
|
||||||
|
|
||||||
OpenSeadragon.removeClass(div, 'xyzzy');
|
OpenSeadragon.removeClass(div, 'xyzzy');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Removed nonexistent class");
|
"Removed nonexistent class");
|
||||||
OpenSeadragon.removeClass(div, 'ba');
|
OpenSeadragon.removeClass(div, 'ba');
|
||||||
strictEqual(div.className, 'foo bar baz plugh',
|
assert.strictEqual(div.className, 'foo bar baz plugh',
|
||||||
"Removed nonexistent class with existent substring");
|
"Removed nonexistent class with existent substring");
|
||||||
|
|
||||||
OpenSeadragon.removeClass(div, 'bar');
|
OpenSeadragon.removeClass(div, 'bar');
|
||||||
strictEqual(div.className, 'foo baz plugh',
|
assert.strictEqual(div.className, 'foo baz plugh',
|
||||||
"Removed middle class");
|
"Removed middle class");
|
||||||
OpenSeadragon.removeClass(div, 'plugh');
|
OpenSeadragon.removeClass(div, 'plugh');
|
||||||
strictEqual(div.className, 'foo baz',
|
assert.strictEqual(div.className, 'foo baz',
|
||||||
"Removed last class");
|
"Removed last class");
|
||||||
OpenSeadragon.removeClass(div, 'foo');
|
OpenSeadragon.removeClass(div, 'foo');
|
||||||
strictEqual(div.className, 'baz',
|
assert.strictEqual(div.className, 'baz',
|
||||||
"Removed first class");
|
"Removed first class");
|
||||||
OpenSeadragon.removeClass(div, 'baz');
|
OpenSeadragon.removeClass(div, 'baz');
|
||||||
strictEqual(div.className, '',
|
assert.strictEqual(div.className, '',
|
||||||
"Removed only class");
|
"Removed only class");
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest("makeAjaxRequest", function() {
|
QUnit.test("makeAjaxRequest", function(assert) {
|
||||||
var timeWatcher = Util.timeWatcher();
|
var timeWatcher = Util.timeWatcher(assert);
|
||||||
|
|
||||||
OpenSeadragon.makeAjaxRequest('data/testpattern.dzi',
|
OpenSeadragon.makeAjaxRequest('data/testpattern.dzi',
|
||||||
function(xhr) {
|
function(xhr) {
|
||||||
equal(xhr.status, 200, 'Success callback called for HTTP 200');
|
assert.equal(xhr.status, 200, 'Success callback called for HTTP 200');
|
||||||
ok(/deepzoom/.test(xhr.responseText), 'Success function called');
|
assert.ok(/deepzoom/.test(xhr.responseText), 'Success function called');
|
||||||
timeWatcher.done();
|
timeWatcher.done();
|
||||||
},
|
},
|
||||||
function(xhr) {
|
function(xhr) {
|
||||||
ok(false, 'Error callback should not be called');
|
assert.ok(false, 'Error callback should not be called');
|
||||||
timeWatcher.done();
|
timeWatcher.done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("makeAjaxRequest for invalid file", function() {
|
QUnit.test("makeAjaxRequest for invalid file", function(assert) {
|
||||||
var timeWatcher = Util.timeWatcher();
|
var timeWatcher = Util.timeWatcher(assert);
|
||||||
|
|
||||||
OpenSeadragon.makeAjaxRequest('not-a-real-dzi-file',
|
OpenSeadragon.makeAjaxRequest('not-a-real-dzi-file',
|
||||||
function(xhr) {
|
function(xhr) {
|
||||||
ok(false, 'Success function should not be called for errors');
|
assert.ok(false, 'Success function should not be called for errors');
|
||||||
timeWatcher.done();
|
timeWatcher.done();
|
||||||
},
|
},
|
||||||
function(xhr) {
|
function(xhr) {
|
||||||
equal(xhr.status, 404, 'Error callback called for HTTP 404');
|
assert.equal(xhr.status, 404, 'Error callback called for HTTP 404');
|
||||||
ok(true, 'Error function should be called for errors');
|
assert.ok(true, 'Error function should be called for errors');
|
||||||
timeWatcher.done();
|
timeWatcher.done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getUrlProtocol", function() {
|
QUnit.test("getUrlProtocol", function(assert) {
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol,
|
assert.equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol,
|
||||||
"'test' url protocol should be window.location.protocol");
|
"'test' url protocol should be window.location.protocol");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol,
|
assert.equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol,
|
||||||
"'/test' url protocol should be window.location.protocol");
|
"'/test' url protocol should be window.location.protocol");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol,
|
assert.equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol,
|
||||||
"'//test' url protocol should be window.location.protocol");
|
"'//test' url protocol should be window.location.protocol");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("http://test"), "http:",
|
assert.equal(OpenSeadragon.getUrlProtocol("http://test"), "http:",
|
||||||
"'http://test' url protocol should be http:");
|
"'http://test' url protocol should be http:");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("https://test"), "https:",
|
assert.equal(OpenSeadragon.getUrlProtocol("https://test"), "https:",
|
||||||
"'https://test' url protocol should be https:");
|
"'https://test' url protocol should be https:");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("file://test"), "file:",
|
assert.equal(OpenSeadragon.getUrlProtocol("file://test"), "file:",
|
||||||
"'file://test' url protocol should be file:");
|
"'file://test' url protocol should be file:");
|
||||||
|
|
||||||
equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:",
|
assert.equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:",
|
||||||
"'FTP://test' url protocol should be ftp:");
|
"'FTP://test' url protocol should be ftp:");
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest("requestAnimationFrame", function() {
|
QUnit.test("requestAnimationFrame", function(assert) {
|
||||||
var timeWatcher = Util.timeWatcher();
|
var timeWatcher = Util.timeWatcher(assert);
|
||||||
|
|
||||||
OpenSeadragon.requestAnimationFrame(function() {
|
OpenSeadragon.requestAnimationFrame(function() {
|
||||||
ok(true, 'frame fired');
|
assert.ok(true, 'frame fired');
|
||||||
timeWatcher.done();
|
timeWatcher.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest("cancelAnimationFrame", function() {
|
QUnit.test("cancelAnimationFrame", function(assert) {
|
||||||
|
var done = assert.async();
|
||||||
var frameFired = false;
|
var frameFired = false;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
strictEqual(frameFired, false, 'the frame never fired');
|
assert.strictEqual(frameFired, false, 'the frame never fired');
|
||||||
start();
|
done();
|
||||||
}, 150);
|
}, 150);
|
||||||
|
|
||||||
var frameId = OpenSeadragon.requestAnimationFrame(function() {
|
var frameId = OpenSeadragon.requestAnimationFrame(function() {
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
<script src="/test/modules/basic.js"></script>
|
<script src="/test/modules/basic.js"></script>
|
||||||
<script src="/test/modules/strings.js"></script>
|
<script src="/test/modules/strings.js"></script>
|
||||||
<script src="/test/modules/formats.js"></script>
|
<script src="/test/modules/formats.js"></script>
|
||||||
<!-- <script src="/test/modules/utils.js"></script>
|
<script src="/test/modules/utils.js"></script>
|
||||||
<script src="/test/modules/events.js"></script>
|
<!--<script src="/test/modules/events.js"></script>
|
||||||
<script src="/test/modules/units.js"></script>
|
<script src="/test/modules/units.js"></script>
|
||||||
<script src="/test/modules/multi-image.js"></script>
|
<script src="/test/modules/multi-image.js"></script>
|
||||||
<script src="/test/modules/overlays.js"></script>
|
<script src="/test/modules/overlays.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user