]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/assertions.js
1 // noVNC specific assertions
2 chai
.use(function (_chai
, utils
) {
3 _chai
.Assertion
.addMethod('displayed', function (target_data
) {
5 const ctx
= obj
._target
.getContext('2d');
6 const 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 const data
= new Uint8Array(data_cl
);
9 const len
= data_cl
.length
;
10 new chai
.Assertion(len
).to
.be
.equal(target_data
.length
, "unexpected display size");
12 for (let i
= 0; i
< len
; i
++) {
13 if (data
[i
] != target_data
[i
]) {
19 // eslint-disable-next-line no-console
20 console
.log("expected data: %o, actual data: %o", target_data
, data
);
23 "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
24 "expected #{this} not to have displayed the image #{act}",
29 _chai
.Assertion
.addMethod('sent', function (target_data
) {
30 const obj
= this._obj
;
32 const res
= { _websocket
: obj
._websocket
, rQi
: obj
._rQi
, _rQ
: new Uint8Array(obj
._rQ
.buffer
, 0, obj
._rQlen
),
33 _sQ
: new Uint8Array(obj
._sQ
.buffer
, 0, obj
._sQlen
) };
37 const data
= obj
._websocket
._get_sent_data();
39 if (data
.length
!= target_data
.length
) {
42 for (let i
= 0; i
< data
.length
; i
++) {
43 if (data
[i
] != target_data
[i
]) {
50 // eslint-disable-next-line no-console
51 console
.log("expected data: %o, actual data: %o", target_data
, data
);
54 "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
55 "expected #{this} not to have sent the data #{act}",
56 Array
.prototype.slice
.call(target_data
),
57 Array
.prototype.slice
.call(data
));
60 _chai
.Assertion
.addProperty('array', function () {
61 utils
.flag(this, 'array', true);
64 _chai
.Assertion
.overwriteMethod('equal', function (_super
) {
65 return function assertArrayEqual(target
) {
66 if (utils
.flag(this, 'array')) {
67 const obj
= this._obj
;
71 if (utils
.flag(this, 'deep')) {
72 for (let i
= 0; i
< obj
.length
; i
++) {
73 if (!utils
.eql(obj
[i
], target
[i
])) {
80 "expected #{this} to have elements deeply equal to #{exp}",
81 "expected #{this} not to have elements deeply equal to #{exp}",
82 Array
.prototype.slice
.call(target
));
84 for (let i
= 0; i
< obj
.length
; i
++) {
85 if (obj
[i
] != target
[i
]) {
92 "expected #{this} to have elements equal to #{exp}",
93 "expected #{this} not to have elements equal to #{exp}",
94 Array
.prototype.slice
.call(target
));
97 _super
.apply(this, arguments
);