Bug 1504855 [wpt PR 13931] - Implement RTCQuicStream.write(), a=testonly

Automatic update from web-platform-testsImplement RTCQuicStream.write()

Bug: 874296
Change-Id: I1786acb3b64fa0450e76fe27300c178081d1e191
Reviewed-on: https://chromium-review.googlesource.com/c/1285528
Commit-Queue: Steve Anton <steveanton@chromium.org>
Reviewed-by: Henrik Boström <hbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607708}

--

wpt-commits: 7201104211385809c4c53914834f7fe5c7a8b425
wpt-pr: 13931
This commit is contained in:
Steve Anton 2018-11-15 10:14:59 +00:00 коммит произвёл moz-wptsync-bot
Родитель 2229c47cdd
Коммит 846fb30d46
2 изменённых файлов: 160 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,62 @@
'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(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();
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(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(localStream.state, 'closed');
return test_func(t, localStream);
}, 'Stream closed by remote RTCQuicTransport stop(): ' + description);
}

Просмотреть файл

@ -5,6 +5,7 @@
<script src="/resources/testharnessreport.js"></script>
<script src="RTCIceTransport-extension-helper.js"></script>
<script src="RTCQuicTransport-helper.js"></script>
<script src="RTCQuicStream-helper.js"></script>
<script>
'use strict';
@ -14,6 +15,8 @@
// The following helper functions are called from RTCQuicTransport-helper.js:
// makeStandaloneQuicTransport
// makeTwoConnectedQuicTransports
// The following helper functions are called from RTCQuicStream-helper.js:
// closed_stream_test
promise_test(async t => {
const [ quicTransport, ] = await makeTwoConnectedQuicTransports(t);
@ -25,6 +28,8 @@ promise_test(async t => {
'Expect read buffered amount to be 0.');
assert_equals(quicStream.writeBufferedAmount, 0,
'Expect write buffered amount to be 0.');
assert_greater_than(quicStream.maxWriteBufferedAmount, 0,
'Expect max write buffered amount to be greater than 0.');
}, 'createStream() returns an RTCQuicStream with initial properties set.');
promise_test(async t => {
@ -155,4 +160,97 @@ promise_test(async t => {
assert_equals(remoteStream.state, 'closed');
}, 'finish() then reset() fires two statechange events on the remote side.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(0));
assert_equals(localStream.writeBufferedAmount, 0);
}, 'write() with an empty array does nothing.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array([65]));
assert_equals(localStream.writeBufferedAmount, 1);
localStream.write(new Uint8Array([66, 67]));
assert_equals(localStream.writeBufferedAmount, 3);
localStream.write(new Uint8Array([68, 69, 70]));
assert_equals(localStream.writeBufferedAmount, 6);
}, 'write() adds to writeBufferedAmount each call.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(localStream.maxWriteBufferedAmount));
assert_equals(localStream.writeBufferedAmount,
localStream.maxWriteBufferedAmount);
}, 'write() can write exactly maxWriteBufferedAmount.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
assert_throws('OperationError',
() =>
localStream.write(
new Uint8Array(localStream.maxWriteBufferedAmount + 1)));
assert_equals(localStream.writeBufferedAmount, 0);
}, 'write() throws if data longer than maxWriteBufferedAmount.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(10));
assert_throws('OperationError',
() =>
localStream.write(
new Uint8Array(localStream.maxWriteBufferedAmount)));
assert_equals(localStream.writeBufferedAmount, 10);
}, 'write() throws if total write buffered amount would be greater than ' +
'maxWriteBufferedAmount.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.finish();
assert_throws('InvalidStateError',
() => localStream.write(new Uint8Array()));
}, 'write() throws InvalidStateError if finish() has been called.');
closed_stream_test(async (t, stream) => {
assert_throws('InvalidStateError', () => stream.write(new Uint8Array()));
}, 'write() throws InvalidStateError.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(10));
localStream.reset();
assert_equals(localStream.writeBufferedAmount, 0);
}, 'writeBufferedAmount set to 0 after local reset().');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(10));
localQuicTransport.stop();
assert_equals(localStream.writeBufferedAmount, 0);
}, 'writeBufferedAmount set to 0 after local RTCQuicTransport stop().');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
const localStream = localQuicTransport.createStream();
localStream.write(new Uint8Array(10));
localStream.finish();
assert_equals(localStream.writeBufferedAmount, 10);
}, 'writeBufferedAmount maintained after finish() has been called.');
</script>