mirror of
https://github.com/novnc/noVNC.git
synced 2026-06-08 21:34:38 +00:00
Prefer const/let over var
This commit is contained in:
@@ -5,15 +5,15 @@ chai.use(sinonChai);
|
||||
// noVNC specific assertions
|
||||
chai.use(function (_chai, utils) {
|
||||
_chai.Assertion.addMethod('displayed', function (target_data) {
|
||||
var obj = this._obj;
|
||||
var ctx = obj._target.getContext('2d');
|
||||
var data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
|
||||
const obj = this._obj;
|
||||
const ctx = obj._target.getContext('2d');
|
||||
const data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
|
||||
// NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
|
||||
var data = new Uint8Array(data_cl);
|
||||
var len = data_cl.length;
|
||||
const data = new Uint8Array(data_cl);
|
||||
const len = data_cl.length;
|
||||
new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size");
|
||||
var same = true;
|
||||
for (var i = 0; i < len; i++) {
|
||||
let same = true;
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (data[i] != target_data[i]) {
|
||||
same = false;
|
||||
break;
|
||||
@@ -31,19 +31,19 @@ chai.use(function (_chai, utils) {
|
||||
});
|
||||
|
||||
_chai.Assertion.addMethod('sent', function (target_data) {
|
||||
var obj = this._obj;
|
||||
const obj = this._obj;
|
||||
obj.inspect = function () {
|
||||
var res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
||||
const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
||||
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
|
||||
res.prototype = obj;
|
||||
return res;
|
||||
};
|
||||
var data = obj._websocket._get_sent_data();
|
||||
var same = true;
|
||||
const data = obj._websocket._get_sent_data();
|
||||
let same = true;
|
||||
if (data.length != target_data.length) {
|
||||
same = false;
|
||||
} else {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i] != target_data[i]) {
|
||||
same = false;
|
||||
break;
|
||||
@@ -68,13 +68,12 @@ chai.use(function (_chai, utils) {
|
||||
_chai.Assertion.overwriteMethod('equal', function (_super) {
|
||||
return function assertArrayEqual(target) {
|
||||
if (utils.flag(this, 'array')) {
|
||||
var obj = this._obj;
|
||||
const obj = this._obj;
|
||||
|
||||
var i;
|
||||
var same = true;
|
||||
let same = true;
|
||||
|
||||
if (utils.flag(this, 'deep')) {
|
||||
for (i = 0; i < obj.length; i++) {
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
if (!utils.eql(obj[i], target[i])) {
|
||||
same = false;
|
||||
break;
|
||||
@@ -86,7 +85,7 @@ chai.use(function (_chai, utils) {
|
||||
"expected #{this} not to have elements deeply equal to #{exp}",
|
||||
Array.prototype.slice.call(target));
|
||||
} else {
|
||||
for (i = 0; i < obj.length; i++) {
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
if (obj[i] != target[i]) {
|
||||
same = false;
|
||||
break;
|
||||
|
||||
@@ -2,10 +2,10 @@ import Base64 from '../core/base64.js';
|
||||
|
||||
// PhantomJS can't create Event objects directly, so we need to use this
|
||||
function make_event(name, props) {
|
||||
var evt = document.createEvent('Event');
|
||||
const evt = document.createEvent('Event');
|
||||
evt.initEvent(name, true, true);
|
||||
if (props) {
|
||||
for (var prop in props) {
|
||||
for (let prop in props) {
|
||||
evt[prop] = props[prop];
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ FakeWebSocket.prototype = {
|
||||
},
|
||||
|
||||
_get_sent_data: function () {
|
||||
var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
||||
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
||||
this.bufferedAmount = 0;
|
||||
return res;
|
||||
},
|
||||
@@ -76,7 +76,7 @@ FakeWebSocket.__is_fake = true;
|
||||
|
||||
FakeWebSocket.replace = function () {
|
||||
if (!WebSocket.__is_fake) {
|
||||
var real_version = WebSocket;
|
||||
const real_version = WebSocket;
|
||||
// eslint-disable-next-line no-global-assign
|
||||
WebSocket = FakeWebSocket;
|
||||
FakeWebSocket.__real_version = real_version;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var TEST_REGEXP = /test\..*\.js/;
|
||||
var allTestFiles = [];
|
||||
var extraFiles = ['/base/tests/assertions.js'];
|
||||
const TEST_REGEXP = /test\..*\.js/;
|
||||
const allTestFiles = [];
|
||||
const extraFiles = ['/base/tests/assertions.js'];
|
||||
|
||||
Object.keys(window.__karma__.files).forEach(function (file) {
|
||||
if (TEST_REGEXP.test(file)) {
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
import * as WebUtil from '../app/webutil.js';
|
||||
import RecordingPlayer from './playback.js';
|
||||
|
||||
var frames = null;
|
||||
var encoding = null;
|
||||
let frames = null;
|
||||
let encoding = null;
|
||||
|
||||
function message(str) {
|
||||
var cell = document.getElementById('messages');
|
||||
const cell = document.getElementById('messages');
|
||||
cell.textContent += str + "\n";
|
||||
cell.scrollTop = cell.scrollHeight;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ function loadFile() {
|
||||
message("Loading " + fname);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var script = document.createElement("script");
|
||||
const script = document.createElement("script");
|
||||
script.onload = resolve;
|
||||
script.onerror = reject;
|
||||
document.body.appendChild(script);
|
||||
@@ -31,10 +31,10 @@ function loadFile() {
|
||||
}
|
||||
|
||||
function enableUI() {
|
||||
var iterations = WebUtil.getQueryVar('iterations', 3);
|
||||
const iterations = WebUtil.getQueryVar('iterations', 3);
|
||||
document.getElementById('iterations').value = iterations;
|
||||
|
||||
var mode = WebUtil.getQueryVar('mode', 3);
|
||||
const mode = WebUtil.getQueryVar('mode', 3);
|
||||
if (mode === 'realtime') {
|
||||
document.getElementById('mode2').checked = true;
|
||||
} else {
|
||||
@@ -121,7 +121,7 @@ IterationPlayer.prototype = {
|
||||
this._state = 'failed';
|
||||
}
|
||||
|
||||
var evt = new Event('rfbdisconnected');
|
||||
const evt = new Event('rfbdisconnected');
|
||||
evt.clean = clean;
|
||||
evt.frame = frame;
|
||||
evt.iteration = this._iteration;
|
||||
@@ -136,7 +136,7 @@ function start() {
|
||||
|
||||
const iterations = document.getElementById('iterations').value;
|
||||
|
||||
var mode;
|
||||
let mode;
|
||||
|
||||
if (document.getElementById('mode1').checked) {
|
||||
message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
|
||||
|
||||
@@ -9,12 +9,12 @@ import * as Log from '../core/util/logging.js';
|
||||
import Base64 from '../core/base64.js';
|
||||
|
||||
// Immediate polyfill
|
||||
if (setImmediate === undefined) {
|
||||
var _immediateIdCounter = 1;
|
||||
var _immediateFuncs = {};
|
||||
if (window.setImmediate === undefined) {
|
||||
let _immediateIdCounter = 1;
|
||||
const _immediateFuncs = {};
|
||||
|
||||
var setImmediate = function (func) {
|
||||
var index = _immediateIdCounter++;
|
||||
window.setImmediate = function (func) {
|
||||
const index = _immediateIdCounter++;
|
||||
_immediateFuncs[index] = func;
|
||||
window.postMessage("noVNC immediate trigger:" + index, "*");
|
||||
return index;
|
||||
@@ -24,15 +24,15 @@ if (setImmediate === undefined) {
|
||||
_immediateFuncs[id];
|
||||
};
|
||||
|
||||
var _onMessage = function (event) {
|
||||
const _onMessage = function (event) {
|
||||
if ((typeof event.data !== "string") ||
|
||||
(event.data.indexOf("noVNC immediate trigger:") !== 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = event.data.slice("noVNC immediate trigger:".length);
|
||||
const index = event.data.slice("noVNC immediate trigger:".length);
|
||||
|
||||
var callback = _immediateFuncs[index];
|
||||
const callback = _immediateFuncs[index];
|
||||
if (callback === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -51,8 +51,8 @@ export default function RecordingPlayer (frames, encoding, disconnected) {
|
||||
this._disconnected = disconnected;
|
||||
|
||||
if (this._encoding === undefined) {
|
||||
let frame = this._frames[0];
|
||||
let start = frame.indexOf('{', 1) + 1;
|
||||
const frame = this._frames[0];
|
||||
const start = frame.indexOf('{', 1) + 1;
|
||||
if (frame.slice(start).startsWith('UkZC')) {
|
||||
this._encoding = 'base64';
|
||||
} else {
|
||||
@@ -108,7 +108,7 @@ RecordingPlayer.prototype = {
|
||||
_queueNextPacket: function () {
|
||||
if (!this._running) { return; }
|
||||
|
||||
var frame = this._frames[this._frame_index];
|
||||
let frame = this._frames[this._frame_index];
|
||||
|
||||
// skip send frames
|
||||
while (this._frame_index < this._frame_length && frame.charAt(0) === "}") {
|
||||
@@ -129,8 +129,8 @@ RecordingPlayer.prototype = {
|
||||
}
|
||||
|
||||
if (this._realtime) {
|
||||
let foffset = frame.slice(1, frame.indexOf('{', 1));
|
||||
let toffset = (new Date()).getTime() - this._start_time;
|
||||
const foffset = frame.slice(1, frame.indexOf('{', 1));
|
||||
const toffset = (new Date()).getTime() - this._start_time;
|
||||
let delay = foffset - toffset;
|
||||
if (delay < 1) delay = 1;
|
||||
|
||||
@@ -143,8 +143,8 @@ RecordingPlayer.prototype = {
|
||||
_doPacket: function () {
|
||||
// Avoid having excessive queue buildup in non-realtime mode
|
||||
if (this._trafficManagement && this._rfb._flushing) {
|
||||
let player = this;
|
||||
let orig = this._rfb._display.onflush;
|
||||
const player = this;
|
||||
const orig = this._rfb._display.onflush;
|
||||
this._rfb._display.onflush = function () {
|
||||
player._rfb._display.onflush = orig;
|
||||
player._rfb._onFlush();
|
||||
@@ -154,8 +154,8 @@ RecordingPlayer.prototype = {
|
||||
}
|
||||
|
||||
const frame = this._frames[this._frame_index];
|
||||
var start = frame.indexOf('{', 1) + 1;
|
||||
var u8;
|
||||
let start = frame.indexOf('{', 1) + 1;
|
||||
let u8;
|
||||
if (this._encoding === 'base64') {
|
||||
u8 = Base64.decode(frame.slice(start));
|
||||
start = 0;
|
||||
@@ -174,7 +174,7 @@ RecordingPlayer.prototype = {
|
||||
|
||||
_finish() {
|
||||
if (this._rfb._display.pending()) {
|
||||
var player = this;
|
||||
const player = this;
|
||||
this._rfb._display.onflush = function () {
|
||||
if (player._rfb._flushing) {
|
||||
player._rfb._onFlush();
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import Base64 from '../core/base64.js';
|
||||
|
||||
describe('Base64 Tools', function() {
|
||||
"use strict";
|
||||
|
||||
var BIN_ARR = new Array(256);
|
||||
for (var i = 0; i < 256; i++) {
|
||||
const BIN_ARR = new Array(256);
|
||||
for (let i = 0; i < 256; i++) {
|
||||
BIN_ARR[i] = i;
|
||||
}
|
||||
|
||||
var B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
|
||||
const B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
|
||||
|
||||
|
||||
describe('encode', function() {
|
||||
it('should encode a binary string into Base64', function() {
|
||||
var encoded = Base64.encode(BIN_ARR);
|
||||
const encoded = Base64.encode(BIN_ARR);
|
||||
expect(encoded).to.equal(B64_STR);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decode', function() {
|
||||
it('should decode a Base64 string into a normal string', function() {
|
||||
var decoded = Base64.decode(B64_STR);
|
||||
const decoded = Base64.decode(B64_STR);
|
||||
expect(decoded).to.deep.equal(BIN_ARR);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import Base64 from '../core/base64.js';
|
||||
import Display from '../core/display.js';
|
||||
@@ -6,37 +6,35 @@ import Display from '../core/display.js';
|
||||
import sinon from '../vendor/sinon.js';
|
||||
|
||||
describe('Display/Canvas Helper', function () {
|
||||
var checked_data = [
|
||||
const checked_data = 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
|
||||
];
|
||||
checked_data = new Uint8Array(checked_data);
|
||||
]);
|
||||
|
||||
var basic_data = [0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255];
|
||||
basic_data = new Uint8Array(basic_data);
|
||||
const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]);
|
||||
|
||||
function make_image_canvas (input_data) {
|
||||
var canvas = document.createElement('canvas');
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 4;
|
||||
canvas.height = 4;
|
||||
var ctx = canvas.getContext('2d');
|
||||
var data = ctx.createImageData(4, 4);
|
||||
for (var i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; }
|
||||
const ctx = canvas.getContext('2d');
|
||||
const data = ctx.createImageData(4, 4);
|
||||
for (let i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; }
|
||||
ctx.putImageData(data, 0, 0);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
function make_image_png (input_data) {
|
||||
var canvas = make_image_canvas(input_data);
|
||||
var url = canvas.toDataURL();
|
||||
var data = url.split(",")[1];
|
||||
const canvas = make_image_canvas(input_data);
|
||||
const url = canvas.toDataURL();
|
||||
const data = url.split(",")[1];
|
||||
return Base64.decode(data);
|
||||
}
|
||||
|
||||
describe('viewport handling', function () {
|
||||
var display;
|
||||
let display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.clipViewport = true;
|
||||
@@ -51,10 +49,9 @@ describe('Display/Canvas Helper', function () {
|
||||
display.drawImage(make_image_canvas(basic_data), 1, 1);
|
||||
display.flip();
|
||||
|
||||
var expected = new Uint8Array(16);
|
||||
var i;
|
||||
for (i = 0; i < 8; i++) { expected[i] = basic_data[i]; }
|
||||
for (i = 8; i < 16; i++) { expected[i] = 0; }
|
||||
const expected = new Uint8Array(16);
|
||||
for (let i = 0; i < 8; i++) { expected[i] = basic_data[i]; }
|
||||
for (let i = 8; i < 16; i++) { expected[i] = 0; }
|
||||
expect(display).to.have.displayed(expected);
|
||||
});
|
||||
|
||||
@@ -119,7 +116,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
describe('resizing', function () {
|
||||
var display;
|
||||
let display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.clipViewport = false;
|
||||
@@ -136,8 +133,8 @@ describe('Display/Canvas Helper', function () {
|
||||
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
||||
display.resize(2, 2);
|
||||
display.flip();
|
||||
var expected = [];
|
||||
for (var i = 0; i < 4 * 2*2; i += 4) {
|
||||
const expected = [];
|
||||
for (let i = 0; i < 4 * 2*2; i += 4) {
|
||||
expected[i] = 0xff;
|
||||
expected[i+1] = expected[i+2] = 0;
|
||||
expected[i+3] = 0xff;
|
||||
@@ -179,8 +176,8 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
describe('rescaling', function () {
|
||||
var display;
|
||||
var canvas;
|
||||
let display;
|
||||
let canvas;
|
||||
|
||||
beforeEach(function () {
|
||||
canvas = document.createElement('canvas');
|
||||
@@ -220,8 +217,8 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
describe('autoscaling', function () {
|
||||
var display;
|
||||
var canvas;
|
||||
let display;
|
||||
let canvas;
|
||||
|
||||
beforeEach(function () {
|
||||
canvas = document.createElement('canvas');
|
||||
@@ -268,7 +265,7 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
|
||||
// basic cases
|
||||
var display;
|
||||
let display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.resize(4, 4);
|
||||
@@ -279,8 +276,8 @@ describe('Display/Canvas Helper', function () {
|
||||
display._logo = null;
|
||||
display.clear();
|
||||
display.resize(4, 4);
|
||||
var empty = [];
|
||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
||||
const empty = [];
|
||||
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
||||
expect(display).to.have.displayed(new Uint8Array(empty));
|
||||
});
|
||||
|
||||
@@ -300,8 +297,8 @@ describe('Display/Canvas Helper', function () {
|
||||
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
||||
display.flip();
|
||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||
var expected = [];
|
||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
||||
const expected = [];
|
||||
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
||||
expected[i] = 0xff;
|
||||
expected[i+1] = expected[i+2] = 0;
|
||||
expected[i+3] = 0xff;
|
||||
@@ -346,7 +343,7 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
// We have a special cache for 16x16 tiles that we need to test
|
||||
it('should support drawing a 16x16 tile', function () {
|
||||
let large_checked_data = new Uint8Array(16*16*4);
|
||||
const large_checked_data = new Uint8Array(16*16*4);
|
||||
display.resize(16, 16);
|
||||
|
||||
for (let y = 0;y < 16;y++) {
|
||||
@@ -371,8 +368,8 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
||||
var data = [];
|
||||
for (var i = 0; i < 16; i++) {
|
||||
const data = [];
|
||||
for (let i = 0; i < 16; i++) {
|
||||
data[i * 4] = checked_data[i * 4 + 2];
|
||||
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
||||
data[i * 4 + 2] = checked_data[i * 4];
|
||||
@@ -384,8 +381,8 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
||||
var data = [];
|
||||
for (var i = 0; i < 16; i++) {
|
||||
const data = [];
|
||||
for (let i = 0; i < 16; i++) {
|
||||
data[i * 3] = checked_data[i * 4];
|
||||
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
||||
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
||||
@@ -396,7 +393,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should support drawing an image object via #drawImage', function () {
|
||||
var img = make_image_canvas(checked_data);
|
||||
const img = make_image_canvas(checked_data);
|
||||
display.drawImage(img, 0, 0);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
@@ -404,7 +401,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
describe('the render queue processor', function () {
|
||||
var display;
|
||||
let display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.resize(4, 4);
|
||||
@@ -427,7 +424,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
|
||||
var img = { complete: false, addEventListener: sinon.spy() }
|
||||
const img = { complete: false, addEventListener: sinon.spy() }
|
||||
display._renderQ = [{ type: 'img', x: 3, y: 4, img: img },
|
||||
{ type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }];
|
||||
display.drawImage = sinon.spy();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import keysyms from '../core/input/keysymdef.js';
|
||||
import * as KeyboardUtil from "../core/input/util.js";
|
||||
@@ -64,7 +64,7 @@ describe('Helpers', function() {
|
||||
});
|
||||
|
||||
describe('Fix Meta on macOS', function() {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
@@ -127,7 +127,7 @@ describe('Helpers', function() {
|
||||
});
|
||||
|
||||
describe('Broken key AltGraph on IE/Edge', function() {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import sinon from '../vendor/sinon.js';
|
||||
|
||||
@@ -11,8 +11,8 @@ describe('Key Event Handling', function() {
|
||||
// The real KeyboardEvent constructor might not work everywhere we
|
||||
// want to run these tests
|
||||
function keyevent(typeArg, KeyboardEventInit) {
|
||||
var e = { type: typeArg };
|
||||
for (var key in KeyboardEventInit) {
|
||||
const e = { type: typeArg };
|
||||
for (let key in KeyboardEventInit) {
|
||||
e[key] = KeyboardEventInit[key];
|
||||
}
|
||||
e.stopPropagation = sinon.spy();
|
||||
@@ -23,7 +23,7 @@ describe('Key Event Handling', function() {
|
||||
describe('Decode Keyboard Events', function() {
|
||||
it('should decode keydown events', function(done) {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -34,8 +34,8 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
it('should decode keyup events', function(done) {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
var calls = 0;
|
||||
var kbd = new Keyboard(document);
|
||||
let calls = 0;
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -50,13 +50,13 @@ describe('Key Event Handling', function() {
|
||||
|
||||
describe('Legacy keypress Events', function() {
|
||||
it('should wait for keypress when needed', function() {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
it('should decode keypress events', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -67,14 +67,14 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyA', charCode: 0x61}));
|
||||
});
|
||||
it('should ignore keypress with different code', function() {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
it('should handle keypress with missing code', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -85,7 +85,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
|
||||
});
|
||||
it('should guess key if no keypress and numeric key', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x32);
|
||||
expect(code).to.be.equal('Digit2');
|
||||
@@ -95,7 +95,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
|
||||
});
|
||||
it('should guess key if no keypress and alpha key', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -105,7 +105,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
|
||||
});
|
||||
it('should guess key if no keypress and alpha key (with shift)', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x41);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -115,7 +115,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
|
||||
});
|
||||
it('should not guess key if no keypress and unknown key', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -131,25 +131,25 @@ describe('Key Event Handling', function() {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
});
|
||||
it('should suppress anything with a valid key', function() {
|
||||
var kbd = new Keyboard(document, {});
|
||||
var evt1 = keyevent('keydown', {code: 'KeyA', key: 'a'});
|
||||
const kbd = new Keyboard(document, {});
|
||||
const evt1 = keyevent('keydown', {code: 'KeyA', key: 'a'});
|
||||
kbd._handleKeyDown(evt1);
|
||||
expect(evt1.preventDefault).to.have.been.called;
|
||||
var evt2 = keyevent('keyup', {code: 'KeyA', key: 'a'});
|
||||
const evt2 = keyevent('keyup', {code: 'KeyA', key: 'a'});
|
||||
kbd._handleKeyUp(evt2);
|
||||
expect(evt2.preventDefault).to.have.been.called;
|
||||
});
|
||||
it('should not suppress keys without key', function() {
|
||||
var kbd = new Keyboard(document, {});
|
||||
var evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||
const kbd = new Keyboard(document, {});
|
||||
const evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||
kbd._handleKeyDown(evt);
|
||||
expect(evt.preventDefault).to.not.have.been.called;
|
||||
});
|
||||
it('should suppress the following keypress event', function() {
|
||||
var kbd = new Keyboard(document, {});
|
||||
var evt1 = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||
const kbd = new Keyboard(document, {});
|
||||
const evt1 = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||
kbd._handleKeyDown(evt1);
|
||||
var evt2 = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
|
||||
const evt2 = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
|
||||
kbd._handleKeyPress(evt2);
|
||||
expect(evt2.preventDefault).to.have.been.called;
|
||||
});
|
||||
@@ -159,8 +159,8 @@ describe('Key Event Handling', function() {
|
||||
describe('Fake keyup', function() {
|
||||
it('should fake keyup events for virtual keyboards', function(done) {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document);
|
||||
let count = 0;
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
@@ -179,7 +179,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
describe('iOS', function() {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
@@ -206,8 +206,8 @@ describe('Key Event Handling', function() {
|
||||
|
||||
it('should fake keyup events on iOS', function(done) {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document);
|
||||
let count = 0;
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
@@ -232,7 +232,7 @@ describe('Key Event Handling', function() {
|
||||
if (browser.isIE() || browser.isEdge()) this.skip();
|
||||
});
|
||||
it('should send release using the same keysym as the press', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -244,8 +244,8 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
|
||||
});
|
||||
it('should send the same keysym for multiple presses', function() {
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document);
|
||||
let count = 0;
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
@@ -257,7 +257,7 @@ describe('Key Event Handling', function() {
|
||||
expect(count).to.be.equal(2);
|
||||
});
|
||||
it('should do nothing on keyup events if no keys are down', function() {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
@@ -265,7 +265,7 @@ describe('Key Event Handling', function() {
|
||||
|
||||
describe('Legacy Events', function() {
|
||||
it('should track keys using keyCode if no code', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Platform65');
|
||||
@@ -277,7 +277,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyUp(keyevent('keyup', {keyCode: 65, key: 'b'}));
|
||||
});
|
||||
it('should ignore compositing code', function() {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Unidentified');
|
||||
@@ -285,7 +285,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
|
||||
});
|
||||
it('should track keys using keyIdentifier if no code', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Platform65');
|
||||
@@ -300,7 +300,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
describe('Shuffle modifiers on macOS', function() {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
@@ -326,8 +326,8 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should change Alt to AltGraph', function() {
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document);
|
||||
let count = 0;
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
@@ -345,7 +345,7 @@ describe('Key Event Handling', function() {
|
||||
expect(count).to.be.equal(2);
|
||||
});
|
||||
it('should change left Super to Alt', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0xFFE9);
|
||||
expect(code).to.be.equal('MetaLeft');
|
||||
@@ -354,7 +354,7 @@ describe('Key Event Handling', function() {
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
|
||||
});
|
||||
it('should change right Super to left Super', function(done) {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0xFFEB);
|
||||
expect(code).to.be.equal('MetaRight');
|
||||
@@ -365,7 +365,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
describe('Escape AltGraph on Windows', function() {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
@@ -394,14 +394,14 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should supress ControlLeft until it knows if it is AltGr', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should not trigger on repeating ControlLeft', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
@@ -411,7 +411,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should not supress ControlRight', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlRight', key: 'Control', location: 2}));
|
||||
expect(kbd.onkeyevent).to.have.been.calledOnce;
|
||||
@@ -419,7 +419,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should release ControlLeft after 100 ms', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
@@ -429,7 +429,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should release ControlLeft on other key press', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
@@ -445,7 +445,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should release ControlLeft on other key release', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
@@ -463,7 +463,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should generate AltGraph for quick Ctrl+Alt sequence', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
|
||||
this.clock.tick(20);
|
||||
@@ -478,7 +478,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should generate Ctrl, Alt for slow Ctrl+Alt sequence', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
|
||||
this.clock.tick(60);
|
||||
@@ -494,7 +494,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should pass through single Alt', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
|
||||
expect(kbd.onkeyevent).to.have.been.calledOnce;
|
||||
@@ -502,7 +502,7 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should pass through single AltGr', function () {
|
||||
var kbd = new Keyboard(document);
|
||||
const kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'AltGraph', location: 2}));
|
||||
expect(kbd.onkeyevent).to.have.been.calledOnce;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
var expect = chai.expect;
|
||||
|
||||
const expect = chai.expect;
|
||||
import { l10n } from '../app/localization.js';
|
||||
|
||||
describe('Localization', function() {
|
||||
"use strict";
|
||||
|
||||
describe('language selection', function () {
|
||||
var origNavigator;
|
||||
let origNavigator;
|
||||
beforeEach(function () {
|
||||
// window.navigator is a protected read-only property in many
|
||||
// environments, so we need to redefine it whilst running these
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import sinon from '../vendor/sinon.js';
|
||||
|
||||
@@ -14,24 +14,24 @@ describe('Mouse Event Handling', function() {
|
||||
// located at coordinates 10x10
|
||||
sinon.stub(Element.prototype, 'getBoundingClientRect').returns(
|
||||
{left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100});
|
||||
var target = document.createElement('canvas');
|
||||
const target = document.createElement('canvas');
|
||||
|
||||
// The real constructors might not work everywhere we
|
||||
// want to run these tests
|
||||
var mouseevent, touchevent;
|
||||
mouseevent = touchevent = function(typeArg, MouseEventInit) {
|
||||
var e = { type: typeArg };
|
||||
for (var key in MouseEventInit) {
|
||||
const mouseevent = function(typeArg, MouseEventInit) {
|
||||
const e = { type: typeArg };
|
||||
for (let key in MouseEventInit) {
|
||||
e[key] = MouseEventInit[key];
|
||||
}
|
||||
e.stopPropagation = sinon.spy();
|
||||
e.preventDefault = sinon.spy();
|
||||
return e;
|
||||
};
|
||||
const touchevent = mouseevent;
|
||||
|
||||
describe('Decode Mouse Events', function() {
|
||||
it('should decode mousedown events', function(done) {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
expect(down).to.be.equal(1);
|
||||
@@ -40,8 +40,8 @@ describe('Mouse Event Handling', function() {
|
||||
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
|
||||
});
|
||||
it('should decode mouseup events', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
if (calls++ === 1) {
|
||||
@@ -53,7 +53,7 @@ describe('Mouse Event Handling', function() {
|
||||
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
|
||||
});
|
||||
it('should decode mousemove events', function(done) {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousemove = function(x, y) {
|
||||
// Note that target relative coordinates are sent
|
||||
expect(x).to.be.equal(40);
|
||||
@@ -64,8 +64,8 @@ describe('Mouse Event Handling', function() {
|
||||
{ clientX: 50, clientY: 20 }));
|
||||
});
|
||||
it('should decode mousewheel events', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
expect(bmask).to.be.equal(1<<6);
|
||||
@@ -88,8 +88,8 @@ describe('Mouse Event Handling', function() {
|
||||
afterEach(function () { this.clock.restore(); });
|
||||
|
||||
it('should use same pos for 2nd tap if close enough', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
@@ -119,8 +119,8 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should not modify 2nd tap pos if far apart', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
@@ -148,8 +148,8 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should not modify 2nd tap pos if not soon enough', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
@@ -177,8 +177,8 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should not modify 2nd tap pos if not touch', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target);
|
||||
let calls = 0;
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
@@ -213,7 +213,7 @@ describe('Mouse Event Handling', function() {
|
||||
afterEach(function () { this.clock.restore(); });
|
||||
|
||||
it('should accumulate wheel events if small enough', function () {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
@@ -246,7 +246,7 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should not accumulate large wheel events', function () {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
@@ -265,7 +265,7 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should send even small wheel events after a timeout', function () {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
@@ -277,7 +277,7 @@ describe('Mouse Event Handling', function() {
|
||||
});
|
||||
|
||||
it('should account for non-zero deltaMode', function () {
|
||||
var mouse = new Mouse(target);
|
||||
const mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable no-console */
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import * as Log from '../core/util/logging.js';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import Websock from '../core/websock.js';
|
||||
import FakeWebSocket from './fake.websocket.js';
|
||||
@@ -9,8 +9,8 @@ describe('Websock', function() {
|
||||
"use strict";
|
||||
|
||||
describe('Queue methods', function () {
|
||||
var sock;
|
||||
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
let sock;
|
||||
const RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
@@ -35,8 +35,8 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQpeek8', function () {
|
||||
it('should peek at the next byte without poping it off the queue', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
var peek = sock.rQpeek8();
|
||||
const bef_len = sock.rQlen();
|
||||
const peek = sock.rQpeek8();
|
||||
expect(sock.rQpeek8()).to.equal(peek);
|
||||
expect(sock.rQlen()).to.equal(bef_len);
|
||||
});
|
||||
@@ -44,8 +44,8 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQshift8', function () {
|
||||
it('should pop a single byte from the receive queue', function () {
|
||||
var peek = sock.rQpeek8();
|
||||
var bef_len = sock.rQlen();
|
||||
const peek = sock.rQpeek8();
|
||||
const bef_len = sock.rQlen();
|
||||
expect(sock.rQshift8()).to.equal(peek);
|
||||
expect(sock.rQlen()).to.equal(bef_len - 1);
|
||||
});
|
||||
@@ -53,8 +53,8 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQshift16', function () {
|
||||
it('should pop two bytes from the receive queue and return a single number', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
var expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
|
||||
const bef_len = sock.rQlen();
|
||||
const expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
|
||||
expect(sock.rQshift16()).to.equal(expected);
|
||||
expect(sock.rQlen()).to.equal(bef_len - 2);
|
||||
});
|
||||
@@ -62,8 +62,8 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQshift32', function () {
|
||||
it('should pop four bytes from the receive queue and return a single number', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
var expected = (RQ_TEMPLATE[0] << 24) +
|
||||
const bef_len = sock.rQlen();
|
||||
const expected = (RQ_TEMPLATE[0] << 24) +
|
||||
(RQ_TEMPLATE[1] << 16) +
|
||||
(RQ_TEMPLATE[2] << 8) +
|
||||
RQ_TEMPLATE[3];
|
||||
@@ -74,9 +74,9 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQshiftStr', function () {
|
||||
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
var bef_rQi = sock.get_rQi();
|
||||
var shifted = sock.rQshiftStr(3);
|
||||
const bef_len = sock.rQlen();
|
||||
const bef_rQi = sock.get_rQi();
|
||||
const shifted = sock.rQshiftStr(3);
|
||||
expect(shifted).to.be.a('string');
|
||||
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
|
||||
expect(sock.rQlen()).to.equal(bef_len - 3);
|
||||
@@ -90,9 +90,9 @@ describe('Websock', function() {
|
||||
|
||||
describe('rQshiftBytes', function () {
|
||||
it('should shift the given number of bytes of the receive queue and return an array', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
var bef_rQi = sock.get_rQi();
|
||||
var shifted = sock.rQshiftBytes(3);
|
||||
const bef_len = sock.rQlen();
|
||||
const bef_rQi = sock.get_rQi();
|
||||
const shifted = sock.rQshiftBytes(3);
|
||||
expect(shifted).to.be.an.instanceof(Uint8Array);
|
||||
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3));
|
||||
expect(sock.rQlen()).to.equal(bef_len - 3);
|
||||
@@ -110,19 +110,19 @@ describe('Websock', function() {
|
||||
});
|
||||
|
||||
it('should not modify the receive queue', function () {
|
||||
var bef_len = sock.rQlen();
|
||||
const bef_len = sock.rQlen();
|
||||
sock.rQslice(0, 2);
|
||||
expect(sock.rQlen()).to.equal(bef_len);
|
||||
});
|
||||
|
||||
it('should return an array containing the given slice of the receive queue', function () {
|
||||
var sl = sock.rQslice(0, 2);
|
||||
const sl = sock.rQslice(0, 2);
|
||||
expect(sl).to.be.an.instanceof(Uint8Array);
|
||||
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 0, 2));
|
||||
});
|
||||
|
||||
it('should use the rest of the receive queue if no end is given', function () {
|
||||
var sl = sock.rQslice(1);
|
||||
const sl = sock.rQslice(1);
|
||||
expect(sl).to.have.length(RQ_TEMPLATE.length - 1);
|
||||
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 1));
|
||||
});
|
||||
@@ -176,7 +176,7 @@ describe('Websock', function() {
|
||||
sock._websocket.readyState = WebSocket.OPEN
|
||||
sock._sQ = new Uint8Array([1, 2, 3]);
|
||||
sock._sQlen = 3;
|
||||
var encoded = sock._encode_message();
|
||||
const encoded = sock._encode_message();
|
||||
|
||||
sock.flush();
|
||||
expect(sock._websocket.send).to.have.been.calledOnce;
|
||||
@@ -200,7 +200,7 @@ describe('Websock', function() {
|
||||
|
||||
it('should add to the send queue', function () {
|
||||
sock.send([1, 2, 3]);
|
||||
var sq = sock.get_sQ();
|
||||
const sq = sock.get_sQ();
|
||||
expect(new Uint8Array(sq.buffer, sock._sQlen - 3, 3)).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||
});
|
||||
|
||||
@@ -223,12 +223,12 @@ describe('Websock', function() {
|
||||
});
|
||||
|
||||
describe('lifecycle methods', function () {
|
||||
var old_WS;
|
||||
let old_WS;
|
||||
before(function () {
|
||||
old_WS = WebSocket;
|
||||
});
|
||||
|
||||
var sock;
|
||||
let sock;
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
// eslint-disable-next-line no-global-assign
|
||||
@@ -333,14 +333,14 @@ describe('Websock', function() {
|
||||
});
|
||||
|
||||
describe('WebSocket Receiving', function () {
|
||||
var sock;
|
||||
let sock;
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
sock._allocate_buffers();
|
||||
});
|
||||
|
||||
it('should support adding binary Uint8Array data to the receive queue', function () {
|
||||
var msg = { data: new Uint8Array([1, 2, 3]) };
|
||||
const msg = { data: new Uint8Array([1, 2, 3]) };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03');
|
||||
@@ -348,7 +348,7 @@ describe('Websock', function() {
|
||||
|
||||
it('should call the message event handler if present', function () {
|
||||
sock._eventHandlers.message = sinon.spy();
|
||||
var msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
expect(sock._eventHandlers.message).to.have.been.calledOnce;
|
||||
@@ -356,7 +356,7 @@ describe('Websock', function() {
|
||||
|
||||
it('should not call the message event handler if there is nothing in the receive queue', function () {
|
||||
sock._eventHandlers.message = sinon.spy();
|
||||
var msg = { data: new Uint8Array([]).buffer };
|
||||
const msg = { data: new Uint8Array([]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
expect(sock._eventHandlers.message).not.to.have.been.called;
|
||||
@@ -369,7 +369,7 @@ describe('Websock', function() {
|
||||
sock._rQlen = 6;
|
||||
sock.set_rQi(6);
|
||||
sock._rQmax = 3;
|
||||
var msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
expect(sock._rQlen).to.equal(3);
|
||||
@@ -382,7 +382,7 @@ describe('Websock', function() {
|
||||
sock.set_rQi(0);
|
||||
sock._rQbufferSize = 20;
|
||||
sock._rQmax = 2;
|
||||
var msg = { data: new Uint8Array(30).buffer };
|
||||
const msg = { data: new Uint8Array(30).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
expect(sock._rQlen).to.equal(30);
|
||||
@@ -396,7 +396,7 @@ describe('Websock', function() {
|
||||
after(function () { FakeWebSocket.restore(); });
|
||||
|
||||
describe('as binary data', function () {
|
||||
var sock;
|
||||
let sock;
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
sock.open('ws://', 'binary');
|
||||
@@ -406,7 +406,7 @@ describe('Websock', function() {
|
||||
it('should only send the send queue up to the send queue length', function () {
|
||||
sock._sQ = new Uint8Array([1, 2, 3, 4, 5]);
|
||||
sock._sQlen = 3;
|
||||
var res = sock._encode_message();
|
||||
const res = sock._encode_message();
|
||||
expect(res).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* jshint expr: true */
|
||||
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
import * as WebUtil from '../app/webutil.js';
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('WebUtil', function() {
|
||||
describe('settings', function () {
|
||||
|
||||
describe('localStorage', function() {
|
||||
var chrome = window.chrome;
|
||||
let chrome = window.chrome;
|
||||
before(function() {
|
||||
chrome = window.chrome;
|
||||
window.chrome = null;
|
||||
@@ -21,7 +21,7 @@ describe('WebUtil', function() {
|
||||
window.chrome = chrome;
|
||||
});
|
||||
|
||||
var origLocalStorage;
|
||||
let origLocalStorage;
|
||||
beforeEach(function() {
|
||||
origLocalStorage = Object.getOwnPropertyDescriptor(window, "localStorage");
|
||||
if (origLocalStorage === undefined) {
|
||||
@@ -110,8 +110,8 @@ describe('WebUtil', function() {
|
||||
});
|
||||
|
||||
describe('chrome.storage', function() {
|
||||
var chrome = window.chrome;
|
||||
var settings = {};
|
||||
let chrome = window.chrome;
|
||||
let settings = {};
|
||||
before(function() {
|
||||
chrome = window.chrome;
|
||||
window.chrome = {
|
||||
@@ -128,7 +128,7 @@ describe('WebUtil', function() {
|
||||
window.chrome = chrome;
|
||||
});
|
||||
|
||||
var csSandbox = sinon.createSandbox();
|
||||
const csSandbox = sinon.createSandbox();
|
||||
|
||||
beforeEach(function() {
|
||||
settings = {};
|
||||
|
||||
Reference in New Issue
Block a user