[Pkg-javascript-commits] [sockjs-client] 146/350: All echo tests

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit c311395278ceb1f8014e208c460a7cecae61726d
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Wed Oct 15 18:04:17 2014 -0400

    All echo tests
---
 tests/html/lib/alltests.js      |   4 -
 tests/html/lib/domtests.js      | 207 ----------------------------------------
 tests/html/lib/endtoendtests.js | 108 ---------------------
 tests/html/lib/tests.js         | 170 ---------------------------------
 tests/lib/echo-tests.js         | 125 ++++++++++++++++++++++++
 tests/lib/transports.js         |  53 ++--------
 6 files changed, 134 insertions(+), 533 deletions(-)

diff --git a/tests/html/lib/alltests.js b/tests/html/lib/alltests.js
deleted file mode 100644
index 20042fb..0000000
--- a/tests/html/lib/alltests.js
+++ /dev/null
@@ -1,4 +0,0 @@
-'use strict';
-require('./domtests');
-require('./endtoendtests');
-require('./tests');
\ No newline at end of file
diff --git a/tests/html/lib/domtests.js b/tests/html/lib/domtests.js
deleted file mode 100644
index adaf451..0000000
--- a/tests/html/lib/domtests.js
+++ /dev/null
@@ -1,207 +0,0 @@
-'use strict';
-/* global suite, test */
-/* jshint multistr: true */
-var ajax_simple_factory, ajax_streaming_factory, ajax_wrong_port_factory, onunload_test_factory, test_wrong_url;
-
-suite('DOM');
-
-var assert = require('assert');
-var u = require('../../../lib/utils');
-var testutils = require('./testutils');
-
-onunload_test_factory = function(code, done) {
-  var hook;
-  //expect(3);
-  hook = testutils.newIframe();
-  hook.open = function() {
-    assert.ok(true, 'open hook called by an iframe');
-    return hook.callback(code);
-  };
-  hook.load = function() {
-    var f;
-    assert.ok(true, 'onload hook called by an iframe');
-    f = function() {
-      return hook.iobj.cleanup();
-    };
-    return setTimeout(f, 1);
-  };
-  hook.unload = function() {
-    assert.ok(true, 'onunload hook called by an iframe');
-    hook.del();
-    done();
-  };
-};
-
-if (navigator.userAgent.indexOf('Konqueror') !== -1 || navigator.userAgent.indexOf('Opera') !== -1) {
-  test("onunload [unsupported by client]", function() {
-    assert.ok(true);
-  });
-} else {
-  test('onunload', function (done) {
-    this.timeout(5000);
-    this.runnable().globals(['_sockjs_global']);
-    onunload_test_factory("\
-      function attachEvent(event, listener) {\n\
-          if (typeof window.addEventListener !== 'undefined') {\n\
-              window.addEventListener(event, listener, false);\n\
-          } else {\n\
-              document.attachEvent('on' + event, listener);\n\
-              window.attachEvent('on' + event, listener);\n\
-          }\n\
-      }\n\
-      attachEvent('load', function(){\n\
-          hook.load();\n\
-      });\n\
-      var w = 0;\n\
-      var run = function(){\n\
-          if(w === 0) {\n\
-              w = 1;\n\
-              hook.unload();\n\
-          }\n\
-      };\n\
-      attachEvent('beforeunload', run);\n\
-      attachEvent('unload', run);", done);
-  });
-}
-
-if (!require('../../../lib/transport/lib/iframe').enabled()) {
-  test("onmessage [unsupported by client]", function() {
-    assert.ok(true);
-  });
-} else {
-  test('onmessage', function(done) {
-    this.runnable().globals(['_sockjs_global']);
-    var hook;
-    //expect(3);
-    hook = testutils.newIframe();
-    hook.open = function() {
-      assert.ok(true, 'open hook called by an iframe');
-      hook.callback("\
-        function attachEvent(event, listener) {\n\
-            if (typeof window.addEventListener !== 'undefined') {\n\
-                window.addEventListener(event, listener, false);\n\
-            } else {\n\
-                document.attachEvent('on' + event, listener);\n\
-                window.attachEvent('on' + event, listener);\n\
-            }\n\
-        }\n\
-        attachEvent('message', function(e) {\n\
-            var b = e.data;\n\
-            parent.postMessage(window_id + ' ' + 'e', '*');\n\
-        });\n\
-        parent.postMessage(window_id + ' ' + 's', '*');");
-    };
-    u.attachMessage(function(e) {
-      var _ref = e.data.split(' ')
-        , window_id = _ref[0]
-        , data = _ref[1]
-        , origin
-        ;
-      if (window_id === hook.id) {
-        switch (data) {
-          case 's':
-            hook.iobj.loaded();
-            assert.ok(true, 'start frame send');
-            origin = u.getOrigin(u.amendUrl('/'));
-            hook.iobj.post(hook.id + ' ' + 's', origin);
-            break;
-          case 'e':
-            assert.ok(true, 'done hook called by an iframe');
-            hook.iobj.cleanup();
-            hook.del();
-            done();
-            break;
-        }
-      }
-    });
-  });
-}
-
-ajax_simple_factory = function(name, Obj) {
-  test(name + ' simple', function(done) {
-    this.runnable().globals(['_sockjs_global']);
-    var x;
-    //expect(2);
-    x = new Obj('GET', '/simple.txt', null);
-    x.on('finish', function(status, text) {
-      assert.equal(text.length, 2051);
-      assert.equal(text.slice(-2), 'b\n');
-      done();
-    });
-  });
-};
-
-ajax_streaming_factory = function(name, Obj) {
-  test(name + ' streaming', function(done) {
-    this.runnable().globals(['_sockjs_global']);
-    var x;
-    //expect(4);
-    x = new Obj('GET', '/streaming.txt', null);
-    x.on('chunk', function(status, text) {
-      assert.equal(status, 200);
-      assert.ok(text.length <= 2049, 'Most likely you\'re behind a transparent Proxy that can\'t do streaming. QUnit tests won\'t work properly. Sorry!');
-      x.removeAllListeners('chunk');
-    });
-    x.on('finish', function(status, text) {
-      assert.equal(status, 200);
-      assert.equal(text.slice(-4), 'a\nb\n');
-      done();
-    });
-  });
-};
-
-test_wrong_url = function(name, Obj, url, statuses, done) {
-  var x;
-  if (window.console && console.log) {
-    console.log(' [*] Connecting to wrong url ' + url);
-  }
-  //expect(2);
-  x = new Obj('GET', url, null);
-  x.on('chunk', function() {
-    assert.ok(false, "chunk shall not be received");
-  });
-  x.on('finish', function(status, text) {
-    assert.ok(u.arrIndexOf(statuses, status) !== -1);
-    assert.equal(text, '');
-    done();
-  });
-};
-
-ajax_wrong_port_factory = function(name, Obj) {
-  var port, _i, _len, _ref;
-  _ref = [25, 8999, 65300];
-  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-    port = _ref[_i];
-    test(name + ' wrong port ' + port, function(done) {
-      this.runnable().globals(['_sockjs_global']);
-      test_wrong_url(name, Obj, 'http://localhost:' + port + '/wrong_url_indeed.txt', [0], done);
-    });
-  }
-};
-
-var XHRLocalObject = require('../../../lib/xhr-local');
-var XDRObject = require('../../../lib/xdr');
-
-ajax_simple_factory('XHRLocalObject', XHRLocalObject);
-
-if (window.XDomainRequest) ajax_simple_factory('XDRObject', XDRObject);
-
-if (!window.ActiveXObject) ajax_streaming_factory('XHRLocalObject', XHRLocalObject);
-
-if (window.XDomainRequest) ajax_streaming_factory('XDRObject', XDRObject);
-
-ajax_wrong_port_factory('XHRLocalObject', XHRLocalObject);
-
-if (window.XDomainRequest) ajax_wrong_port_factory('XDRObject', XDRObject);
-
-test('XHRLocalObject wrong url', function(done) {
-  this.runnable().globals(['_sockjs_global']);
-  test_wrong_url('XHRLocalObject', XHRLocalObject, '/wrong_url_indeed.txt', [0, 404], done);
-});
-
-if (window.XDomainRequest) {
-  test('XDRObject wrong url', function(done) {
-    this.runnable().globals(['_sockjs_global']);
-    test_wrong_url('XDRObject', XDRObject, '/wrong_url_indeed.txt', [0], done);
-  });
-}
diff --git a/tests/html/lib/endtoendtests.js b/tests/html/lib/endtoendtests.js
deleted file mode 100644
index af1eccd..0000000
--- a/tests/html/lib/endtoendtests.js
+++ /dev/null
@@ -1,108 +0,0 @@
-'use strict';
-/* global test, suite */
-
-var assert = require('assert');
-var u = require('../../../lib/utils');
-var testutils = require('./testutils');
-
-var TIMEOUT_MS = 10000;
-
-suite('End to End');
-
-suite('Connection Errors');
-
-test("invalid url 404", function(done) {
-  this.timeout(TIMEOUT_MS);
-  this.runnable().globals(['_sockjs_global']);
-  var r;
-  //expect(4);
-  r = testutils.newSockJS('/invalid_url', 'jsonp-polling');
-  assert.ok(r);
-  r.onopen = function(e) {
-    assert.ok(false);
-  };
-  r.onmessage = function(e) {
-    assert.ok(false);
-  };
-  r.onclose = function(e) {
-    if (u.isXHRCorsCapable() < 4) {
-      assert.equal(e.code, 1002);
-      assert.equal(e.reason, 'Can\'t connect to server');
-    } else {
-      assert.equal(e.code, 2000);
-      assert.equal(e.reason, 'All transports failed');
-    }
-    assert.equal(e.wasClean, false);
-    done();
-  };
-});
-
-test("invalid url port", function(done) {
-  this.timeout(TIMEOUT_MS);
-  this.runnable().globals(['_sockjs_global']);
-  var dl, r;
-  //expect(4);
-  dl = document.location;
-  r = testutils.newSockJS(dl.protocol + '//' + dl.hostname + ':1079', 'jsonp-polling');
-  assert.ok(r);
-  r.onopen = function(e) {
-    assert.ok(false);
-  };
-  r.onclose = function(e) {
-    if (u.isXHRCorsCapable() < 4) {
-      assert.equal(e.code, 1002);
-      assert.equal(e.reason, 'Can\'t connect to server');
-    } else {
-      assert.equal(e.code, 2000);
-      assert.equal(e.reason, 'All transports failed');
-    }
-    assert.equal(e.wasClean, false);
-    done();
-  };
-});
-
-test("disabled websocket test", function(done) {
-  this.timeout(TIMEOUT_MS);
-  this.runnable().globals(['_sockjs_global']);
-  var r;
-  //expect(3);
-  r = testutils.newSockJS('/disabled_websocket_echo', 'websocket');
-  r.onopen = function(e) {
-    assert.ok(false);
-  };
-  r.onmessage = function(e) {
-    assert.ok(false);
-  };
-  r.onclose = function(e) {
-    assert.equal(e.code, 2000);
-    assert.equal(e.reason, "All transports failed");
-    assert.equal(e.wasClean, false);
-    done();
-  };
-});
-
-test("close on close", function(done) {
-  this.timeout(TIMEOUT_MS);
-  this.runnable().globals(['_sockjs_global', '_jp']);
-  var r;
-  //expect(4);
-  r = testutils.newSockJS('/close', 'jsonp-polling');
-  r.onopen = function(e) {
-    assert.ok(true);
-  };
-  r.onmessage = function(e) {
-    assert.ok(false);
-  };
-  r.onclose = function(e) {
-    assert.equal(e.code, 3000);
-    assert.equal(e.reason, "Go away!");
-    assert.equal(e.wasClean, true);
-    r.onclose = function() {
-      assert.ok(false);
-    };
-    r.close();
-    setTimeout(function() {
-      done();
-    }, 10);
-  };
-});
diff --git a/tests/html/lib/tests.js b/tests/html/lib/tests.js
index 8492667..8a5eae9 100644
--- a/tests/html/lib/tests.js
+++ b/tests/html/lib/tests.js
@@ -9,130 +9,6 @@ var protocols = require('../../../lib/protocols');
 
 var TIMEOUT_MS = 10000;
 
