             return i
      return -1
 
-test_protocol = (protocol) ->
+test_protocol_messages = (protocol) ->
     module(protocol)
     if not SockJS[protocol] or not SockJS[protocol].enabled(client_opts.sockjs_opts)
         test "[unsupported by client]", ->

    r.removeEventListener 'message', bluff
    r.dispatchEvent({type:'message'})

asyncTest "chunking test", ->
    expect(25)
    a = new Array(25)
    go = ->
        SockJS.chunkingTest client_opts.url + '/echo', (r) ->
            if $.browser.msie and $.browser.version < 8
                # on browsers with no streaming support...
                equal(r, false)
            else
                equal(r, true)
            a.shift()
            if a.length isnt 0
                go()
            else
                start()
    go()

asyncTest "chunking test, invalid url 404", ->
        expect(1)


        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("user close", factor_user_close(protocol))
        asyncTest("server close", factor_server_close(protocol))
        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)


module('other')
