constructor.https.any.js (2602B)
1 // META: global=window,worker 2 // META: script=/common/get-host-info.sub.js 3 // META: script=resources/webtransport-test-helpers.sub.js 4 // META: script=/common/utils.js 5 6 const BAD_URLS = [ 7 null, 8 '', 9 'no-scheme', 10 'http://example.com/' /* scheme is wrong */, 11 'quic-transport://example.com/' /* scheme is wrong */, 12 'https:///' /* no host specified */, 13 'https://example.com/#failing' /* has fragment */, 14 `https://${HOST}:999999/` /* invalid port */, 15 ]; 16 17 for (const url of BAD_URLS) { 18 test(() => { 19 assert_throws_dom('SyntaxError', () => new WebTransport(url), 20 'constructor should throw'); 21 }, `WebTransport constructor should reject URL '${url}'`); 22 } 23 24 const BAD_PROTOCOL_LISTS = [ 25 [''], 26 ['\u8AA4'], 27 ['test', 'test'], 28 ['a'.repeat(513)], 29 ]; 30 31 for (const protocols of BAD_PROTOCOL_LISTS) { 32 test(() => { 33 assert_throws_dom('SyntaxError', () => new WebTransport( 34 webtransport_url(`echo.py`), 35 { protocols : protocols }), 36 'constructor should throw'); 37 }, `WebTransport constructor should reject protocol list '${protocols}'`); 38 } 39 40 const OPTIONS = [ 41 { allowPooling: true }, 42 { requireUnreliable: true }, 43 { allowPooling: true, requireUnreliable: true }, 44 { congestionControl: "default" }, 45 { congestionControl: "throughput" }, 46 { congestionControl: "low-latency" }, 47 { protocols: ["test"] }, 48 { protocols: ["a", "b", "c"] }, 49 { allowPooling: true, requireUnreliable: true, congestionControl: "low-latency" }, 50 // XXX Need to test serverCertificateHashes 51 ]; 52 53 for (const options of OPTIONS) { 54 promise_test(async t => { 55 const id = token(); 56 const wt = new WebTransport(webtransport_url(`client-close.py?token=${id}`), options ); 57 await wt.ready; 58 wt.close(); 59 }, "WebTransport constructor should allow options " + JSON.stringify(options)); 60 } 61 62 promise_test(async t => { 63 const wt = new WebTransport(`https://${HOST}:0/`); 64 65 // Sadly we cannot use promise_rejects_dom as the error constructor is 66 // WebTransportError rather than DOMException. 67 // We get a possible error, and then make sure wt.ready is rejected with it. 68 const e = await wt.ready.catch(e => e); 69 70 await promise_rejects_exactly(t, e, wt.ready, 'ready should be rejected'); 71 await promise_rejects_exactly(t, e, wt.closed, 'closed should be rejected'); 72 assert_true(e instanceof WebTransportError); 73 assert_equals(e.source, 'session', 'source'); 74 assert_equals(e.streamErrorCode, null, 'streamErrorCode'); 75 }, 'Connection to port 0 should fail');