]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.copyrect.js
1 const expect
= chai
.expect
;
3 import Websock
from '../core/websock.js';
4 import Display
from '../core/display.js';
6 import CopyRectDecoder
from '../core/decoders/copyrect.js';
8 import FakeWebSocket
from './fake.websocket.js';
10 function testDecodeRect(decoder
, x
, y
, width
, height
, data
, display
, depth
) {
14 sock
.open("ws://example.com");
16 sock
.on('message', () => {
17 decoder
.decodeRect(x
, y
, width
, height
, sock
, display
, depth
);
20 sock
._websocket
._receiveData(new Uint8Array(data
));
25 describe('CopyRect Decoder', function () {
29 before(FakeWebSocket
.replace
);
30 after(FakeWebSocket
.restore
);
32 beforeEach(function () {
33 decoder
= new CopyRectDecoder();
34 display
= new Display(document
.createElement('canvas'));
38 it('should handle the CopyRect encoding', function () {
39 // seed some initial data to copy
40 display
.fillRect(0, 0, 4, 4, [ 0x11, 0x22, 0x33 ]);
41 display
.fillRect(0, 0, 2, 2, [ 0x00, 0x00, 0xff ]);
42 display
.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
44 testDecodeRect(decoder
, 0, 2, 2, 2,
45 [0x00, 0x02, 0x00, 0x00],
47 testDecodeRect(decoder
, 2, 2, 2, 2,
48 [0x00, 0x00, 0x00, 0x00],
51 let targetData
= new Uint8Array([
52 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
53 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
54 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
55 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
58 expect(display
).to
.have
.displayed(targetData
);