[Pkg-javascript-commits] [sockjs-client] 225/350: Setup for cross-origin tests
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:04:24 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 8cff1287067b085cd673a438ee0bc8d344a319c7
Author: Bryce Kahle <bkahle at gmail.com>
Date: Thu Oct 23 14:19:42 2014 -0400
Setup for cross-origin tests
---
.zuul.yml | 1 +
lib/main.js | 4 ++--
tests/lib/batch-tests.js | 23 +++++++++++++--------
tests/lib/echo-tests.js | 38 +++++++++++++++++------------------
tests/lib/test-utils.js | 11 ++++++++--
tests/lib/transports.js | 52 +++++++++++++++++++++++++++++++-----------------
6 files changed, 80 insertions(+), 49 deletions(-)
diff --git a/.zuul.yml b/.zuul.yml
index 485fa1c..4632b74 100644
--- a/.zuul.yml
+++ b/.zuul.yml
@@ -1,5 +1,6 @@
ui: mocha-bdd
scripts:
+ - "config.js"
- "domain.js"
server: ./tests/support/sockjs_server.js
tunnel_provider: ngrok
diff --git a/lib/main.js b/lib/main.js
index f1aeb0c..1d7184e 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -178,7 +178,7 @@ SockJS.prototype._receiveInfo = function(info, rtt) {
// allow server to override url used for the actual transport
this._transUrl = info.base_url ? info.base_url : this.url;
info = objectUtils.extend(info, this._urlInfo);
- debug('info: ', info);
+ debug('info', info);
// determine list of desired and supported transports
var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);
this._transports = enabledTransports.main;
@@ -205,7 +205,7 @@ SockJS.prototype._connect = function() {
// calculate timeout based on RTO and round trips. Default to 5s
var timeoutMs = (this._rto * Transport.roundTrips) || 5000;
this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
- debug('using timeout ', timeoutMs);
+ debug('using timeout', timeoutMs);
var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + random.string(8));
debug('transport url: %s', transportUrl);
diff --git a/tests/lib/batch-tests.js b/tests/lib/batch-tests.js
index 66ce6f3..dd03420 100644
--- a/tests/lib/batch-tests.js
+++ b/tests/lib/batch-tests.js
@@ -1,12 +1,15 @@
'use strict';
var expect = require('expect.js')
, testUtils = require('./test-utils')
+ , debug = require('debug')('sockjs-client:tests:batch')
;
-function batchFactory(transport, messages) {
+function batchFactory(transport, messages, url) {
return function(done) {
+ var title = this.runnable().fullTitle();
+ debug('start', title);
this.timeout(10000);
- var sjs = testUtils.newSockJs('/echo', transport);
+ var sjs = testUtils.newSockJs(url + '/echo', transport);
var counter = 0;
sjs.onopen = function () {
messages.forEach(function (m) {
@@ -24,19 +27,22 @@ function batchFactory(transport, messages) {
expect(e.code).to.equal(1000);
expect(counter).to.equal(messages.length);
done();
+ debug('end', title);
};
};
}
-module.exports.largeMessage = function(transport) {
+module.exports.largeMessage = function(url, 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 (batch)', batchFactory(transport, messages));
+ it('large message (batch)', batchFactory(transport, messages, url));
};
-function amplifyFactory(transport, messages) {
+function amplifyFactory(transport, messages, url) {
return function(done) {
+ var title = this.runnable().fullTitle();
+ debug('start', title);
this.timeout(10000);
- var sjs = testUtils.newSockJs('/amplify', transport);
+ var sjs = testUtils.newSockJs(url + '/amplify', transport);
var counter = 0;
sjs.onopen = function () {
messages.forEach(function (m) {
@@ -54,11 +60,12 @@ function amplifyFactory(transport, messages) {
expect(e.code).to.equal(1000);
expect(counter).to.equal(messages.length);
done();
+ debug('end', title);
};
};
}
-module.exports.largeDownload = function(transport) {
+module.exports.largeDownload = function(url, transport) {
var messages = [1, 2, 4, 8, 13, 15, 15];
- it('large download', amplifyFactory(transport, messages));
+ it('large download', amplifyFactory(transport, messages, url));
};
diff --git a/tests/lib/echo-tests.js b/tests/lib/echo-tests.js
index 1b2feae..500f503 100644
--- a/tests/lib/echo-tests.js
+++ b/tests/lib/echo-tests.js
@@ -12,7 +12,7 @@ function echoFactory(transport, messages, url) {
this.timeout(20000);
var msgs = messages.slice(0);
- var sjs = testUtils.newSockJs(url || '/echo', transport);
+ var sjs = testUtils.newSockJs(url, transport);
sjs.onopen = function () {
sjs.send(msgs[0]);
};
@@ -35,51 +35,51 @@ function echoFactory(transport, messages, url) {
};
}
-module.exports.echoBasic = function echoBasic(transport) {
+module.exports.echoBasic = function echoBasic(url, transport) {
var messages = ['data'];
- it('echo basic', echoFactory(transport, messages));
+ it('echo basic', echoFactory(transport, messages, url + '/echo'));
};
-module.exports.echoQueryString = function echoBasic(transport) {
+module.exports.echoQueryString = function echoBasic(url, transport) {
var messages = ['data'];
- it('echo querystring', echoFactory(transport, messages, '/echo?testqs=1'));
+ it('echo querystring', echoFactory(transport, messages, url + '/echo?testqs=1'));
};
-module.exports.echoRich = function echoRich(transport) {
+module.exports.echoRich = function echoRich(url, transport) {
var messages = [
[1, 2, 3, 'data'], null, false, 'data', 1, 12.0, {
a: 1,
b: 2
}
];
- it('echo rich', echoFactory(transport, messages));
+ it('echo rich', echoFactory(transport, messages, url + '/echo'));
};
-module.exports.echoUnicode = function echoUnicode(transport) {
+module.exports.echoUnicode = function echoUnicode(url, 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', echoFactory(transport, messages));
+ it('unicode', echoFactory(transport, messages, url + '/echo'));
};
-module.exports.echoSpecialChars = function echoSpecialChars(transport) {
+module.exports.echoSpecialChars = function echoSpecialChars(url, 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', echoFactory(transport, messages));
+ it('special chars', echoFactory(transport, messages, url + '/echo'));
};
-module.exports.echoLargeMessage = function echoLargeMessage(transport) {
+module.exports.echoLargeMessage = function echoLargeMessage(url, 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)', echoFactory(transport, messages));
+ it('large message (ping-pong)', echoFactory(transport, messages, url + '/echo'));
};
-module.exports.echoUtfEncodingSimple = function echoUtfEncodingSimple(transport) {
+module.exports.echoUtfEncodingSimple = function echoUtfEncodingSimple(url, transport) {
var chars = [];
for (var i = 0; i <= 256; i++) {
chars.push(String.fromCharCode(i));
}
- it('echo utf encoding 0x00-0xFF', echoFactory(transport, [chars.join('')] ));
+ it('echo utf encoding 0x00-0xFF', echoFactory(transport, [chars.join('')], url + '/echo'));
};
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) {
+module.exports.echoUtfEncoding = function echoUtfEncoding(url, transport) {
var chars = [], message = [];
for (var i = 0; i <= 65536; i++) {
chars.push(String.fromCharCode(i));
@@ -89,10 +89,10 @@ module.exports.echoUtfEncoding = function echoUtfEncoding(transport) {
message.push(a);
return '';
});
- it('echo utf encoding killer message', echoFactory(transport, [message.join('')] ));
+ it('echo utf encoding killer message', echoFactory(transport, [message.join('')], url + '/echo'));
};
-module.exports.echoFromChild = function echoFromChild(transport) {
+module.exports.echoFromChild = function echoFromChild(url, transport) {
it('echo from child', function (done) {
if (!iframeUtils.iframeEnabled) {
done();
@@ -103,7 +103,7 @@ module.exports.echoFromChild = function echoFromChild(transport) {
var title = this.runnable().fullTitle();
debug('start', title);
var hook = testUtils.createIframe('/sockjs-in-parent.html');
- var sjs = testUtils.newSockJs('/echo', transport);
+ var sjs = testUtils.newSockJs(url + '/echo', transport);
var code = 'hook.sjs.send("a"); hook.onsend();';
var hookReady, sockJsReady, timeout, i = 0;
diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js
index d9ddc1b..e768f7b 100644
--- a/tests/lib/test-utils.js
+++ b/tests/lib/test-utils.js
@@ -9,15 +9,22 @@ var SockJS = require('../../lib/entry')
var MPrefix = '_sockjs_global';
module.exports = {
- getOriginUrl: function () {
+ getSameOriginUrl: function () {
if (global.location) {
return urlUtils.getOrigin(global.location.href);
}
return 'http://localhost:8081';
}
+, getCrossOriginUrl: function () {
+ if (global.clientOptions) {
+ return global.clientOptions.url;
+ }
+ return null;
+ }
+
, getUrl: function (path) {
- return /^http/.test(path) ? path : this.getOriginUrl() + path;
+ return /^http/.test(path) ? path : this.getSameOriginUrl() + path;
}
, newSockJs: function (path, transport) {
diff --git a/tests/lib/transports.js b/tests/lib/transports.js
index bc90e51..b3c01d9 100644
--- a/tests/lib/transports.js
+++ b/tests/lib/transports.js
@@ -6,6 +6,7 @@ var expect = require('expect.js')
, testUtils = require('./test-utils')
, echoTests = require('./echo-tests')
, batchTests = require('./batch-tests')
+ , SockJS = require('../../lib/entry')
;
describe('Transports', function () {
@@ -39,27 +40,42 @@ describe('Transports', function () {
}
var transport = Trans.transportName;
- echoTests.echoBasic(transport);
- echoTests.echoQueryString(transport);
- echoTests.echoRich(transport);
- echoTests.echoUnicode(transport);
- echoTests.echoSpecialChars(transport);
- echoTests.echoLargeMessage(transport);
- echoTests.echoUtfEncodingSimple(transport);
- echoTests.echoUtfEncoding(transport);
-
- batchTests.largeMessage(transport);
- batchTests.largeDownload(transport);
-
- userClose(transport);
- serverClose(transport);
+
+ var soUrl = testUtils.getSameOriginUrl();
+ describe('same origin', function () {
+ runTests(soUrl, transport);
+ });
+
+ // var corsUrl = testUtils.getCrossOriginUrl();
+ // if (corsUrl && corsUrl !== soUrl) {
+ // describe('cross origin', function () {
+ // runTests(corsUrl, transport);
+ // });
+ // }
});
});
});
-function userClose(transport) {
+function runTests(url, transport) {
+ echoTests.echoBasic(url, transport);
+ echoTests.echoQueryString(url, transport);
+ echoTests.echoRich(url, transport);
+ echoTests.echoUnicode(url, transport);
+ echoTests.echoSpecialChars(url, transport);
+ echoTests.echoLargeMessage(url, transport);
+ echoTests.echoUtfEncodingSimple(url, transport);
+ echoTests.echoUtfEncoding(url, transport);
+
+ batchTests.largeMessage(url, transport);
+ batchTests.largeDownload(url, transport);
+
+ userClose(url, transport);
+ serverClose(url, transport);
+}
+
+function userClose(url, transport) {
it('user close', function (done) {
- var sjs = testUtils.newSockJs('/echo', transport);
+ var sjs = new SockJS(url + '/echo', null, transport);
expect(sjs).to.be.ok();
var counter = 0;
@@ -82,9 +98,9 @@ function userClose(transport) {
});
}
-function serverClose(transport) {
+function serverClose(url, transport) {
it('server close', function (done) {
- var sjs = testUtils.newSockJs('/close', transport);
+ var sjs = new SockJS(url + '/close', null, transport);
expect(sjs).to.be.ok();
var i = 0;
sjs.onopen = function() {
--
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