File: connect.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 (144 lines) | stat: -rw-r--r-- 6,234 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// META: global=window,worker
// META: script=/common/get-host-info.sub.js
// META: script=resources/webtransport-test-helpers.sub.js

promise_test(async t => {
  const wt = new WebTransport(webtransport_url('custom-response.py?:status=200'));
  await wt.ready;
}, 'WebTransport session is established with status code 200');

promise_test(async t => {
  const wt = new WebTransport(webtransport_url('custom-response.py?:status=204'));
  await wt.ready;
}, 'WebTransport session is established with status code 204');

promise_test(async t => {
  const wt = new WebTransport(webtransport_url('custom-response.py?:status=301'));
  // Sadly we cannot use promise_rejects_dom as the error constructor is
  // WebTransportError rather than DOMException. Ditto below.
  // We get a possible error, and then make sure wt.closed is rejected with it.
  const e = await wt.ready.catch(e => e);
  await promise_rejects_exactly(t, e, wt.closed, 'closed promise should be rejected');
  await promise_rejects_exactly(t, e, wt.ready, 'ready promise shoud be rejected');
  assert_true(e instanceof WebTransportError);
  assert_equals(e.source, 'session', 'source');
  assert_equals(e.streamErrorCode, null, 'streamErrorCode');
}, 'WebTransport session establishment fails with status code 301');

promise_test(async t => {
  const  wt = new WebTransport(webtransport_url('custom-response.py?:status=401'));
  const e = await wt.ready.catch(e => e);
  await promise_rejects_exactly(t, e, wt.closed, 'closed promise should be rejected');
  await promise_rejects_exactly(t, e, wt.ready, 'ready promise shoud be rejected');
  assert_true(e instanceof WebTransportError);
  assert_equals(e.source, 'session', 'source');
  assert_equals(e.streamErrorCode, null, 'streamErrorCode');
}, 'WebTransport session establishment with status code 401');

promise_test(async t => {
  const wt = new WebTransport(webtransport_url('custom-response.py?:status=404'));
  const e = await wt.ready.catch(e => e);
  await promise_rejects_exactly(t, e, wt.closed, 'closed promise should be rejected');
  await promise_rejects_exactly(t, e, wt.ready, 'ready promise shoud be rejected');
  assert_true(e instanceof WebTransportError);
  assert_equals(e.source, 'session', 'source');
  assert_equals(e.streamErrorCode, null, 'streamErrorCode');
}, 'WebTransport session establishment fails with status code 404');

promise_test(async t => {
  // Create WebTransport session.
  const wt = new WebTransport(webtransport_url('echo-request-headers.py'));
  await wt.ready;

  // Read incoming unidirectional stream for echoed request headers.
  const streams = await wt.incomingUnidirectionalStreams;

  const stream_reader = streams.getReader();
  const { value: recv_stream } = await stream_reader.read();
  stream_reader.releaseLock();

  const request_headers = await read_stream_as_json(recv_stream);

  // Check the standard request headers.
  check_and_remove_standard_headers(request_headers);
}, 'Echo back request headers');

promise_test(async t => {
  // Create WebTransport session.
  const options = { protocols: ["a", "b", "c"] };
  const wt = new WebTransport(webtransport_url('echo-request-headers.py'), options);
  await wt.ready;

  // Read incoming unidirectional stream for echoed request headers.
  const streams = await wt.incomingUnidirectionalStreams;

  const stream_reader = streams.getReader();
  const { value: recv_stream } = await stream_reader.read();
  stream_reader.releaseLock();

  const request_headers = await read_stream_as_json(recv_stream);

  // Check the standard request headers.
  check_and_remove_standard_headers(request_headers);
  assert_equals(request_headers['wt-available-protocols'], '"a", "b", "c"');
  assert_equals(wt.protocol, "");
}, 'Validate subprotocol headers sent');

promise_test(async t => {
  const options = { protocols: ["a", "b", "c"] };
  const wt = new WebTransport(webtransport_url('custom-response.py?wt-protocol="b"'), options);
  await wt.ready;
  assert_equals(wt.protocol, "b");
}, 'Validate subprotocol response header received');

promise_test(async t => {
  const options = { protocols: ["a", "b", "c"] };
  const wt = new WebTransport(webtransport_url('custom-response.py?wt-protocol=%22b%22%3B%20a%3Dc%3B%20c%3D2'), options);
  await wt.ready;
  assert_equals(wt.protocol, "b");
}, 'Validate subprotocol response header received with parameters handled correctly');

promise_test(async t => {
  const options = { protocols: ["a", "b", "c"] };
  const wt = new WebTransport(webtransport_url('custom-response.py?wt-protocol=%22d%22'), options);
  await wt.ready;
  assert_equals(wt.protocol, "");
}, 'Validate subprotocol response header with non-offered protocol gets ignored');

promise_test(async t => {
  const options = { protocols: [] };
  const wt = new WebTransport(webtransport_url('custom-response.py?wt-protocol=%22d%22'), options);
  await wt.ready;
  assert_equals(wt.protocol, "");
}, 'Validate subprotocol response header when no protocols were offered gets ignored');

promise_test(async t => {
  const options = { protocols: ["a", "b", "c"] };
  const wt = new WebTransport(webtransport_url('custom-response.py?wt-protocol=b'), options);
  await wt.ready;
  assert_equals(wt.protocol, "");
}, 'Validate malformed subprotocol response header gets ignored');

promise_test(async t => {
  // Create WebTransport session, and attach "Set-Cookie: foo=bar" to the response of
  // the handshake.
  const encodedSetCookie = encodeURIComponent('foo=bar');
  let wt = new WebTransport(webtransport_url('custom-response.py?set-cookie=' + encodedSetCookie));
  await wt.ready;

  wt = new WebTransport(webtransport_url('echo-request-headers.py'));
  await wt.ready;

  // Read incoming unidirectional stream for echoed request headers.
  const streams = await wt.incomingUnidirectionalStreams;

  const stream_reader = streams.getReader();
  const { value: recv_stream } = await stream_reader.read();
  stream_reader.releaseLock();

  const request_headers = await read_stream_as_json(recv_stream);

  // Check cookie header is not echoed back.
  check_and_remove_standard_headers(request_headers);
  assert_equals(request_headers['cookie'], undefined);
}, 'Cookie header is not echoed back');