diff options
8 files changed, 31 insertions, 509 deletions
diff --git a/components/script/dom/webidls/WebSocket.webidl b/components/script/dom/webidls/WebSocket.webidl index 3fd2fcd403d..b29cf6ba4ed 100644 --- a/components/script/dom/webidls/WebSocket.webidl +++ b/components/script/dom/webidls/WebSocket.webidl @@ -4,7 +4,7 @@ enum BinaryType { "blob", "arraybuffer" }; -[Constructor(DOMString url)] +[Constructor(DOMString url, optional /*(*/DOMString /*or DOMString[])*/ protocols)] interface WebSocket : EventTarget { readonly attribute DOMString url; //ready state diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index bd90a36680a..6b97352f65b 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -96,11 +96,34 @@ impl WebSocket { } - pub fn new(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> { + pub fn new(global: GlobalRef, + url: DOMString, + protocols: Option<DOMString>) + -> Fallible<Root<WebSocket>> { // Step 1. let parsed_url = try!(Url::parse(&url).map_err(|_| Error::Syntax)); let url = try!(parse_url(&parsed_url).map_err(|_| Error::Syntax)); + // Step 4. + let protocols = protocols.as_slice(); + + // Step 5. + for (i, protocol) in protocols.iter().enumerate() { + // https://tools.ietf.org/html/rfc6455#section-4.1 + // Handshake requirements, step 10 + if protocol.is_empty() { + return Err(Syntax); + } + + if protocols[i+1..].iter().any(|p| p == protocol) { + return Err(Syntax); + } + + if protocol.chars().any(|c| c < '\u{0021}' || c > '\u{007E}') { + return Err(Syntax); + } + } + /*TODO: This constructor is only a prototype, it does not accomplish the specs defined here: http://html.spec.whatwg.org @@ -150,8 +173,11 @@ impl WebSocket { Ok(ws) } - pub fn Constructor(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> { - WebSocket::new(global, url) + pub fn Constructor(global: GlobalRef, + url: DOMString, + protocols: Option<DOMString>) + -> Fallible<Root<WebSocket>> { + WebSocket::new(global, url, protocols) } } diff --git a/components/script/lib.rs b/components/script/lib.rs index c57c0de7998..2712aaca88e 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -4,6 +4,7 @@ #![feature(append)] #![feature(arc_unique)] +#![feature(as_slice)] #![feature(as_unsafe_cell)] #![feature(borrow_state)] #![feature(box_raw)] diff --git a/tests/wpt/metadata/websockets/Create-nonAscii-protocol-string.htm.ini b/tests/wpt/metadata/websockets/Create-nonAscii-protocol-string.htm.ini deleted file mode 100644 index 08b72e6c518..00000000000 --- a/tests/wpt/metadata/websockets/Create-nonAscii-protocol-string.htm.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Create-nonAscii-protocol-string.htm] - type: testharness - [W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string with non-ascii values - SYNTAX_ERR is thrown] - expected: FAIL - diff --git a/tests/wpt/metadata/websockets/Create-protocol-with-space.htm.ini b/tests/wpt/metadata/websockets/Create-protocol-with-space.htm.ini deleted file mode 100644 index 08c4f65eb16..00000000000 --- a/tests/wpt/metadata/websockets/Create-protocol-with-space.htm.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Create-protocol-with-space.htm] - type: testharness - [W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string with a space in it - SYNTAX_ERR is thrown] - expected: FAIL - diff --git a/tests/wpt/metadata/websockets/constructor/004.html.ini b/tests/wpt/metadata/websockets/constructor/004.html.ini deleted file mode 100644 index 96b6eb53ac1..00000000000 --- a/tests/wpt/metadata/websockets/constructor/004.html.ini +++ /dev/null @@ -1,485 +0,0 @@ -[004.html] - type: testharness - [WebSockets: new WebSocket(url, invalid protocol)] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 1] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 2] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 3] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 4] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 5] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 6] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 7] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 8] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 9] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 10] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 11] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 12] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 13] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 14] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 15] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 16] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 17] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 18] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 19] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 20] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 21] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 22] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 23] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 24] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 25] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 26] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 27] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 28] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 29] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 30] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 31] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 32] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 33] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 34] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 35] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 36] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 37] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 38] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 39] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 40] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 41] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 42] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 43] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 44] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 45] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 46] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 47] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 48] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 49] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 50] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 51] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 52] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 53] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 54] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 55] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 56] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 57] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 58] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 59] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 60] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 61] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 62] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 63] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 64] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 65] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 66] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 67] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 68] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 69] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 70] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 71] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 72] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 73] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 74] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 75] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 76] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 77] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 78] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 79] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 80] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 81] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 82] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 83] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 84] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 85] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 86] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 87] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 88] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 89] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 90] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 91] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 92] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 93] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 94] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 95] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 96] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 97] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 98] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 99] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 100] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 101] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 102] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 103] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 104] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 105] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 106] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 107] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 108] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 109] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 110] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 111] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 112] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 113] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 114] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 115] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 116] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 117] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 118] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 119] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 120] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 121] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 122] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 123] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 124] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 125] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 126] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 127] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 128] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 129] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 130] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 131] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 132] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 133] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 134] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 135] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 136] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 137] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 138] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 139] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 140] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 141] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 142] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 143] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 144] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 145] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 146] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 147] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 148] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 149] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 150] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 151] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 152] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 153] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 154] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 155] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 156] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 157] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 158] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 159] - expected: FAIL - - [WebSockets: new WebSocket(url, invalid protocol) 160] - expected: FAIL - diff --git a/tests/wpt/metadata/websockets/constructor/007.html.ini b/tests/wpt/metadata/websockets/constructor/007.html.ini deleted file mode 100644 index da31c8e0253..00000000000 --- a/tests/wpt/metadata/websockets/constructor/007.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[007.html] - type: testharness - [WebSockets: new WebSocket(url, null char)] - expected: FAIL - diff --git a/tests/wpt/metadata/websockets/constructor/021.html.ini b/tests/wpt/metadata/websockets/constructor/021.html.ini deleted file mode 100644 index 450a75a3112..00000000000 --- a/tests/wpt/metadata/websockets/constructor/021.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[021.html] - type: testharness - [WebSockets: Same sub protocol twice] - expected: FAIL - |