gecko-dev/testing/web-platform/tests/webrtc-quic/RTCQuicStream-helper.js
Seth Hampson 00a380a608 Bug 1514099 [wpt PR 14510] - Update for RTCQuicStream.write() function., a=testonly
Automatic update from web-platform-tests
Update for RTCQuicStream.write() function.

Combines functionality of finish() into write() by adding a new
QuicStreamWriteParameters input parameter that includes a finish
boolean. This is consistent with the latest spec draft and also adds
symmetry between readInto() and write().

Bug: 874296
Change-Id: I0def0ca25587ebf00a4b179ce8e9e7a124c818f6
Reviewed-on: https://chromium-review.googlesource.com/c/1376720
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Steve Anton <steveanton@chromium.org>
Commit-Queue: Seth Hampson <shampson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616941}

--

wpt-commits: a3efcf10006556ecb6169610324f650a5522650d
wpt-pr: 14510
2019-01-23 10:56:15 +00:00

98 lines
4.2 KiB
JavaScript

'use strict';
// This file depends on RTCQuicTransport-helper.js which should be loaded from
// the main HTML file.
// The following helper methods are called from RTCQuicTransport-helper.js:
// makeTwoConnectedQuicTransports
// Run a test function for as many ways as an RTCQuicStream can transition to
// the 'closed' state.
// |test_func| will be called with the test as the first argument and the closed
// RTCQuicStream as the second argument.
function closed_stream_test(test_func, description) {
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.reset();
assert_equals(localStream.state, 'closed');
return test_func(t, localStream);
}, 'Stream closed by local reset(): ' + description);
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write({ data: new Uint8Array(1) });
const remoteWatcher =
new EventWatcher(t, remoteQuicTransport, 'quicstream');
const { stream: remoteStream } = await remoteWatcher.wait_for('quicstream');
localStream.reset();
const remoteStreamWatcher =
new EventWatcher(t, remoteStream, 'statechange');
await remoteStreamWatcher.wait_for('statechange');
assert_equals(remoteStream.state, 'closed');
return test_func(t, remoteStream);
}, 'Stream closed by remote reset(): ' + description);
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write({ finish: true });
const remoteWatcher =
new EventWatcher(t, remoteQuicTransport, 'quicstream');
const { stream: remoteStream } = await remoteWatcher.wait_for('quicstream');
remoteStream.write({ finish: true });
await localStream.waitForReadable(localStream.maxReadBufferedAmount);
assert_object_equals(
localStream.readInto(new Uint8Array(10)),
{ amount: 0, finished: true });
assert_equals(localStream.state, 'closed');
return test_func(t, localStream);
}, 'Stream closed by writing a finish, followed by reading remote finish: ' +
description);
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write({ finish: true });
const remoteWatcher =
new EventWatcher(t, remoteQuicTransport, 'quicstream');
const { stream: remoteStream } = await remoteWatcher.wait_for('quicstream');
await remoteStream.waitForReadable(10);
assert_object_equals(
remoteStream.readInto(new Uint8Array(10)),
{ amount: 0, finished: true });
remoteStream.write({ finish: true });
assert_equals(remoteStream.state, 'closed');
return test_func(t, remoteStream);
}, 'Stream closed by by reading remote finish, followed by writing a ' +
'finish: ' + description);
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localQuicTransport.stop();
assert_equals(localStream.state, 'closed');
return test_func(t, localStream);
}, 'Stream closed by local RTCQuicTransport stop(): ' + description);
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write({ data: new Uint8Array(1) });
const remoteWatcher =
new EventWatcher(t, remoteQuicTransport,
[ 'quicstream', 'statechange' ]);
const { stream: remoteStream } = await remoteWatcher.wait_for('quicstream');
localQuicTransport.stop();
await remoteWatcher.wait_for('statechange');
assert_equals(remoteStream.state, 'closed');
return test_func(t, remoteStream);
}, 'Stream closed by remote RTCQuicTransport stop(): ' + description);
}