File: constructor.https.any.js

package info (click to toggle)
firefox 147.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,320 kB
  • sloc: cpp: 7,607,359; javascript: 6,533,295; ansic: 3,775,223; python: 1,415,500; xml: 634,561; asm: 438,949; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (75 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// META: global=window,worker
// META: script=/common/get-host-info.sub.js
// META: script=resources/webtransport-test-helpers.sub.js
// META: script=/common/utils.js

const BAD_URLS = [
  null,
  '',
  'no-scheme',
  'http://example.com/' /* scheme is wrong */,
  'quic-transport://example.com/' /* scheme is wrong */,
  'https:///' /* no host  specified */,
  'https://example.com/#failing' /* has fragment */,
  `https://${HOST}:999999/` /* invalid port */,
];

for (const url of BAD_URLS) {
  test(() => {
    assert_throws_dom('SyntaxError', () => new WebTransport(url),
                      'constructor should throw');
  }, `WebTransport constructor should reject URL '${url}'`);
}

const BAD_PROTOCOL_LISTS = [
  [''],
  ['\u8AA4'],
  ['test', 'test'],
  ['a'.repeat(513)],
];

for (const protocols of BAD_PROTOCOL_LISTS) {
  test(() => {
    assert_throws_dom('SyntaxError', () => new WebTransport(
                                               webtransport_url(`echo.py`),
                                               { protocols : protocols }),
                      'constructor should throw');
  }, `WebTransport constructor should reject protocol list '${protocols}'`);
}

const OPTIONS = [
  { allowPooling: true },
  { requireUnreliable: true },
  { allowPooling: true, requireUnreliable: true },
  { congestionControl: "default" },
  { congestionControl: "throughput" },
  { congestionControl: "low-latency" },
  { protocols: ["test"] },
  { protocols: ["a", "b", "c"] },
  { allowPooling: true, requireUnreliable: true, congestionControl: "low-latency" },
  // XXX Need to test serverCertificateHashes
];

for (const options of OPTIONS) {
  promise_test(async t => {
    const id = token();
    const wt = new WebTransport(webtransport_url(`client-close.py?token=${id}`), options );
    await wt.ready;
    wt.close();
  }, "WebTransport constructor should allow options " + JSON.stringify(options));
}

promise_test(async t => {
  const wt = new WebTransport(`https://${HOST}:0/`);

  // Sadly we cannot use promise_rejects_dom as the error constructor is
  // WebTransportError rather than DOMException.
  // We get a possible error, and then make sure wt.ready is rejected with it.
  const e = await wt.ready.catch(e => e);

  await promise_rejects_exactly(t, e, wt.ready, 'ready should be rejected');
  await promise_rejects_exactly(t, e, wt.closed, 'closed should be rejected');
  assert_true(e instanceof WebTransportError);
  assert_equals(e.source, 'session', 'source');
  assert_equals(e.streamErrorCode, null, 'streamErrorCode');
}, 'Connection to port 0 should fail');