Files
noVNC/tests/test.rre.js
T

114 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-06-06 14:24:44 +02:00
import Websock from '../core/websock.js';
import Display from '../core/display.js';
import RREDecoder from '../core/decoders/rre.js';
import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock;
2023-06-03 15:36:29 +02:00
let done = false;
2020-06-06 14:24:44 +02:00
sock = new Websock;
sock.open("ws://example.com");
sock.on('message', () => {
2023-06-03 15:36:29 +02:00
done = decoder.decodeRect(x, y, width, height, sock, display, depth);
2020-06-06 14:24:44 +02:00
});
2020-09-07 12:58:52 +02:00
// Empty messages are filtered at multiple layers, so we need to
// do a direct call
if (data.length === 0) {
2023-06-03 15:36:29 +02:00
done = decoder.decodeRect(x, y, width, height, sock, display, depth);
2020-09-07 12:58:52 +02:00
} else {
sock._websocket._receiveData(new Uint8Array(data));
}
2020-06-06 14:24:44 +02:00
display.flip();
2023-06-03 15:36:29 +02:00
return done;
2020-06-06 14:24:44 +02:00
}
function push16(arr, num) {
arr.push((num >> 8) & 0xFF,
num & 0xFF);
}
function push32(arr, num) {
arr.push((num >> 24) & 0xFF,
(num >> 16) & 0xFF,
(num >> 8) & 0xFF,
num & 0xFF);
}
2024-11-27 13:58:26 +01:00
describe('RRE decoder', function () {
2020-06-06 14:24:44 +02:00
let decoder;
let display;
before(FakeWebSocket.replace);
after(FakeWebSocket.restore);
beforeEach(function () {
decoder = new RREDecoder();
display = new Display(document.createElement('canvas'));
display.resize(4, 4);
});
// TODO(directxman12): test rre_chunk_sz?
it('should handle the RRE encoding', function () {
let data = [];
push32(data, 2); // 2 subrects
2020-06-08 07:40:56 +02:00
push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
2020-06-07 14:22:07 +02:00
data.push(0x00); // becomes 0000ff00 --> #0000FF fg color
2020-06-06 14:24:44 +02:00
data.push(0x00);
2020-06-07 14:22:07 +02:00
data.push(0xff);
2020-06-06 14:24:44 +02:00
data.push(0x00);
push16(data, 0); // x: 0
push16(data, 0); // y: 0
push16(data, 2); // width: 2
push16(data, 2); // height: 2
2020-06-07 14:22:07 +02:00
data.push(0x00); // becomes 0000ff00 --> #0000FF fg color
2020-06-06 14:24:44 +02:00
data.push(0x00);
2020-06-07 14:22:07 +02:00
data.push(0xff);
2020-06-06 14:24:44 +02:00
data.push(0x00);
push16(data, 2); // x: 2
push16(data, 2); // y: 2
push16(data, 2); // width: 2
push16(data, 2); // height: 2
2023-06-03 15:36:29 +02:00
let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
2020-06-06 14:24:44 +02:00
let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]);
2023-06-03 15:36:29 +02:00
expect(done).to.be.true;
2020-06-06 14:24:44 +02:00
expect(display).to.have.displayed(targetData);
});
2020-09-04 16:16:44 +02:00
it('should handle empty rects', function () {
display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
2023-06-03 15:36:29 +02:00
let done = testDecodeRect(decoder, 1, 2, 0, 0,
[ 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff ],
display, 24);
2020-09-04 16:16:44 +02:00
let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]);
2023-06-03 15:36:29 +02:00
expect(done).to.be.true;
2020-09-04 16:16:44 +02:00
expect(display).to.have.displayed(targetData);
});
2020-06-06 14:24:44 +02:00
});