// noVNC specific assertions
chai.use(function (_chai, utils) {
- _chai.Assertion.addMethod('displayed', function (targetData) {
+ function _equal(a, b) {
+ return a === b;
+ }
+ _chai.Assertion.addMethod('displayed', function (targetData, cmp=_equal) {
const obj = this._obj;
const ctx = obj._target.getContext('2d');
const dataCl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
new chai.Assertion(len).to.be.equal(targetData.length, "unexpected display size");
let same = true;
for (let i = 0; i < len; i++) {
- if (data[i] != targetData[i]) {
+ if (!cmp(data[i], targetData[i])) {
same = false;
break;
}
testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
- // We got some rounding errors when we compressed things,
- // hence not perfect 0xff/0x00 values
let targetData = new Uint8Array([
- 0xfe, 0x00, 0x00, 255, 0xfe, 0x00, 0x00, 255, 0x00, 0xff, 0x01, 255, 0x00, 0xff, 0x01, 255,
- 0xfe, 0x00, 0x00, 255, 0xfd, 0x00, 0x00, 255, 0x00, 0xff, 0x01, 255, 0x01, 0xff, 0x02, 255,
- 0x00, 0xff, 0x01, 255, 0x00, 0xff, 0x01, 255, 0xfe, 0x00, 0x00, 255, 0xfe, 0x00, 0x00, 255,
- 0x00, 0xff, 0x01, 255, 0x01, 0xff, 0x00, 255, 0xfe, 0x00, 0x00, 255, 0xfd, 0x01, 0x00, 255
+ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
+ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
+ 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255,
+ 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255
]);
+ // Browsers have rounding errors, so we need an approximate
+ // comparing function
+ function almost(a, b) {
+ let diff = Math.abs(a - b);
+ return diff < 5;
+ }
+
display.onflush = () => {
- expect(display).to.have.displayed(targetData);
+ expect(display).to.have.displayed(targetData, almost);
done();
};
display.flush();