-echo_factory_factory = function(protocol, messages) {
-  return function(done) {
-    this.timeout(TIMEOUT_MS);
-    this.runnable().globals(['_sockjs_global', '_jp', '_send_form', '_send_area']);
-    var a, r;
-    //expect(2 + messages.length);
-    a = messages.slice(0);
-    r = testutils.newSockJS('/echo', protocol);
-    r.onopen = function(e) {
-      assert.ok(true);
-      r.send(a[0]);
-    };
-    r.onmessage = function(e) {
-      var i, x, xx1, xx2, _ref;
-      x = '' + a[0];
-      if (e.data !== x) {
-        for (i = 0, _ref = e.data.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
-          if (e.data.charCodeAt(i) !== x.charCodeAt(i)) {
-            xx1 = ('0000' + x.charCodeAt(i).toString(16)).slice(-4);
-            xx2 = ('0000' + e.data.charCodeAt(i).toString(16)).slice(-4);
-            u.log('source: \\u' + xx1 + ' differs from: \\u' + xx2);
-            break;
-          }
-        }
-      }
-      assert.equal(e.data, '' + a[0]);
-      a.shift();
-      if (typeof a[0] === 'undefined') {
-        r.close();
-      } else {
-        r.send(a[0]);
-      }
-    };
-    r.onclose = function(e) {
-      if (a.length) {
-        assert.ok(false, "Transport closed prematurely. " + e);
-      } else {
-        assert.ok(true);
-      }
-      done();
-    };
-  };
-};
-
-factor_echo_basic = function(protocol) {
-  var messages;
-  messages = ['data'];
-  return echo_factory_factory(protocol, messages);
-};
-
-factor_echo_rich = function(protocol) {
-  var messages;
-  messages = [
-    [1, 2, 3, 'data'], null, false, "data", 1, 12.0, {
-      a: 1,
-      b: 2
-    }
-  ];
-  return echo_factory_factory(protocol, messages);
-};
-
-factor_echo_from_child = function(protocol) {
-  return function(done) {
-    this.timeout(TIMEOUT_MS);
-    this.runnable().globals(['_sockjs_global', '_jp', '_send_form', '_send_area']);
-    var code, hook, hookReady, r, sockJSReady, timeout;
-    timeout = void 0;
-    hookReady = false;
-    sockJSReady = false;
-    //expect(4);
-    hook = testutils.newIframe("sockjs-in-parent.html");
-    r = testutils.newSockJS("/echo", protocol);
-    code = "hook.r.send('a'); hook.onsend();";
-    hook.open = function() {
-      hook.iobj.loaded();
-      assert.ok(true, "iframe open");
-      hookReady = true;
-      hook.r = r;
-      sockJSReady && hook.callback(code);
-    };
-    r.onopen = function(e) {
-      hook.iobj.loaded();
-      assert.ok(true, "sockjs open");
-      sockJSReady = true;
-      hookReady && hook.callback(code);
-    };
-    r.onmessage = function(e) {
-      clearTimeout(timeout);
-      assert.equal(e.data, "a");
-      assert.ok(true, "onmessage");
-      hook.iobj.cleanup();
-      hook.del();
-      r.close();
-    };
-    hook.onsend = function(e) {
-      timeout = setTimeout(function() {
-        assert.ok(false);
-        r.close();
-      }, 300);
-    };
-    r.onclose = function() {
-      done();
-    };
-  };
-};
-
-factor_echo_unicode = function(protocol) {
-  var messages;
-  messages = ["Τη γλώσσα μου έδωσαν ελληνική το σπίτι φτωχικό στις αμμουδιές του ", "ღმერთსი შემვედრე, ნუთუ კვლა დამხსნას სოფლისა შრომასა, ცეცხლს, წყალს", "⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", "Би шил идэй чадна, надад хортой биш", "을", "나는 유리를 먹을 수 있어요. 그래도 아프지 않아요", "ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ", "Ég get etið gler án þess að meiða mig.", "Mogę jeść szkło, i mi nie szkodzi.", "\ufffd\u10102\u2f877", "Начало музыкальной карьеры\nБритни пела [...]
-  return echo_factory_factory(protocol, messages);
-};
-
-factor_echo_special_chars = function(protocol) {
-  var messages;
-  messages = [" ", "\u0000", "\xff", "\xff\x00", "\x00\xff", " \r ", " \n ", " \r\n ", "\r\n", "", "message\t", "\tmessage", "message ", " message", "message\r", "\rmessage", "message\n", "\nmessage", "message\xff", "\xffmessage", "A", "b", "c", "d", "e", "\ufffd", "\ufffd\u0000", "message\ufffd", "\ufffdmessage"];
-  return echo_factory_factory(protocol, messages);
-};
-
-factor_echo_large_message = function(protocol) {
-  var messages;
-  messages = [new Array(Math.pow(2, 1)).join('x'), new Array(Math.pow(2, 2)).join('x'), new Array(Math.pow(2, 4)).join('x'), new Array(Math.pow(2, 8)).join('x'), new Array(Math.pow(2, 13)).join('x'), new Array(Math.pow(2, 13)).join('x')];
-  return echo_factory_factory(protocol, messages);
-};
-
 batch_factory_factory = function(protocol, messages) {
   return function(done) {
     this.timeout(TIMEOUT_MS);
@@ -211,45 +87,7 @@ factor_batch_large_amp = function(protocol) {
   return batch_factory_factory_amp(protocol, messages);
 };
 
-escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u2000-\u20ff\ufeff\ufff0-\uffff\x00-\x1f\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0 [...]
 
-generate_killer_string = function(escapable) {
-  var c, i, s;
-  s = [];
-  c = (function() {
-    var _results;
-    _results = [];
-    for (i = 0; i <= 65535; i++) {
-      _results.push(String.fromCharCode(i));
-    }
-    return _results;
-  })();
-  escapable.lastIndex = 0;
-  c.join('').replace(escapable, function(a) {
-    s.push(a);
-    return '';
-  });
-  return s.join('');
-};
-
-factor_echo_utf_encoding_simple = function(protocol) {
-  var i, message;
-  message = (function() {
-    var _results;
-    _results = [];
-    for (i = 0; i <= 256; i++) {
-      _results.push(String.fromCharCode(i));
-    }
-    return _results;
-  })();
-  return echo_factory_factory(protocol, [message.join('')]);
-};
-
-factor_echo_utf_encoding = function(protocol) {
-  var message;
-  message = generate_killer_string(escapable);
-  return echo_factory_factory(protocol, [message]);
-};
 
 factor_user_close = function(protocol) {
   return function(done) {
@@ -301,14 +139,6 @@ factor_server_close = function(protocol) {
   };
 };
 
-arrIndexOf = function(arr, obj) {
-  var i, _ref;
-  for (i = 0, _ref = arr.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
-    if (arr[i] === obj) return i;
-  }
-  return -1;
-};
-
 test_protocol_messages = function(protocol) {
   suite(protocol);
   if (client_opts.disabled_transports && arrIndexOf(client_opts.disabled_transports, protocol) !== -1) {
diff --git a/tests/lib/echo-tests.js b/tests/lib/echo-tests.js
new file mode 100644
index 0000000..41e4c58
--- /dev/null
+++ b/tests/lib/echo-tests.js
@@ -0,0 +1,125 @@
+'use strict';
+var expect = require('expect.js')
+  , testUtils = require('./test-utils')
+  ;
+
+
+module.exports.echoFactory = function echoFactory(transport, messages) {
+  return function (done) {
+    this.timeout(10000);
+    var msgs = messages.slice(0);
+
+    var sjs = testUtils.newSockJs('/echo', transport);
+    sjs.onopen = function () {
+      sjs.send(msgs[0]);
+    };
+    sjs.onmessage = function (e) {
+      // TODO don't like having to force the element toString here
+      expect(e.data).to.eql('' + msgs[0]);
+      msgs.shift();
+      if (typeof msgs[0] === 'undefined') {
+        sjs.close();
+      } else {
+        sjs.send(msgs[0]);
+      }
+    };
+    sjs.onclose = function (e) {
+      expect(e.code).to.equal(1000);
+      expect(msgs).to.have.length(0);
+      done();
+    };
+  };
+};
+
+module.exports.echoBasic = function echoBasic(transport) {
+  var messages = ['data'];
+  it('echo basic', module.exports.echoFactory(transport, messages));
+};
+
+module.exports.echoRich = function echoRich(transport) {
+  var messages = [
+    [1, 2, 3, 'data'], null, false, 'data', 1, 12.0, {
+      a: 1,
+      b: 2
+    }
+  ];
+  it('echo rich', module.exports.echoFactory(transport, messages));
+};
+
+module.exports.echoUnicode = function echoUnicode(transport) {
+  var messages = ["Τη γλώσσα μου έδωσαν ελληνική το σπίτι φτωχικό στις αμμουδιές του ", "ღმერთსი შემვედრე, ნუთუ კვლა დამხსნას სოფლისა შრომასა, ცეცხლს, წყალს", "⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", "Би шил идэй чадна, надад хортой биш", "을", "나는 유리를 먹을 수 있어요. 그래도 아프지 않아요", "ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ", "Ég get etið gler án þess að meiða mig.", "Mogę jeść szkło, i mi nie szkodzi.", "\ufffd\u10102\u2f877", "Начало музыкальной карьеры\nБритни  [...]
+  it('unicode', module.exports.echoFactory(transport, messages));
+};
+
+module.exports.echoSpecialChars = function echoSpecialChars(transport) {
+  var messages = [" ", "\u0000", "\xff", "\xff\x00", "\x00\xff", " \r ", " \n ", " \r\n ", "\r\n", "", "message\t", "\tmessage", "message ", " message", "message\r", "\rmessage", "message\n", "\nmessage", "message\xff", "\xffmessage", "A", "b", "c", "d", "e", "\ufffd", "\ufffd\u0000", "message\ufffd", "\ufffdmessage"];
+  it('special chars', module.exports.echoFactory(transport, messages));
+};
+
+module.exports.echoLargeMessage = function echoLargeMessage(transport) {
+  var messages = [new Array(Math.pow(2, 1)).join('x'), new Array(Math.pow(2, 2)).join('x'), new Array(Math.pow(2, 4)).join('x'), new Array(Math.pow(2, 8)).join('x'), new Array(Math.pow(2, 13)).join('x'), new Array(Math.pow(2, 13)).join('x')];
+  it('large message (ping-pong)', module.exports.echoFactory(transport, messages));
+};
+
+module.exports.echoUtfEncodingSimple = function echoUtfEncodingSimple(transport) {
+  var chars = [];
+  for (var i = 0; i <= 256; i++) {
+    chars.push(String.fromCharCode(i));
+  }
+  it('echo utf encoding 0x00-0xFF', module.exports.echoFactory(transport, [chars.join('')] ));
+};
+
+var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u2000-\u20ff\ufeff\ufff0-\uffff\x00-\x1f\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5 [...]
+module.exports.echoUtfEncoding = function echoUtfEncoding(transport) {
+  var chars = [], message = [];
+  for (var i = 0; i <= 65536; i++) {
+    chars.push(String.fromCharCode(i));
+  }
+  escapable.lastIndex = 0;
+  chars.join('').replace(escapable, function (a) {
+    message.push(a);
+    return '';
+  });
+  it('echo utf encoding killer message', module.exports.echoFactory(transport, [message.join('')] ));
+};
+
+module.exports.echoFromChild = function echoFromChild(transport) {
+  it('echo from child', function (done) {
+    var hook = testUtils.createIframe('/sockjs-in-parent.html');
+    var sjs = testUtils.newSockJs('/echo', transport);
+    var code = 'hook.sjs.send("a"); hook.onsend();';
+    var hookReady, sockJsReady, timeout, i = 0;
+
+    hook.open = function() {
+      hook.iobj.loaded();
+      i++;
+      hookReady = true;
+      hook.sjs = sjs;
+      sockJsReady && hook.callback(code);
+    };
+    hook.onsend = function () {
+      timeout = setTimeout(function() {
+        expect().fail();
+        sjs.close();
+      }, 300);
+    };
+
+    sjs.onopen = function() {
+      hook.iobj.loaded();
+      i++;
+      sockJsReady = true;
+      hookReady && hook.callback(code);
+    };
+    sjs.onmessage = function(e) {
+      clearTimeout(timeout);
+      expect(e.data).to.equal('a');
+      expect(i).to.equal(2);
+      hook.iobj.cleanup();
+      hook.del();
+      sjs.close();
+    };
+    sjs.onclose = function() {
+      done();
+    };
+  });
+};
diff --git a/tests/lib/transports.js b/tests/lib/transports.js
index 656c13e..63b3b06 100644
--- a/tests/lib/transports.js
+++ b/tests/lib/transports.js
@@ -4,50 +4,9 @@
 var expect = require('expect.js')
   , transportList = require('../../lib/transport-list')
   , testUtils = require('./test-utils')
+  , echoTests = require('./echo-tests')
   ;
 
-function echoFactory(transport, messages) {
-  return function (done) {
-    this.timeout(10000);
-    var msgs = messages.slice(0);
-
-    var sjs = testUtils.newSockJs('/echo', transport);
-    sjs.onopen = function () {
-      sjs.send(msgs[0]);
-    };
-    sjs.onmessage = function (e) {
-      // TODO don't like having to force the element toString here
-      expect(e.data).to.eql('' + msgs[0]);
-      msgs.shift();
-      if (typeof msgs[0] === 'undefined') {
-        sjs.close();
-      } else {
-        sjs.send(msgs[0]);
-      }
-    };
-    sjs.onclose = function (e) {
-      expect(e.code).to.equal(1000);
-      expect(msgs).to.have.length(0);
-      done();
-    };
-  };
-}
-
-function echoBasic(transport) {
-  var messages = ['data'];
-  it('echo basic', echoFactory(transport, messages));
-}
-
-function echoRich(transport) {
-  var messages = [
-    [1, 2, 3, 'data'], null, false, 'data', 1, 12.0, {
-      a: 1,
-      b: 2
-    }
-  ];
-  it('echo rich', echoFactory(transport, messages));
-}
-
 describe('Transports', function () {
   transportList.forEach(function (Trans) {
     describe(Trans.transportName, function () {
@@ -78,8 +37,14 @@ describe('Transports', function () {
         return;
       }
 
-      echoBasic(Trans.transportName);
-      echoRich(Trans.transportName);
+      echoTests.echoBasic(Trans.transportName);
+      echoTests.echoRich(Trans.transportName);
+      echoTests.echoUnicode(Trans.transportName);
+      echoTests.echoSpecialChars(Trans.transportName);
+      echoTests.echoLargeMessage(Trans.transportName);
+      echoTests.echoUtfEncodingSimple(Trans.transportName);
+      echoTests.echoUtfEncoding(Trans.transportName);
+      echoTests.echoFromChild(Trans.transportName);
     });
   });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list