|
<!DOCTYPE html> |
|
<head> |
|
<title>Chrome "WebSocket is closed before the connection is established." Test Case</title> |
|
</head> |
|
<body> |
|
<h1>Chrome "WebSocket is closed before the connection is established." Test Case</h1> |
|
<p>This page opens a websocket connection to ws://localhost:8080/</p> |
|
|
|
<h2>Running this Test Case</h2> |
|
<h3>Install dependencies:</h3> |
|
<pre><code>bundle install</code></pre> |
|
|
|
<h3>Start simple websocket server:</h3> |
|
|
|
<pre><code>ruby ws-server.rb</code></pre> |
|
|
|
<h3>Start webserver:</h3> |
|
<pre><code>ruby app.rb</code></pre> |
|
|
|
<h3>Repeat the following steps:</h3> |
|
|
|
<ul> |
|
<li>Open <a href="http://localhost:4567/">http://localhost:4567/</a></li> |
|
<li>Open the JavaScript console.</li> |
|
<li>Click the "test this" button at the bottom of the page</li> |
|
<li>Verify that the following error is logged to the javascript console:</li> |
|
<li><code>"WebSocket is closed before the connection is established."</code></li> |
|
<li>Verify that none of the following have been logged: |
|
<ul> |
|
<li>“onerror”</li> |
|
<li>“window.onerror”</li> |
|
<li>“try/catch around ws.close()”</li> |
|
<li>“try/catch around entire ws code.”</li> |
|
</ul></li> |
|
</ul> |
|
|
|
<hr /> |
|
<button id="test">Test this</button> |
|
|
|
<script type="text/javascript"> |
|
window.onerror = function() { |
|
console.log('window.onerror') |
|
} |
|
|
|
document.getElementById('test').onclick = function() { |
|
var Socket = window['MozWebSocket'] || window['WebSocket'] |
|
|
|
if (Socket) { |
|
try { |
|
var ws = new Socket('ws://localhost:8080/') |
|
ws.onopen = function() { console.log('onopen'); }; |
|
ws.onerror = function() { console.log('onerror attached to websocket object.'); }; |
|
ws.onclose = function() { console.log('onclose'); }; |
|
ws.onmessage = function(evt) { console.log('onmessage: '+evt.data); }; |
|
|
|
// Close as soon as open is called. |
|
try { |
|
ws.onopen = null; |
|
ws.onmessage = null; |
|
ws.onclose = null; |
|
ws.onerror = null; |
|
|
|
ws.close(); |
|
} catch (e) { |
|
console.log('try/catch around ws.close()') |
|
} |
|
} catch (e) { |
|
console.log('try/catch around entire ws code.') |
|
} |
|
} |
|
} |
|
</script> |
|
</body> |