Merge pull request #1289 from CendioNiko/master

Desktop name improvements
This commit is contained in:
Samuel Mannehed
2019-09-25 14:43:55 +02:00
committed by GitHub
4 changed files with 68 additions and 13 deletions
+30 -7
View File
@@ -41,6 +41,13 @@ function push32(arr, num) {
num & 0xFF);
}
function pushString(arr, string) {
let utf8 = unescape(encodeURIComponent(string));
for (let i = 0; i < utf8.length; i++) {
arr.push(utf8.charCodeAt(i));
}
}
describe('Remote Frame Buffer Protocol Client', function () {
let clock;
let raf;
@@ -1446,10 +1453,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._sock._websocket._receive_data(new Uint8Array(data));
const name_data = [];
push32(name_data, full_opts.name.length);
for (let i = 0; i < full_opts.name.length; i++) {
name_data.push(full_opts.name.charCodeAt(i));
}
let name_len = [];
pushString(name_data, full_opts.name);
push32(name_len, name_data.length);
client._sock._websocket._receive_data(new Uint8Array(name_len));
client._sock._websocket._receive_data(new Uint8Array(name_data));
}
@@ -1464,11 +1472,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should set the framebuffer name and call the callback', function () {
const spy = sinon.spy();
client.addEventListener("desktopname", spy);
send_server_init({ name: 'some name' }, client);
send_server_init({ name: 'som nam' }, client);
expect(client._fb_name).to.equal('some name');
expect(client._fb_name).to.equal('som nam');
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.name).to.equal('some name');
expect(spy.args[0][0].detail.name).to.equal('som nam');
});
it('should handle the extended init message of the tight encoding', function () {
@@ -2128,6 +2136,21 @@ describe('Remote Frame Buffer Protocol Client', function () {
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -224}], [[]], client, 100);
expect(client._FBU.rects).to.equal(0);
});
it('should handle the DesktopName pseudo-encoding', function () {
let data = [];
push32(data, 13);
pushString(data, "som€ nam€");
const spy = sinon.spy();
client.addEventListener("desktopname", spy);
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -307 }], [data], client);
expect(client._fb_name).to.equal('som€ nam€');
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.name).to.equal('som€ nam€');
});
});
});