SockJS

 view release on metacpan or  search on metacpan

t-vendor/html/lib/unittests.js  view on Meta::CPAN

  };
  raises(t, 'Wrong url');
  t = function() {
    return u.amendUrl(false);
  };
  raises(t, 'Wrong url');
  t = function() {
    return u.amendUrl('http://abc?a=a');
  };
  raises(t, 'Only basic urls are supported');
  t = function() {
    return u.amendUrl('http://abc#a');
  };
  return raises(t, 'Only basic urls are supported');
});

test('arrIndexOf', function() {
  var a;
  a = [1, 2, 3, 4, 5];
  equal(u.arrIndexOf(a, 1), 0);
  equal(u.arrIndexOf(a, 5), 4);
  equal(u.arrIndexOf(a, null), -1);
  return equal(u.arrIndexOf(a, 6), -1);
});

test('arrSkip', function() {
  var a;
  a = [1, 2, 3, 4, 5];
  deepEqual(u.arrSkip(a, 1), [2, 3, 4, 5]);
  deepEqual(u.arrSkip(a, 2), [1, 3, 4, 5]);
  deepEqual(u.arrSkip(a, 11), [1, 2, 3, 4, 5]);
  deepEqual(u.arrSkip(a, 'a'), [1, 2, 3, 4, 5]);
  return deepEqual(u.arrSkip(a, '1'), [1, 2, 3, 4, 5]);
});

test('quote', function() {
  var all_chars, c, i;
  equal(u.quote(''), '""');
  equal(u.quote('a'), '"a"');
  ok(u.arrIndexOf(['"\\t"', '"\\u0009"'], u.quote('\t')) !== -1);
  ok(u.arrIndexOf(['"\\n"', '"\\u000a"'], u.quote('\n')) !== -1);
  equal(u.quote('\x00\udfff\ufffe\uffff'), '"\\u0000\\udfff\\ufffe\\uffff"');
  equal(u.quote('\ud85c\udff7\ud800\ud8ff'), '"\\ud85c\\udff7\\ud800\\ud8ff"');
  equal(u.quote('\u2000\u2001\u0300\u0301'), '"\\u2000\\u2001\\u0300\\u0301"');
  c = (function() {
    var _i, _results;
    _results = [];
    for (i = _i = 0; _i <= 65535; i = ++_i) {
      _results.push(String.fromCharCode(i));
    }
    return _results;
  })();
  all_chars = c.join('');
  return ok(JSON.parse(u.quote(all_chars)) === all_chars, "Quote/unquote all 64K chars.");
});

test('detectProtocols', function() {
  var chrome_probed, ie10_probed, ie6_probed, ie8_probed, opera_probed;
  chrome_probed = {
    'websocket': true,
    'xdr-streaming': false,
    'xhr-streaming': true,
    'iframe-eventsource': true,
    'iframe-htmlfile': true,
    'xdr-polling': false,
    'xhr-polling': true,
    'iframe-xhr-polling': true,
    'jsonp-polling': true
  };
  deepEqual(u.detectProtocols(chrome_probed, null, {}), ['websocket', 'xhr-streaming', 'xhr-polling']);
  deepEqual(u.detectProtocols(chrome_probed, null, {
    websocket: false
  }), ['xhr-streaming', 'xhr-polling']);
  opera_probed = {
    'websocket': false,
    'xdr-streaming': false,
    'xhr-streaming': false,
    'iframe-eventsource': true,
    'iframe-htmlfile': true,
    'xdr-polling': false,
    'xhr-polling': false,
    'iframe-xhr-polling': true,
    'jsonp-polling': true
  };
  deepEqual(u.detectProtocols(opera_probed, null, {}), ['iframe-eventsource', 'iframe-xhr-polling']);
  ie6_probed = {
    'websocket': false,
    'xdr-streaming': false,
    'xhr-streaming': false,
    'iframe-eventsource': false,
    'iframe-htmlfile': false,
    'xdr-polling': false,
    'xhr-polling': false,
    'iframe-xhr-polling': false,
    'jsonp-polling': true
  };
  deepEqual(u.detectProtocols(ie6_probed, null, {}), ['jsonp-polling']);
  ie8_probed = {
    'websocket': false,
    'xdr-streaming': true,
    'xhr-streaming': false,
    'iframe-eventsource': false,
    'iframe-htmlfile': true,
    'xdr-polling': true,
    'xhr-polling': false,
    'iframe-xhr-polling': true,
    'jsonp-polling': true
  };
  deepEqual(u.detectProtocols(ie8_probed, null, {}), ['xdr-streaming', 'xdr-polling']);
  deepEqual(u.detectProtocols(ie8_probed, null, {
    cookie_needed: true
  }), ['iframe-htmlfile', 'iframe-xhr-polling']);
  ie10_probed = {
    'websocket': true,
    'xdr-streaming': true,
    'xhr-streaming': true,
    'iframe-eventsource': false,
    'iframe-htmlfile': true,
    'xdr-polling': true,
    'xhr-polling': true,
    'iframe-xhr-polling': true,
    'jsonp-polling': true
  };
  deepEqual(u.detectProtocols(ie10_probed, null, {}), ['websocket', 'xhr-streaming', 'xhr-polling']);
  deepEqual(u.detectProtocols(ie10_probed, null, {
    cookie_needed: true
  }), ['websocket', 'xhr-streaming', 'xhr-polling']);
  deepEqual(u.detectProtocols(chrome_probed, null, {
    null_origin: true
  }), ['websocket', 'iframe-eventsource', 'iframe-xhr-polling']);
  deepEqual(u.detectProtocols(chrome_probed, null, {
    websocket: false,
    null_origin: true
  }), ['iframe-eventsource', 'iframe-xhr-polling']);
  deepEqual(u.detectProtocols(opera_probed, null, {
    null_origin: true
  }), ['iframe-eventsource', 'iframe-xhr-polling']);
  deepEqual(u.detectProtocols(ie6_probed, null, {
    null_origin: true
  }), ['jsonp-polling']);
  deepEqual(u.detectProtocols(ie8_probed, null, {
    null_origin: true
  }), ['iframe-htmlfile', 'iframe-xhr-polling']);
  return deepEqual(u.detectProtocols(ie10_probed, null, {
    null_origin: true
  }), ['websocket', 'iframe-htmlfile', 'iframe-xhr-polling']);
});

test("EventEmitter", function() {
  var bluff, r, single;
  expect(4);
  r = new SockJS('//1.2.3.4/wrongurl', null, {
    protocols_whitelist: []
  });
  r.addEventListener('message', function() {
    return ok(true);
  });
  r.onmessage = function() {
    return ok(false);
  };
  bluff = function() {
    return ok(false);
  };
  r.addEventListener('message', bluff);
  r.removeEventListener('message', bluff);
  r.addEventListener('message', bluff);
  r.addEventListener('message', function() {
    return ok(true);
  });
  r.onmessage = function() {
    return ok(true);
  };
  r.removeEventListener('message', bluff);
  r.dispatchEvent({
    type: 'message'
  });
  single = function() {
    return ok(true);
  };
  r.addEventListener('close', single);
  r.addEventListener('close', single);
  r.dispatchEvent({
    type: 'close'
  });
  r.removeEventListener('close', single);
  r.dispatchEvent({
    type: 'close'



( run in 3.408 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )