[Pkg-javascript-commits] [sockjs-client] 305/434: Fix the 2000 error on invalid paths. Now expect 1002.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:21 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit f699fe3c2fd63ba87009ea9fd022030579bc2417
Author: Marek Majkowski <majek04 at gmail.com>
Date: Mon Jan 16 11:21:15 2012 +0000
Fix the 2000 error on invalid paths. Now expect 1002.
Now, with the /info code, testing each protocol for handling 404/500 makes little sense. Instead, we should check the end-to-end results.
---
lib/sockjs.js | 14 +++++----
tests/html/src/endtoendtests.coffee | 33 +++++++++++++++++++-
tests/html/src/tests.coffee | 60 -------------------------------------
3 files changed, 40 insertions(+), 67 deletions(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index cccf846..057e870 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -24,7 +24,7 @@ var SockJS = function(url, protocols_whitelist, options) {
that._applyInfo(info, rtt, protocols_whitelist);
that._didClose();
} else {
- that._didClose(3000, 'Can\'t connect to server');
+ that._didClose(1002, 'Can\'t connect to server', true);
}
};
};
@@ -73,7 +73,7 @@ SockJS.prototype._dispatchHeartbeat = function(data) {
that.dispatchEvent(new SimpleEvent('heartbeat', {}));
};
-SockJS.prototype._didClose = function(code, reason) {
+SockJS.prototype._didClose = function(code, reason, force) {
var that = this;
if (that.readyState !== SockJS.CONNECTING &&
that.readyState !== SockJS.OPEN &&
@@ -83,11 +83,13 @@ SockJS.prototype._didClose = function(code, reason) {
that._transport.doCleanup();
that._transport = null;
- var close_event = new SimpleEvent("close", {code: code,
- reason: reason,
- wasClean: utils.userSetCode(code)});
+ var close_event = new SimpleEvent("close", {
+ code: code,
+ reason: reason,
+ wasClean: utils.userSetCode(code)});
- if (!utils.userSetCode(code) && that.readyState === SockJS.CONNECTING) {
+ if (!utils.userSetCode(code) &&
+ that.readyState === SockJS.CONNECTING && !force) {
if (that._try_next_protocol(close_event)) {
return;
}
diff --git a/tests/html/src/endtoendtests.coffee b/tests/html/src/endtoendtests.coffee
index dda697d..5238b7c 100644
--- a/tests/html/src/endtoendtests.coffee
+++ b/tests/html/src/endtoendtests.coffee
@@ -46,4 +46,35 @@ body_protocols = ['iframe-eventsource',
'iframe-xhr-polling',
'jsonp-polling']
for protocol in body_protocols
- factory_body_check(protocol)
\ No newline at end of file
+ factory_body_check(protocol)
+
+
+module('connection errors')
+asyncTest "invalid url 404", ->
+ expect(4)
+ r = newSockJS('/invalid_url', 'jsonp-polling')
+ ok(r)
+ r.onopen = (e) ->
+ fail(true)
+ r.onmessage = (e) ->
+ fail(true)
+ r.onclose = (e) ->
+ log('404', e)
+ equals(e.code, 1002)
+ equals(e.reason, 'Can\'t connect to server')
+ equals(e.wasClean, false)
+ start()
+
+asyncTest "invalid url port", ->
+ expect(4)
+ dl = document.location
+ r = newSockJS(dl.protocol + '//' + dl.hostname + ':1079', 'jsonp-polling')
+ ok(r)
+ r.onopen = (e) ->
+ fail(true)
+ r.onclose = (e) ->
+ log('port', e)
+ equals(e.code, 1002)
+ equals(e.reason, 'Can\'t connect to server')
+ equals(e.wasClean, false)
+ start()
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 8f00a2c..331c720 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -270,49 +270,6 @@ factor_server_close = (protocol) ->
equals(e.wasClean, true)
start()
-test_invalid_url_404 = (protocol) ->
- return ->
- expect(3)
- r = newSockJS('/invalid_url', protocol)
- ok(r)
- r.onopen = (e) ->
- fail(true)
- r.onmessage = (e) ->
- fail(true)
- r.onclose = (e) ->
- log('404', e)
- equals(e.code, 2000)
- equals(e.wasClean, false)
- start()
-
-test_invalid_url_500 = (protocol) ->
- return ->
- expect(3)
- r = newSockJS('/500_error', protocol)
- ok(r)
- r.onopen = (e) ->
- fail(true)
- r.onclose = (e) ->
- log('500', e)
- equals(e.code, 2000)
- equals(e.wasClean, false)
- start()
-
-test_invalid_url_port = (protocol) ->
- return ->
- expect(3)
- dl = document.location
- r = newSockJS(dl.protocol + '//' + dl.hostname + ':1079', protocol)
- ok(r)
- r.onopen = (e) ->
- fail(true)
- r.onclose = (e) ->
- log('port', e)
- equals(e.code, 2000)
- equals(e.wasClean, false)
- start()
-
-
# IE doesn't do array.indexOf...
arrIndexOf = (arr, obj) ->
for i in [0...arr.length]
@@ -346,20 +303,6 @@ test_protocol_messages = (protocol) ->
asyncTest("user close", factor_user_close(protocol))
asyncTest("server close", factor_server_close(protocol))
-test_protocol_errors = (protocol) ->
- module(protocol)
- if not SockJS[protocol] or not SockJS[protocol].enabled(client_opts.sockjs_opts)
- test "[unsupported by client]", ->
- log('Unsupported protocol (by client): "' + protocol + '"')
- else if client_opts.disabled_transports and
- arrIndexOf(client_opts.disabled_transports, protocol) isnt -1
- test "[unsupported by server]", ->
- log('Unsupported protocol (by server): "' + protocol + '"')
- else
- asyncTest("invalid url 404", test_invalid_url_404(protocol))
- asyncTest("invalid url 500", test_invalid_url_500(protocol))
- asyncTest("invalid url port", test_invalid_url_port(protocol))
-
for protocol in protocols
test_protocol_messages(protocol)
@@ -403,6 +346,3 @@ asyncTest "disabled websocket test", ->
equals(e.wasClean, false)
start()
-
-for protocol in protocols
- test_protocol_errors(protocol)
--
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