Auto merge of #6397 - servo:ws-connect, r=Ms2ger

Make an early return when the WebSocket connection fails in the constructor.
Also let the WebSocket connection to be closed when the connection could
not be established.

Fixes #6082.
This commit is contained in:
bors-servo 2015-06-16 01:47:10 -06:00
commit a5d76e4b2c
15 changed files with 48 additions and 28 deletions

View file

@ -141,7 +141,16 @@ impl WebSocket {
// TODO Client::connect does not conform to RFC 6455
// see https://github.com/cyderize/rust-websocket/issues/38
let request = Client::connect(parsed_url).unwrap();
let request = match Client::connect(parsed_url) {
Ok(request) => request,
Err(_) => {
let global_root = ws_root.global.root();
let address = Trusted::new(global_root.r().get_cx(), ws_root, global_root.r().script_chan().clone());
let task = box WebSocketTaskHandler::new(address, WebSocketTask::Close);
global_root.r().script_chan().send(ScriptMsg::RunnableMsg(task)).unwrap();
return Ok(Temporary::from_rooted(ws_root));
}
};
let response = request.send().unwrap();
response.validate().unwrap();
ws_root.ready_state.set(WebSocketRequestState::Open);

View file

@ -1,3 +1,6 @@
[progress.html]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Create WebSocket - Pass a URL with a non ws/wss scheme - SYNTAX_ERR is thrown]
expected: FAIL

View file

@ -1,3 +1,5 @@
[Create-Secure-blocked-port.htm]
type: testharness
expected: CRASH
[W3C WebSocket API - Create Secure WebSocket - Pass a URL with a blocked port - SECURITY_ERR should be thrown]
expected: FAIL

View file

@ -1,3 +0,0 @@
[008.html]
type: testharness
expected: CRASH

View file

@ -1,3 +0,0 @@
[017.html]
type: testharness
expected: CRASH

View file

@ -1,3 +1,5 @@
[021.html]
type: testharness
expected: CRASH
[WebSockets: Same sub protocol twice]
expected: FAIL

View file

@ -1,3 +0,0 @@
[bufferedAmount-defineProperty-getter.html]
type: testharness
expected: CRASH

View file

@ -1,3 +0,0 @@
[bufferedAmount-defineProperty-setter.html]
type: testharness
expected: CRASH

View file

@ -1,3 +1,6 @@
[020.html]
type: testharness
expected: CRASH
expected: TIMEOUT
[WebSockets: error events]
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[004.html]
type: testharness
expected: CRASH

View file

@ -1,3 +0,0 @@
[005.html]
type: testharness
expected: CRASH

View file

@ -1,3 +0,0 @@
[005.html]
type: testharness
expected: CRASH

View file

@ -1,3 +0,0 @@
[006.html]
type: testharness
expected: CRASH

View file

@ -539,6 +539,12 @@
"url": "/_mozilla/mozilla/union.html"
}
],
"mozilla/websocket_connection_fail.html": [
{
"path": "mozilla/websocket_connection_fail.html",
"url": "/_mozilla/mozilla/websocket_connection_fail.html"
}
],
"mozilla/window.html": [
{
"path": "mozilla/window.html",

View file

@ -0,0 +1,19 @@
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function() {
var onclose = 0;
var ws = new WebSocket("ws://wrong_url");
ws.onclose = this.step_func_done(function(ev) {
onclose++;
assert_equals(onclose, 1);
});
});
</script>
</body>
</html>