]> git.proxmox.com Git - mirror_novnc.git/blobdiff - tests/fake.websocket.js
Remove createEvent() fallbacks
[mirror_novnc.git] / tests / fake.websocket.js
index 623b25e48ed80b0a3e9a153c0eb983496bee872c..4db3c59023680ee05035184992e093e847426e47 100644 (file)
@@ -1,17 +1,5 @@
 import Base64 from '../core/base64.js';
 
-// PhantomJS can't create Event objects directly, so we need to use this
-function makeEvent(name, props) {
-    const evt = document.createEvent('Event');
-    evt.initEvent(name, true, true);
-    if (props) {
-        for (let prop in props) {
-            evt[prop] = props[prop];
-        }
-    }
-    return evt;
-}
-
 export default class FakeWebSocket {
     constructor(uri, protocols) {
         this.url = uri;
@@ -35,7 +23,7 @@ export default class FakeWebSocket {
     close(code, reason) {
         this.readyState = FakeWebSocket.CLOSED;
         if (this.onclose) {
-            this.onclose(makeEvent("close", { 'code': code, 'reason': reason, 'wasClean': true }));
+            this.onclose(new CloseEvent("close", { 'code': code, 'reason': reason, 'wasClean': true }));
         }
     }
 
@@ -58,7 +46,7 @@ export default class FakeWebSocket {
     _open() {
         this.readyState = FakeWebSocket.OPEN;
         if (this.onopen) {
-            this.onopen(makeEvent('open'));
+            this.onopen(new Event('open'));
         }
     }
 
@@ -67,7 +55,7 @@ export default class FakeWebSocket {
         // neatly packaged
         for (let i = 0;i < data.length;i++) {
             let buf = data.subarray(i, i+1);
-            this.onmessage(makeEvent("message", { 'data': buf }));
+            this.onmessage(new MessageEvent("message", { 'data': buf }));
         }
     }
 }