mirror of
https://github.com/fcwu/docker-ubuntu-vnc-desktop
synced 2026-08-05 16:12:41 +02:00
Update noVNC
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
<script src="../include/util.js"></script>
|
||||
<script src="../include/webutil.js"></script>
|
||||
<script src="../include/base64.js"></script>
|
||||
<script src="../include/keysym.js"></script>
|
||||
<script src="../include/keysymdef.js"></script>
|
||||
<script src="../include/keyboard.js"></script>
|
||||
<script src="../include/input.js"></script>
|
||||
|
||||
+129
-21
@@ -28,35 +28,29 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
describe('checking for cursor uri support', function () {
|
||||
beforeEach(function () {
|
||||
this._old_change_cursor = Display.changeCursor;
|
||||
this._old_browser_supports_cursor_uris = Util.browserSupportsCursorURIs;
|
||||
});
|
||||
|
||||
it('should disable cursor URIs if there is no support', function () {
|
||||
Display.changeCursor = function(target) {
|
||||
target.style.cursor = undefined;
|
||||
};
|
||||
Util.browserSupportsCursorURIs = function () { return false; };
|
||||
var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
|
||||
expect(display._cursor_uri).to.be.false;
|
||||
});
|
||||
|
||||
it('should enable cursor URIs if there is support', function () {
|
||||
Display.changeCursor = function(target) {
|
||||
target.style.cursor = 'pointer';
|
||||
};
|
||||
Util.browserSupportsCursorURIs = function () { return true; };
|
||||
var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
|
||||
expect(display._cursor_uri).to.be.true;
|
||||
});
|
||||
|
||||
it('respect the cursor_uri option if there is support', function () {
|
||||
Display.changeCursor = function(target) {
|
||||
target.style.cursor = 'pointer';
|
||||
};
|
||||
Util.browserSupportsCursorURIs = function () { return false; };
|
||||
var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false, cursor_uri: false });
|
||||
expect(display._cursor_uri).to.be.false;
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Display.changeCursor = this._old_change_cursor;
|
||||
Util.browserSupportsCursorURIs = this._old_browser_supports_cursor_uris;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,13 +59,15 @@ describe('Display/Canvas Helper', function () {
|
||||
beforeEach(function () {
|
||||
display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
|
||||
display.resize(5, 5);
|
||||
display.viewportChange(1, 1, 3, 3);
|
||||
display.viewportChangeSize(3, 3);
|
||||
display.viewportChangePos(1, 1);
|
||||
display.getCleanDirtyReset();
|
||||
});
|
||||
|
||||
it('should take viewport location into consideration when drawing images', function () {
|
||||
display.resize(4, 4);
|
||||
display.viewportChange(0, 0, 2, 2);
|
||||
display.set_width(4);
|
||||
display.set_height(4);
|
||||
display.viewportChangeSize(2, 2);
|
||||
display.drawImage(make_image_canvas(basic_data), 1, 1);
|
||||
|
||||
var expected = new Uint8Array(16);
|
||||
@@ -82,7 +78,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should redraw the left side when shifted left', function () {
|
||||
display.viewportChange(-1, 0, 3, 3);
|
||||
display.viewportChangePos(-1, 0);
|
||||
var cdr = display.getCleanDirtyReset();
|
||||
expect(cdr.cleanBox).to.deep.equal({ x: 1, y: 1, w: 2, h: 3 });
|
||||
expect(cdr.dirtyBoxes).to.have.length(1);
|
||||
@@ -90,7 +86,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should redraw the right side when shifted right', function () {
|
||||
display.viewportChange(1, 0, 3, 3);
|
||||
display.viewportChangePos(1, 0);
|
||||
var cdr = display.getCleanDirtyReset();
|
||||
expect(cdr.cleanBox).to.deep.equal({ x: 2, y: 1, w: 2, h: 3 });
|
||||
expect(cdr.dirtyBoxes).to.have.length(1);
|
||||
@@ -98,7 +94,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should redraw the top part when shifted up', function () {
|
||||
display.viewportChange(0, -1, 3, 3);
|
||||
display.viewportChangePos(0, -1);
|
||||
var cdr = display.getCleanDirtyReset();
|
||||
expect(cdr.cleanBox).to.deep.equal({ x: 1, y: 1, w: 3, h: 2 });
|
||||
expect(cdr.dirtyBoxes).to.have.length(1);
|
||||
@@ -106,7 +102,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should redraw the bottom part when shifted down', function () {
|
||||
display.viewportChange(0, 1, 3, 3);
|
||||
display.viewportChangePos(0, 1);
|
||||
var cdr = display.getCleanDirtyReset();
|
||||
expect(cdr.cleanBox).to.deep.equal({ x: 1, y: 2, w: 3, h: 2 });
|
||||
expect(cdr.dirtyBoxes).to.have.length(1);
|
||||
@@ -114,7 +110,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should reset the entire viewport to being clean after calculating the clean/dirty boxes', function () {
|
||||
display.viewportChange(0, 1, 3, 3);
|
||||
display.viewportChangePos(0, 1);
|
||||
var cdr1 = display.getCleanDirtyReset();
|
||||
var cdr2 = display.getCleanDirtyReset();
|
||||
expect(cdr1).to.not.deep.equal(cdr2);
|
||||
@@ -132,6 +128,40 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('clipping', function () {
|
||||
var display;
|
||||
beforeEach(function () {
|
||||
display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
|
||||
display.resize(4, 3);
|
||||
});
|
||||
|
||||
it('should report true when no max-size and framebuffer > viewport', function () {
|
||||
display.viewportChangeSize(2,2);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
|
||||
it('should report false when no max-size and framebuffer = viewport', function () {
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.false;
|
||||
});
|
||||
|
||||
it('should report true when viewport > max-size and framebuffer > viewport', function () {
|
||||
display.viewportChangeSize(2,2);
|
||||
display.set_maxWidth(1);
|
||||
display.set_maxHeight(2);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
|
||||
it('should report true when viewport > max-size and framebuffer = viewport', function () {
|
||||
display.set_maxWidth(1);
|
||||
display.set_maxHeight(2);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('resizing', function () {
|
||||
var display;
|
||||
beforeEach(function () {
|
||||
@@ -146,9 +176,87 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should update the viewport dimensions', function () {
|
||||
sinon.spy(display, 'viewportChange');
|
||||
sinon.spy(display, 'viewportChangeSize');
|
||||
display.resize(2, 2);
|
||||
expect(display.viewportChange).to.have.been.calledOnce;
|
||||
expect(display.viewportChangeSize).to.have.been.calledOnce;
|
||||
});
|
||||
});
|
||||
|
||||
describe('rescaling', function () {
|
||||
var display;
|
||||
var canvas;
|
||||
|
||||
beforeEach(function () {
|
||||
display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
|
||||
display.resize(4, 3);
|
||||
canvas = display.get_target();
|
||||
document.body.appendChild(canvas);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
document.body.removeChild(canvas);
|
||||
});
|
||||
|
||||
it('should not change the bitmap size of the canvas', function () {
|
||||
display.set_scale(0.5);
|
||||
expect(canvas.width).to.equal(4);
|
||||
expect(canvas.height).to.equal(3);
|
||||
});
|
||||
|
||||
it('should change the effective rendered size of the canvas', function () {
|
||||
display.set_scale(0.5);
|
||||
expect(canvas.clientWidth).to.equal(2);
|
||||
expect(canvas.clientHeight).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('autoscaling', function () {
|
||||
var display;
|
||||
var canvas;
|
||||
|
||||
beforeEach(function () {
|
||||
display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
|
||||
display.resize(4, 3);
|
||||
canvas = display.get_target();
|
||||
document.body.appendChild(canvas);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
document.body.removeChild(canvas);
|
||||
});
|
||||
|
||||
it('should preserve aspect ratio while autoscaling', function () {
|
||||
display.autoscale(16, 9);
|
||||
expect(canvas.clientWidth / canvas.clientHeight).to.equal(4 / 3);
|
||||
});
|
||||
|
||||
it('should use width to determine scale when the current aspect ratio is wider than the target', function () {
|
||||
expect(display.autoscale(9, 16)).to.equal(9 / 4);
|
||||
expect(canvas.clientWidth).to.equal(9);
|
||||
expect(canvas.clientHeight).to.equal(7); // round 9 / (4 / 3)
|
||||
});
|
||||
|
||||
it('should use height to determine scale when the current aspect ratio is taller than the target', function () {
|
||||
expect(display.autoscale(16, 9)).to.equal(3); // 9 / 3
|
||||
expect(canvas.clientWidth).to.equal(12); // 16 * (4 / 3)
|
||||
expect(canvas.clientHeight).to.equal(9);
|
||||
|
||||
});
|
||||
|
||||
it('should not change the bitmap size of the canvas', function () {
|
||||
display.autoscale(16, 9);
|
||||
expect(canvas.width).to.equal(4);
|
||||
expect(canvas.height).to.equal(3);
|
||||
});
|
||||
|
||||
it('should not upscale when downscaleOnly is true', function () {
|
||||
expect(display.autoscale(2, 2, true)).to.equal(0.5);
|
||||
expect(canvas.clientWidth).to.equal(2);
|
||||
expect(canvas.clientHeight).to.equal(2);
|
||||
|
||||
expect(display.autoscale(16, 9, true)).to.equal(1.0);
|
||||
expect(canvas.clientWidth).to.equal(4);
|
||||
expect(canvas.clientHeight).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+188
-4
@@ -62,6 +62,24 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._updateState).to.have.been.calledOnce;
|
||||
expect(client._updateState).to.have.been.calledWith('disconnect');
|
||||
});
|
||||
|
||||
it('should unregister error event handler', function () {
|
||||
sinon.spy(client._sock, 'off');
|
||||
client.disconnect();
|
||||
expect(client._sock.off).to.have.been.calledWith('error');
|
||||
});
|
||||
|
||||
it('should unregister message event handler', function () {
|
||||
sinon.spy(client._sock, 'off');
|
||||
client.disconnect();
|
||||
expect(client._sock.off).to.have.been.calledWith('message');
|
||||
});
|
||||
|
||||
it('should unregister open event handler', function () {
|
||||
sinon.spy(client._sock, 'off');
|
||||
client.disconnect();
|
||||
expect(client._sock.off).to.have.been.calledWith('open');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sendPassword', function () {
|
||||
@@ -177,6 +195,48 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setDesktopSize", function () {
|
||||
beforeEach(function() {
|
||||
client._sock = new Websock();
|
||||
client._sock.open('ws://', 'binary');
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'send');
|
||||
client._rfb_state = "normal";
|
||||
client._view_only = false;
|
||||
client._supportsSetDesktopSize = true;
|
||||
});
|
||||
|
||||
it('should send the request with the given width and height', function () {
|
||||
var expected = [251];
|
||||
expected.push8(0); // padding
|
||||
expected.push16(1); // width
|
||||
expected.push16(2); // height
|
||||
expected.push8(1); // number-of-screens
|
||||
expected.push8(0); // padding before screen array
|
||||
expected.push32(0); // id
|
||||
expected.push16(0); // x-position
|
||||
expected.push16(0); // y-position
|
||||
expected.push16(1); // width
|
||||
expected.push16(2); // height
|
||||
expected.push32(0); // flags
|
||||
|
||||
client.setDesktopSize(1, 2);
|
||||
expect(client._sock).to.have.sent(expected);
|
||||
});
|
||||
|
||||
it('should not send the request if the client has not recieved a ExtendedDesktopSize rectangle', function () {
|
||||
client._supportsSetDesktopSize = false;
|
||||
client.setDesktopSize(1,2);
|
||||
expect(client._sock.send).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should not send the request if we are not in a normal state', function () {
|
||||
client._rfb_state = "broken";
|
||||
client.setDesktopSize(1,2);
|
||||
expect(client._sock.send).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe("XVP operations", function () {
|
||||
beforeEach(function () {
|
||||
client._sock = new Websock();
|
||||
@@ -1425,6 +1485,122 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._display.resize).to.have.been.calledWith(20, 50);
|
||||
});
|
||||
|
||||
describe('the ExtendedDesktopSize pseudo-encoding handler', function () {
|
||||
var client;
|
||||
|
||||
beforeEach(function () {
|
||||
client = make_rfb();
|
||||
client.connect('host', 8675);
|
||||
client._sock._websocket._open();
|
||||
client._rfb_state = 'normal';
|
||||
client._fb_name = 'some device';
|
||||
client._supportsSetDesktopSize = false;
|
||||
// a really small frame
|
||||
client._fb_width = 4;
|
||||
client._fb_height = 4;
|
||||
client._display._fb_width = 4;
|
||||
client._display._fb_height = 4;
|
||||
client._display._viewportLoc.w = 4;
|
||||
client._display._viewportLoc.h = 4;
|
||||
client._fb_Bpp = 4;
|
||||
sinon.spy(client._display, 'resize');
|
||||
client.set_onFBResize(sinon.spy());
|
||||
});
|
||||
|
||||
function make_screen_data (nr_of_screens) {
|
||||
var data = [];
|
||||
data.push8(nr_of_screens); // number-of-screens
|
||||
data.push8(0); // padding
|
||||
data.push16(0); // padding
|
||||
for (var i=0; i<nr_of_screens; i += 1) {
|
||||
data.push32(0); // id
|
||||
data.push16(0); // x-position
|
||||
data.push16(0); // y-position
|
||||
data.push16(20); // width
|
||||
data.push16(50); // height
|
||||
data.push32(0); // flags
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
it('should handle a resize requested by this client', function () {
|
||||
var reason_for_change = 1; // requested by this client
|
||||
var status_code = 0; // No error
|
||||
|
||||
send_fbu_msg([{ x: reason_for_change, y: status_code,
|
||||
width: 20, height: 50, encoding: -308 }],
|
||||
make_screen_data(1), client);
|
||||
|
||||
expect(client._supportsSetDesktopSize).to.be.true;
|
||||
expect(client._fb_width).to.equal(20);
|
||||
expect(client._fb_height).to.equal(50);
|
||||
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(20, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 20, 50);
|
||||
});
|
||||
|
||||
it('should handle a resize requested by another client', function () {
|
||||
var reason_for_change = 2; // requested by another client
|
||||
var status_code = 0; // No error
|
||||
|
||||
send_fbu_msg([{ x: reason_for_change, y: status_code,
|
||||
width: 20, height: 50, encoding: -308 }],
|
||||
make_screen_data(1), client);
|
||||
|
||||
expect(client._supportsSetDesktopSize).to.be.true;
|
||||
expect(client._fb_width).to.equal(20);
|
||||
expect(client._fb_height).to.equal(50);
|
||||
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(20, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 20, 50);
|
||||
});
|
||||
|
||||
it('should be able to recieve requests which contain data for multiple screens', function () {
|
||||
var reason_for_change = 2; // requested by another client
|
||||
var status_code = 0; // No error
|
||||
|
||||
send_fbu_msg([{ x: reason_for_change, y: status_code,
|
||||
width: 60, height: 50, encoding: -308 }],
|
||||
make_screen_data(3), client);
|
||||
|
||||
expect(client._supportsSetDesktopSize).to.be.true;
|
||||
expect(client._fb_width).to.equal(60);
|
||||
expect(client._fb_height).to.equal(50);
|
||||
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(60, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 60, 50);
|
||||
});
|
||||
|
||||
it('should not handle a failed request', function () {
|
||||
var reason_for_change = 1; // requested by this client
|
||||
var status_code = 1; // Resize is administratively prohibited
|
||||
|
||||
send_fbu_msg([{ x: reason_for_change, y: status_code,
|
||||
width: 20, height: 50, encoding: -308 }],
|
||||
make_screen_data(1), client);
|
||||
|
||||
expect(client._fb_width).to.equal(4);
|
||||
expect(client._fb_height).to.equal(4);
|
||||
|
||||
expect(client._display.resize).to.not.have.been.called;
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should handle the Cursor pseudo-encoding', function () {
|
||||
// TODO(directxman12): test
|
||||
});
|
||||
@@ -1575,7 +1751,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should not send movement messages when viewport dragging', function () {
|
||||
client._viewportDragging = true;
|
||||
client._display.viewportChange = sinon.spy();
|
||||
client._display.viewportChangePos = sinon.spy();
|
||||
client._mouse._onMouseMove(13, 9);
|
||||
expect(client._sock.send).to.not.have.been.called;
|
||||
});
|
||||
@@ -1604,14 +1780,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._viewportDrag = true;
|
||||
client._viewportDragging = true;
|
||||
client._viewportDragPos = { x: 13, y: 9 };
|
||||
client._display.viewportChange = sinon.spy();
|
||||
client._display.viewportChangePos = sinon.spy();
|
||||
|
||||
client._mouse._onMouseMove(10, 4);
|
||||
|
||||
expect(client._viewportDragging).to.be.true;
|
||||
expect(client._viewportDragPos).to.deep.equal({ x: 10, y: 4 });
|
||||
expect(client._display.viewportChange).to.have.been.calledOnce;
|
||||
expect(client._display.viewportChange).to.have.been.calledWith(3, 5);
|
||||
expect(client._display.viewportChangePos).to.have.been.calledOnce;
|
||||
expect(client._display.viewportChangePos).to.have.been.calledWith(3, 5);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1710,6 +1886,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._rfb_state).to.equal('failed');
|
||||
});
|
||||
|
||||
it('should unregister close event handler', function () {
|
||||
sinon.spy(client._sock, 'off');
|
||||
client.connect('host', 8675);
|
||||
client._rfb_state = 'disconnect';
|
||||
client._sock._websocket.close();
|
||||
expect(client._sock.off).to.have.been.calledWith('close');
|
||||
});
|
||||
|
||||
// error events do nothing
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
deltaY = lastPos.y - y; // drag frame buffer
|
||||
lastPos = {'x': x, 'y': y};
|
||||
|
||||
display.viewportChange(deltaX, deltaY);
|
||||
display.viewportChangePos(deltaX, deltaY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,14 +166,13 @@
|
||||
var p = $D('canvas').parentNode;
|
||||
message("doResize1: [" + (p.offsetWidth - padW) +
|
||||
"," + (p.offsetHeight - padH) + "]");
|
||||
display.viewportChange(0, 0,
|
||||
p.offsetWidth - padW, p.offsetHeight - padH);
|
||||
display.viewportChangeSize(p.offsetWidth - padW, p.offsetHeight - padH);
|
||||
/*
|
||||
var pos, new_w, new_h;pos
|
||||
pos = Util.getPosition($D('canvas').parentNode);
|
||||
new_w = window.innerWidth - pos.x;
|
||||
new_h = window.innerHeight - pos.y;
|
||||
display.viewportChange(0, 0, new_w, new_h);
|
||||
display.viewportChangeSize(new_w, new_h);
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -194,7 +193,7 @@
|
||||
Util.addEvent(window, 'resize', doResize);
|
||||
// Shrink viewport for first resize call so that the
|
||||
// scrollbars are disabled
|
||||
display.viewportChange(0, 0, 10, 10);
|
||||
display.viewportChangeSize(10, 10);
|
||||
setTimeout(doResize, 1);
|
||||
setInterval(dirtyRedraw, 50);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user