1 //describe, beforeAll, it, expext - are the Jasmine default methods
2 //karmaHTML is the karma-html package object with the access to all its features
4 describe("The WebAssembly Browser Test Suite",function(){
6 const DEFAULT_TIMEOUT = 1000;
7 const DEFAULT_WS_TIMEOUT = 5000;
9 beforeAll(function(done){
10 //load DOM custom matchers from karma-jasmine-dom package
11 jasmine.addMatchers(DOMCustomMatchers);
13 //lets open our 'http-spec.html' file in the browser by 'index' tag as you specified in 'karma.conf.js'
14 karmaHTML.httpspec.open();
16 //karmaHTML.httpspec.onstatechange fires when the Document is loaded
17 //now the tests can be executed on the DOM
18 karmaHTML.httpspec.onstatechange = function(ready){
19 //if the #Document is ready, fire tests
20 //the done() callback is the jasmine native async-support function
22 karmaHTML.httpspec.document.onRuntimeDone = function ()
32 it("should be a real Document object",function(){
33 var _document = karmaHTML.httpspec.document;
34 expect(_document.constructor.name).toEqual('HTMLDocument');
37 it('should support streaming', () => {
38 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
39 var _document = karmaHTML.httpspec.document;
41 assert.equal(_document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:IsStreamingSupported", []), true);
45 it('should have streaming enabled', () => {
46 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
47 var _document = karmaHTML.httpspec.document;
49 assert.equal(_document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:IsStreamingEnabled", []), true);
52 it('should have base path', () => {
53 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
54 var _document = karmaHTML.httpspec.document;
56 assert.equal(_document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:BasePath", []), "http://localhost:9876/");
59 it('RequestStream: should return size of Stream with streaming', (done) => {
60 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
61 var _document = karmaHTML.httpspec.document;
63 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestStream", [true, "base/publish/NowIsTheTime.txt"]).then(
66 //console.log("we are here: " + result);
68 assert.equal(result, 500000, "result doesn't match length");
74 (error) => done.fail(error)
80 it('RequestStream: blob should return size of Stream with streaming', (done) => {
81 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
82 var _document = karmaHTML.httpspec.document;
83 var blob = new Blob([JSON.stringify({hello: "world"}, null, 2)], {type : 'application/json'});
84 var blobUrl = URL.createObjectURL(blob);
86 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestStream", [true, blobUrl]).then(
89 //console.log("we are here: " + result);
91 assert.equal(result, 22, "result doesn't match length");
97 (error) => done.fail(error)
101 URL.revokeObjectURL(blobUrl);
104 it('RequestByteArray: should return size of ByteArray with streaming', (done) => {
105 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
106 var _document = karmaHTML.httpspec.document;
108 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestByteArray", [true, "base/publish/NowIsTheTime.txt"]).then(
111 //console.log("we are here: " + result);
113 assert.equal(result, 500000, "result doesn't match length");
119 (error) => done.fail(error)
125 it('RequestByteArray: blob should return size of ByteArray with streaming', (done) => {
126 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
127 var _document = karmaHTML.httpspec.document;
128 var blob = new Blob([JSON.stringify({hello: "world"}, null, 2)], {type : 'application/json'});
129 var blobUrl = URL.createObjectURL(blob);
131 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestByteArray", [true, blobUrl]).then(
134 //console.log("we are here: " + result);
136 assert.equal(result, 22, "result doesn't match length");
142 (error) => done.fail(error)
146 URL.revokeObjectURL(blobUrl);
149 it('RequestStream: should return size of Stream without streaming', (done) => {
150 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
151 var _document = karmaHTML.httpspec.document;
153 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestStream", [false, "base/publish/NowIsTheTime.txt"]).then(
156 //console.log("we are here: " + result);
158 assert.equal(result, 500000, "result doesn't match length");
164 (error) => done.fail(error)
170 it('RequestStream: blob should return size of Stream without streaming', (done) => {
171 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
172 var _document = karmaHTML.httpspec.document;
173 var blob = new Blob([JSON.stringify({hello: "world"}, null, 2)], {type : 'application/json'});
174 var blobUrl = URL.createObjectURL(blob);
176 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestStream", [false, blobUrl]).then(
179 //console.log("we are here: " + result);
181 assert.equal(result, 22, "result doesn't match length");
187 (error) => done.fail(error)
191 URL.revokeObjectURL(blobUrl);
194 it('RequestByteArray: should return size of ByteArray without streaming', (done) => {
195 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
196 var _document = karmaHTML.httpspec.document;
198 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestByteArray", [false, "base/publish/NowIsTheTime.txt"]).then(
201 //console.log("we are here: " + result);
203 assert.equal(result, 500000, "result doesn't match length");
209 (error) => done.fail(error)
215 it('RequestByteArray: blob should return size of ByteArray without streaming', (done) => {
216 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
217 var _document = karmaHTML.httpspec.document;
218 var blob = new Blob([JSON.stringify({hello: "world"}, null, 2)], {type : 'application/json'});
219 var blobUrl = URL.createObjectURL(blob);
221 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:RequestByteArray", [false, blobUrl]).then(
224 //console.log("we are here: " + result);
226 assert.equal(result, 22, "result doesn't match length");
232 (error) => done.fail(error)
236 URL.revokeObjectURL(blobUrl);
239 it('GetStreamAsync_ReadZeroBytes_Success: should return 0', (done) => {
240 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
241 var _document = karmaHTML.httpspec.document;
243 _document.Module.BINDING.call_static_method("[HttpTestSuite]TestSuite.Program:GetStreamAsync_ReadZeroBytes_Success", []).then(
246 //console.log("we are here: " + result);
248 assert.equal(result, 0, "result doesn't match expected result 0");
254 (error) => done.fail(error)
260 it('ConnectWebSocketStatus: should return Error Code 1006 because unresolved host.', (done) => {
261 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
262 var _document = karmaHTML.httpspec.document;
264 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:ConnectWebSocketStatus", ["ws://localhost", ""]).then(
268 assert.equal(result, '1006', "result doesn't match expected result 1006.");
274 (error) => done.fail(error)
278 }, DEFAULT_WS_TIMEOUT);
280 it('ConnectWebSocketStatus: should return Error Code 1006 because of invalid protocol.', (done) => {
281 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
282 var _document = karmaHTML.httpspec.document;
284 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:ConnectWebSocketStatus", ["ws://localhost:8889", ""]).then(
288 assert.equal(result, '1006', "result doesn't match expected result 1006.");
294 (error) => done.fail(error)
298 }, DEFAULT_WS_TIMEOUT);
300 it('ConnectWebSocketStatusWithToken: should return Error Code 1006 because unresolved host.', (done) => {
301 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
302 var _document = karmaHTML.httpspec.document;
304 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:ConnectWebSocketStatusWithToken", ["ws://localhost", ""]).then(
308 assert.equal(result, '1006', "result doesn't match expected result 1006.");
314 (error) => done.fail(error)
318 }, DEFAULT_WS_TIMEOUT);
320 it('ConnectWebSocketStatusWithToken: should return Error Code 1006 because of invalid protocol.', (done) => {
321 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
322 var _document = karmaHTML.httpspec.document;
324 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:ConnectWebSocketStatusWithToken", ["ws://localhost:8889", ""]).then(
328 assert.equal(result, '1006', "result doesn't match expected result 1006.");
334 (error) => done.fail(error)
338 }, DEFAULT_WS_TIMEOUT);
340 it('OpenWebSocket: should return Open.', (done) => {
341 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
342 var _document = karmaHTML.httpspec.document;
344 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:OpenWebSocket", ["ws://localhost:8889", "echo-protocol"]).then(
348 assert.equal(result, 'Open', "result doesn't match expected result Open.");
354 (error) => done.fail(error)
360 it('CloseWebSocket: should return Closed.', (done) => {
361 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
362 var _document = karmaHTML.httpspec.document;
364 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:CloseWebSocket", ["ws://localhost:8889", "echo-protocol"]).then(
368 assert.equal(result, 'Closed', "result doesn't match expected result Closed.");
374 (error) => done.fail(error)
381 it('RecieveHostCloseWebSocket: should return Closed.', (done) => {
382 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
383 var _document = karmaHTML.httpspec.document;
385 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:RecieveHostCloseWebSocket", ["ws://localhost:8889", "echo-protocol"]).then(
389 assert.equal(result, 'Closed', "result doesn't match expected result Closed.");
395 (error) => done.fail(error)
401 it('CloseStatusDescCloseWebSocket: should return Close Code and Description.', (done) => {
402 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
403 var _document = karmaHTML.httpspec.document;
405 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:CloseStatusDescCloseWebSocket", ["ws://localhost:8889", "echo-protocol"]).then(
409 var resultObj = JSON.parse(result);
410 assert.equal(resultObj.code, 'NormalClosure', "code result doesn't match expected result NormalClosure.");
411 assert.equal(resultObj.desc, 'bye!', "description result doesn't match expected result 'bye!'.");
417 (error) => done.fail(error)
423 it('WebSocketSendText: should return echoed text.', (done) => {
424 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
425 var _document = karmaHTML.httpspec.document;
427 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:WebSocketSendText", ["ws://localhost:8889", "echo-protocol", "Hello WebSockets"]).then(
431 assert.equal(result, 'Hello WebSockets', "result does not match Hello WebSockets.");
437 (error) => done.fail(error)
443 it('WebSocketSendBinary: should return echoed text.', (done) => {
444 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
445 var _document = karmaHTML.httpspec.document;
446 var binBuffer = new Uint8Array([49,50,51,52,53,54,55,56,57])
447 _document.Module.BINDING.call_static_method("[WebSocketTestSuite]TestSuite.Program:WebSocketSendBinary", ["ws://localhost:8889", "echo-protocol", "Hello WebSockets"]).then(
451 assert.equal(result, 'Hello WebSockets', "result does not match Hello WebSockets.");
457 (error) => done.fail(error)
460 }, DEFAULT_WS_TIMEOUT);
462 it('BindingTestSuite: Should return new Uint8ClampedArray from a c# byte array.', () => {
463 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
464 var _document = karmaHTML.httpspec.document;
467 var clamped = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Uint8ClampedArrayFrom", []);
468 assert.equal(clamped.length, 50, "result does not match length of 50.");
469 assert.equal(Object.prototype.toString.call(clamped), "[object Uint8ClampedArray]", "TypedArray is not of type Uint8ClampedArray" )
473 it('BindingTestSuite: Should return new Uint8Array from a c# byte array.', () => {
474 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
475 var _document = karmaHTML.httpspec.document;
477 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Uint8ArrayFrom", []);
478 assert.equal(arr.length, 50, "result does not match length of 50.");
479 assert.equal(Object.prototype.toString.call(arr), "[object Uint8Array]", "TypedArray is not of type Uint8Array" )
483 it('BindingTestSuite: Should return new Uint16Array from a c# ushort array.', () => {
484 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
485 var _document = karmaHTML.httpspec.document;
487 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Uint16ArrayFrom", []);
488 assert.equal(arr.length, 50, "result does not match length of 50.");
489 assert.equal(Object.prototype.toString.call(arr), "[object Uint16Array]", "TypedArray is not of type Uint16Array" )
493 it('BindingTestSuite: Should return new Uint32Array from a c# uint array.', () => {
494 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
495 var _document = karmaHTML.httpspec.document;
497 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Uint32ArrayFrom", []);
498 assert.equal(arr.length, 50, "result does not match length of 50.");
499 assert.equal(Object.prototype.toString.call(arr), "[object Uint32Array]", "TypedArray is not of type Uint32Array" )
503 it('BindingTestSuite: Should return new Int8Array from a c# sbyte array.', () => {
504 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
505 var _document = karmaHTML.httpspec.document;
507 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Int8ArrayFrom", []);
508 assert.equal(arr.length, 50, "result does not match length of 50.");
509 assert.equal(Object.prototype.toString.call(arr), "[object Int8Array]", "TypedArray is not of type Int8Array" )
513 it('BindingTestSuite: Should return new Int16Array from a c# short array.', () => {
514 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
515 var _document = karmaHTML.httpspec.document;
517 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Int16ArrayFrom", []);
518 assert.equal(arr.length, 50, "result does not match length of 50.");
519 assert.equal(Object.prototype.toString.call(arr), "[object Int16Array]", "TypedArray is not of type Int16Array" )
523 it('BindingTestSuite: Should return new Int32Array from a c# int array.', () => {
524 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
525 var _document = karmaHTML.httpspec.document;
527 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Int32ArrayFrom", []);
528 assert.equal(arr.length, 50, "result does not match length of 50.");
529 assert.equal(Object.prototype.toString.call(arr), "[object Int32Array]", "TypedArray is not of type Int32Array" )
533 it('BindingTestSuite: Should return new Float32Array from a c# float array.', () => {
534 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
535 var _document = karmaHTML.httpspec.document;
537 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Float32ArrayFrom", []);
538 assert.equal(arr.length, 50, "result does not match length of 50.");
539 assert.equal(Object.prototype.toString.call(arr), "[object Float32Array]", "TypedArray is not of type Float32Array" )
543 it('BindingTestSuite: Should return new Float64Array from a c# double array.', () => {
544 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
545 var _document = karmaHTML.httpspec.document;
547 var arr = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:Float64ArrayFrom", []);
548 assert.equal(arr.length, 50, "result does not match length of 50.");
549 assert.equal(Object.prototype.toString.call(arr), "[object Float64Array]", "TypedArray is not of type Float64Array" )
552 it('BindingTestSuite: Should return Int8Array type.', () => {
553 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
554 var _document = karmaHTML.httpspec.document;
556 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Int8Array()]);
557 assert.equal(type, "Int8Array", "result does not match Int8Array.");
561 it('BindingTestSuite: Should return Uint8Array type.', () => {
562 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
563 var _document = karmaHTML.httpspec.document;
565 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Uint8Array()]);
566 assert.equal(type, "Uint8Array", "result does not match Uint8Array.");
570 it('BindingTestSuite: Should return Uint8ClampedArray type.', () => {
571 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
572 var _document = karmaHTML.httpspec.document;
574 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Uint8ClampedArray()]);
575 assert.equal(type, "Uint8ClampedArray", "result does not match Uint8ClampedArray.");
579 it('BindingTestSuite: Should return Int16Array type.', () => {
580 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
581 var _document = karmaHTML.httpspec.document;
583 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Int16Array()]);
584 assert.equal(type, "Int16Array", "result does not match Int16Array.");
588 it('BindingTestSuite: Should return Uint16Array type.', () => {
589 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
590 var _document = karmaHTML.httpspec.document;
592 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Uint16Array()]);
593 assert.equal(type, "Uint16Array", "result does not match Uint16Array.");
597 it('BindingTestSuite: Should return Int32Array type.', () => {
598 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
599 var _document = karmaHTML.httpspec.document;
601 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Int32Array()]);
602 assert.equal(type, "Int32Array", "result does not match Int32Array.");
606 it('BindingTestSuite: Should return Uint32Array type.', () => {
607 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
608 var _document = karmaHTML.httpspec.document;
610 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Uint32Array()]);
611 assert.equal(type, "Uint32Array", "result does not match Uint32Array.");
615 it('BindingTestSuite: Should return Float32Array type.', () => {
616 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
617 var _document = karmaHTML.httpspec.document;
619 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Float32Array()]);
620 assert.equal(type, "Float32Array", "result does not match Float32Array.");
624 it('BindingTestSuite: Should return Float64Array type.', () => {
625 //karmaHTML.httpspec.document gives the access to the Document object of 'http-spec.html' file
626 var _document = karmaHTML.httpspec.document;
628 var type = _document.Module.BINDING.call_static_method("[BindingsTestSuite]TestSuite.Program:TypedArrayType", [new Float64Array()]);
629 assert.equal(type, "Float64Array", "result does not match Float64Array.");