Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 6 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /websockets/constructor/target-address-space.any.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/target-address-space.any.html?wss - WPT Dashboard Interop Dashboard
- /websockets/constructor/target-address-space.any.worker.html?default - WPT Dashboard Interop Dashboard
- /websockets/constructor/target-address-space.any.worker.html?wss - WPT Dashboard Interop Dashboard
// META: title=WebSockets: targetAddressSpace option in constructor argument
// META: script=../constants.sub.js
// META: variant=?default
// META: variant=?wss
async_test(t => {
const ws = new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'loopback'});
ws.onopen = t.step_func(() => {
ws.close();
t.done();
});
ws.onerror = t.unreached_func('error event should not have fired');
}, 'WebSocket constructor with matching targetAddressSpace \'loopback\' succeeds');
test(() => {
assert_throws_js(TypeError, () => {
new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'private'});
});
}, 'WebSocket constructor with targetAddressSpace \'private\' throws TypeError as it is an unsupported legacy alias');
async_test(t => {
const ws = new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'local'});
ws.onopen = t.unreached_func('open event should not have fired');
ws.onerror = t.step_func(() => {
t.done();
});
}, 'WebSocket constructor with mismatched targetAddressSpace \'local\' fails connection');
async_test(t => {
const ws = new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'public'});
ws.onopen = t.unreached_func('open event should not have fired');
ws.onerror = t.step_func(() => {
t.done();
});
}, 'WebSocket constructor with mismatched targetAddressSpace \'public\' fails connection');
test(() => {
assert_throws_js(TypeError, () => {
new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'unknown'});
});
}, 'WebSocket constructor with targetAddressSpace \'unknown\' throws TypeError');
test(() => {
assert_throws_js(TypeError, () => {
new WebSocket(SCHEME_DOMAIN_PORT + '/echo',
{targetAddressSpace: 'invalid'});
});
}, 'WebSocket constructor with invalid targetAddressSpace throws TypeError');