gecko-dev/testing/web-platform/tests/webrtc-quic/RTCQuicTransport-helper.js
Seth Hampson 74896625af Bug 1523562 [wpt PR 14908] - Adds pre shared key support to RTCQuicTransport., a=testonly
Automatic update from web-platform-tests
Adds pre shared key support to RTCQuicTransport.

This change adds the PSK APIs to the RTCQuicTransport object. This is
done with a readonly key, connect() and listen() methods. This change
keeps the C++ objects certificate support with the current APIs, but
removes these from being exposed in the web idl file. Tests are updated
by moving web platform tests that involve certificates into C++
tests.

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

--

wpt-commits: b759655abcdddff933d46d6e98f0eac0fc31bd41
wpt-pr: 14908
2019-02-07 21:50:43 +00:00

69 lines
2.6 KiB
JavaScript

'use strict';
// This file depends on RTCIceTransport-extension-helper.js which should be
// loaded from the main HTML file.
// The following helper functions are called from
// RTCIceTransport-extension-helper.js:
// makeIceTransport
// makeGatherAndStartTwoIceTransports
// Construct an RTCQuicTransport instance with the given RTCIceTransport
// instance and the given certificates. The RTCQuicTransport instance will be
// automatically cleaned up when the test finishes.
function makeQuicTransport(t, iceTransport) {
const quicTransport = new RTCQuicTransport(iceTransport);
t.add_cleanup(() => quicTransport.stop());
return quicTransport;
}
// Construct an RTCQuicTransport instance with a new RTCIceTransport instance
// and a single, newly-generated certificate. The RTCQuicTransport and
// RTCIceTransport instances will be automatically cleaned up when the test
// finishes.
function makeStandaloneQuicTransport(t) {
return makeQuicTransport(t, makeIceTransport(t));
}
// Construct two RTCQuicTransport instances and each call start() with the other
// transport's local parameters.
// Returns a 2-list:
// [ server RTCQuicTransport,
// client RTCQuicTransport ]
function makeAndStartTwoQuicTransports(t) {
const [ localIceTransport, remoteIceTransport ] =
makeGatherAndStartTwoIceTransports(t);
const localQuicTransport =
makeQuicTransport(t, localIceTransport);
const remoteQuicTransport =
makeQuicTransport(t, remoteIceTransport);
const remote_key = remoteQuicTransport.getKey();
localQuicTransport.listen(remote_key);
remoteQuicTransport.connect();
return [ localQuicTransport, remoteQuicTransport ];
}
// Construct two RTCQuicTransport instances and wait for them to connect.
// Returns a 2-list:
// [ server RTCQuicTransport,
// client RTCQuicTransport ]
async function makeTwoConnectedQuicTransports(t) {
// Returns a promise that resolves when the transport fires a 'statechange'
// event to 'connected'.
function waitForConnected(transport) {
return new Promise((resolve, reject) => {
const eventHandler = t.step_func(() => {
assert_equals(transport.state, 'connected');
transport.removeEventListener('statechange', eventHandler, false);
resolve();
});
transport.addEventListener('statechange', eventHandler, false);
});
}
const [ localQuicTransport, remoteQuicTransport ] =
await makeAndStartTwoQuicTransports(t);
await Promise.all([
waitForConnected(localQuicTransport),
waitForConnected(remoteQuicTransport),
]);
return [ localQuicTransport, remoteQuicTransport ];
}