]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/assertions.js
1 // some useful assertions for noVNC
2 chai
.use(function (_chai
, utils
) {
3 _chai
.Assertion
.addMethod('displayed', function (target_data
) {
5 var ctx
= obj
._target
.getContext('2d');
6 var data_cl
= ctx
.getImageData(0, 0, obj
._target
.width
, obj
._target
.height
).data
;
7 // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
8 var data
= new Uint8Array(data_cl
);
10 var len
= data_cl
.length
;
11 if (len
!= target_data
.length
) {
14 for (var i
= 0; i
< len
; i
++) {
15 if (data
[i
] != target_data
[i
]) {
22 console
.log("expected data: %o, actual data: %o", target_data
, data
);
25 "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
26 "expected #{this} not to have displayed the image #{act}",
31 _chai
.Assertion
.addMethod('sent', function (target_data
) {
33 obj
.inspect = function () {
34 var res
= { _websocket
: obj
._websocket
, rQi
: obj
._rQi
, _rQ
: new Uint8Array(obj
._rQ
.buffer
, 0, obj
._rQlen
),
35 _sQ
: new Uint8Array(obj
._sQ
.buffer
, 0, obj
._sQlen
) };
39 var data
= obj
._websocket
._get_sent_data();
41 if (data
.length
!= target_data
.length
) {
44 for (var i
= 0; i
< data
.length
; i
++) {
45 if (data
[i
] != target_data
[i
]) {
52 console
.log("expected data: %o, actual data: %o", target_data
, data
);
55 "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
56 "expected #{this} not to have sent the data #{act}",
57 Array
.prototype.slice
.call(target_data
),
58 Array
.prototype.slice
.call(data
));
61 _chai
.Assertion
.addProperty('array', function () {
62 utils
.flag(this, 'array', true);
65 _chai
.Assertion
.overwriteMethod('equal', function (_super
) {
66 return function assertArrayEqual(target
) {
67 if (utils
.flag(this, 'array')) {
73 if (utils
.flag(this, 'deep')) {
74 for (i
= 0; i
< obj
.length
; i
++) {
75 if (!utils
.eql(obj
[i
], target
[i
])) {
82 "expected #{this} to have elements deeply equal to #{exp}",
83 "expected #{this} not to have elements deeply equal to #{exp}",
84 Array
.prototype.slice
.call(target
));
86 for (i
= 0; i
< obj
.length
; i
++) {
87 if (obj
[i
] != target
[i
]) {
94 "expected #{this} to have elements equal to #{exp}",
95 "expected #{this} not to have elements equal to #{exp}",
96 Array
.prototype.slice
.call(target
));
99 _super
.apply(this, arguments
);