Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /websockets/constructor/third-param-ignored.any.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.html?wss - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.serviceworker.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.serviceworker.html?wss - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.sharedworker.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.sharedworker.html?wss - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.worker.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/third-param-ignored.any.worker.html?wss - WPT Dashboard Interop Dashboard
// META: title=WebSockets: third parameter ignored
// META: script=../constants.sub.js
// META: global=window,worker
// META: variant=?default
// META: variant=?wss
promise_test(async (t) => {
// The NodeJS "ws" library adds a third option bag parameter to the WebSocket
// constructor. Some pages pass this even in the browser, for convenience when
// sharing the same code between the browser and server, or for tests. Prior
// to the addition of option bag support to the WebSocket constructor, passing
// an `undefined` value as the second parameter results in requesting a
// protocol called "undefined". The `echo_wsh.py` handler doesn't support
// protocols other than "echo", so use `protocol_array_wsh.py` instead.
const ws = new WebSocket(
`${SCHEME_DOMAIN_PORT}/protocol_array`,
undefined,
{},
);
t.add_cleanup(() => ws.close());
await new Promise((resolve) => {
ws.onopen = t.step_func(() => ws.close());
ws.onerror = t.unreached_func('error event should not have fired');
ws.onclose = resolve;
});
}, 'a third parameter to the constructor should be ignored');
promise_test(async (t) => {
const ws = new WebSocket(
`${SCHEME_DOMAIN_PORT}/echo`,
'echo',
{},
);
t.add_cleanup(() => ws.close());
await new Promise(resolve => {
ws.onopen = t.step_func(() => {
assert_equals(ws.protocol, 'echo', 'protocol should be "echo"');
ws.close();
});
ws.onerror = t.unreached_func('error event should not have fired');
ws.onclose = resolve;
});
}, 'protocol string should work with ignored third parameter');
promise_test(async (t) => {
const ws = new WebSocket(
`${SCHEME_DOMAIN_PORT}/echo`,
['echo'],
{},
);
t.add_cleanup(() => ws.close());
await new Promise(resolve => {
ws.onopen = t.step_func(() => {
assert_equals(ws.protocol, 'echo', 'protocol should be "echo"');
ws.close();
});
ws.onerror = t.unreached_func('error event should not have fired');
ws.onclose = resolve;
});
}, 'protocol sequence should work with ignored third parameter');