summaryrefslogtreecommitdiff
path: root/tests/fake.websocket.js
diff options
context:
space:
mode:
authorSolly Ross <sross@redhat.com>2017-02-05 12:34:47 -0500
committerSolly Ross <sross@redhat.com>2017-03-21 17:39:07 -0400
commitdfae3209ebcde77a341addbb55514d8285499d73 (patch)
treea9e4e6547e10b4d3ebff69506b68ce73463fe3ad /tests/fake.websocket.js
parent6d6f0db0da5a46e530fc891136224d58771c00c6 (diff)
downloadnovnc-dfae3209ebcde77a341addbb55514d8285499d73.tar.gz
Update tests to work with new structure
This updates the tests to work with the new structure, and removes the old `utils/run_from_console.js` files in favor of just using Karma directly. The Karma debug page now displays the normal mocha HTML, so we can use that instead of the HTML generation functionality of the old test runner. Note that PhantomJS does not work at the moment (PhantomJS 1.5 should make it possible to test on PhantomJS again).
Diffstat (limited to 'tests/fake.websocket.js')
-rw-r--r--tests/fake.websocket.js146
1 files changed, 71 insertions, 75 deletions
diff --git a/tests/fake.websocket.js b/tests/fake.websocket.js
index 2101205..eb4f203 100644
--- a/tests/fake.websocket.js
+++ b/tests/fake.websocket.js
@@ -1,91 +1,87 @@
-var FakeWebSocket;
-
-(function () {
- // PhantomJS can't create Event objects directly, so we need to use this
- function make_event(name, props) {
- var evt = document.createEvent('Event');
- evt.initEvent(name, true, true);
- if (props) {
- for (var prop in props) {
- evt[prop] = props[prop];
- }
+// PhantomJS can't create Event objects directly, so we need to use this
+function make_event(name, props) {
+ var evt = document.createEvent('Event');
+ evt.initEvent(name, true, true);
+ if (props) {
+ for (var prop in props) {
+ evt[prop] = props[prop];
}
- return evt;
}
+ return evt;
+}
- FakeWebSocket = function (uri, protocols) {
- this.url = uri;
- this.binaryType = "arraybuffer";
- this.extensions = "";
-
- if (!protocols || typeof protocols === 'string') {
- this.protocol = protocols;
- } else {
- this.protocol = protocols[0];
- }
+export default function FakeWebSocket (uri, protocols) {
+ this.url = uri;
+ this.binaryType = "arraybuffer";
+ this.extensions = "";
- this._send_queue = new Uint8Array(20000);
+ if (!protocols || typeof protocols === 'string') {
+ this.protocol = protocols;
+ } else {
+ this.protocol = protocols[0];
+ }
- this.readyState = FakeWebSocket.CONNECTING;
- this.bufferedAmount = 0;
+ this._send_queue = new Uint8Array(20000);
- this.__is_fake = true;
- };
+ this.readyState = FakeWebSocket.CONNECTING;
+ this.bufferedAmount = 0;
- FakeWebSocket.prototype = {
- close: function (code, reason) {
- this.readyState = FakeWebSocket.CLOSED;
- if (this.onclose) {
- this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
- }
- },
+ this.__is_fake = true;
+};
- send: function (data) {
- if (this.protocol == 'base64') {
- data = Base64.decode(data);
- } else {
- data = new Uint8Array(data);
- }
- this._send_queue.set(data, this.bufferedAmount);
- this.bufferedAmount += data.length;
- },
+FakeWebSocket.prototype = {
+ close: function (code, reason) {
+ this.readyState = FakeWebSocket.CLOSED;
+ if (this.onclose) {
+ this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
+ }
+ },
- _get_sent_data: function () {
- var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
- this.bufferedAmount = 0;
- return res;
- },
+ send: function (data) {
+ if (this.protocol == 'base64') {
+ data = Base64.decode(data);
+ } else {
+ data = new Uint8Array(data);
+ }
+ this._send_queue.set(data, this.bufferedAmount);
+ this.bufferedAmount += data.length;
+ },
- _open: function (data) {
- this.readyState = FakeWebSocket.OPEN;
- if (this.onopen) {
- this.onopen(make_event('open'));
- }
- },
+ _get_sent_data: function () {
+ var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
+ this.bufferedAmount = 0;
+ return res;
+ },
- _receive_data: function (data) {
- this.onmessage(make_event("message", { 'data': data }));
+ _open: function (data) {
+ this.readyState = FakeWebSocket.OPEN;
+ if (this.onopen) {
+ this.onopen(make_event('open'));
}
- };
+ },
- FakeWebSocket.OPEN = WebSocket.OPEN;
- FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
- FakeWebSocket.CLOSING = WebSocket.CLOSING;
- FakeWebSocket.CLOSED = WebSocket.CLOSED;
+ _receive_data: function (data) {
+ this.onmessage(make_event("message", { 'data': data }));
+ }
+};
- FakeWebSocket.__is_fake = true;
+FakeWebSocket.OPEN = WebSocket.OPEN;
+FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
+FakeWebSocket.CLOSING = WebSocket.CLOSING;
+FakeWebSocket.CLOSED = WebSocket.CLOSED;
- FakeWebSocket.replace = function () {
- if (!WebSocket.__is_fake) {
- var real_version = WebSocket;
- WebSocket = FakeWebSocket;
- FakeWebSocket.__real_version = real_version;
- }
- };
+FakeWebSocket.__is_fake = true;
- FakeWebSocket.restore = function () {
- if (WebSocket.__is_fake) {
- WebSocket = WebSocket.__real_version;
- }
- };
-})();
+FakeWebSocket.replace = function () {
+ if (!WebSocket.__is_fake) {
+ var real_version = WebSocket;
+ WebSocket = FakeWebSocket;
+ FakeWebSocket.__real_version = real_version;
+ }
+};
+
+FakeWebSocket.restore = function () {
+ if (WebSocket.__is_fake) {
+ WebSocket = WebSocket.__real_version;
+ }
+};