forked from jaysalvat/jquery.facedetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
67 lines (54 loc) · 1.89 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
FaceDetection jQuery Plugin
Copyright (c) 2014 Jay Salvat
*/
/* global jQuery:true, QUnit:true */
(function ($) {
"use strict";
QUnit.test('Plugin', function (assert) {
assert.ok($("#img").faceDetection().addClass("testing"), "can be chained");
});
QUnit.test('Detection in image', function (assert) {
$("#img").faceDetection(function (faces) {
assert.equal(faces.length, 2, "2 faces found (callback)");
});
$("#img").faceDetection({
complete: function (faces) {
assert.equal(faces.length, 2, "2 faces found (options)");
}
});
});
QUnit.test('Detection in canvas', function (assert) {
var img = document.getElementById('img'),
canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
canvas.setAttribute('width', img.width);
canvas.setAttribute('height',img.height);
ctx.drawImage(img, 0, 0);
// TODO Async test on image load
$("#canvas").faceDetection(function (faces) {
assert.equal(faces.length, 2, "2 faces found");
});
});
QUnit.test('Errors', function (assert) {
$("#div").faceDetection({
complete: function (faces) {
assert.equal(faces.length, 0, "no faces found");
},
error: function (code, message) {
assert.equal(code, 1, "returns error code 1");
assert.ok(/images, videos and canvas only/.test(message), "contains message");
}
});
});
QUnit.asyncTest('Async Mode', function (assert) {
assert.expect(1);
$("#img").faceDetection({
worker: true,
complete: function(faces) {
assert.equal(faces.length, 2, "2 faces found");
QUnit.start();
}
});
});
})(jQuery);