]> git.proxmox.com Git - mirror_novnc.git/blob - tests/test.copyrect.js
Switch to RGBx pixel format
[mirror_novnc.git] / tests / test.copyrect.js
1 const expect = chai.expect;
2
3 import Websock from '../core/websock.js';
4 import Display from '../core/display.js';
5
6 import CopyRectDecoder from '../core/decoders/copyrect.js';
7
8 import FakeWebSocket from './fake.websocket.js';
9
10 function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
11 let sock;
12
13 sock = new Websock;
14 sock.open("ws://example.com");
15
16 sock.on('message', () => {
17 decoder.decodeRect(x, y, width, height, sock, display, depth);
18 });
19
20 sock._websocket._receiveData(new Uint8Array(data));
21
22 display.flip();
23 }
24
25 describe('CopyRect Decoder', function () {
26 let decoder;
27 let display;
28
29 before(FakeWebSocket.replace);
30 after(FakeWebSocket.restore);
31
32 beforeEach(function () {
33 decoder = new CopyRectDecoder();
34 display = new Display(document.createElement('canvas'));
35 display.resize(4, 4);
36 });
37
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 ]);
43
44 testDecodeRect(decoder, 0, 2, 2, 2,
45 [0x00, 0x02, 0x00, 0x00],
46 display, 24);
47 testDecodeRect(decoder, 2, 2, 2, 2,
48 [0x00, 0x00, 0x00, 0x00],
49 display, 24);
50
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
56 ]);
57
58 expect(display).to.have.displayed(targetData);
59 });
60 });