fune/testing/web-platform/tests/webrtc-svc/svc-helper.js
Florent Castelli f3ca12485e Bug 1804039 [wpt PR 37320] - Reorganize WebRTC-SVC tests in multiple files, a=testonly
Automatic update from web-platform-tests
Reorganize WebRTC-SVC tests in multiple files

A single file with all the tests used to timeout as it would
take too long.

Also mark the Mac tests as possibly failing since there might be
issues on some devices.

Bug: 986069
Change-Id: I828ec51c0cab66b2482cf1215cc6674a12d03e54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4079144
Reviewed-by: Harald Alvestrand <hta@chromium.org>
Commit-Queue: Florent Castelli <orphis@chromium.org>
Auto-Submit: Florent Castelli <orphis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1079212}

--

wpt-commits: 05845f57ff75c28c25ae4d494c156dcf428af483
wpt-pr: 37320
2022-12-11 12:09:02 +00:00

50 lines
1.9 KiB
JavaScript

function supportsCodec(mimeType) {
return RTCRtpSender.getCapabilities('video').codecs.filter(c => c.mimeType == mimeType).length() > 0;
}
async function supportsScalabilityMode(mimeType, scalabilityMode) {
let result = await navigator.mediaCapabilities.encodingInfo({
type: 'webrtc',
video: {
contentType: mimeType,
width: 60,
height: 60,
bitrate: 10000,
framerate: 30,
scalabilityMode: scalabilityMode
}
});
return result.supported;
}
function createScalabilityTest(mimeType, scalabilityModes) {
for (const scalabilityMode of scalabilityModes) {
promise_test(async t => {
assert_implements_optional(
supportsScalabilityMode(mimeType, scalabilityMode),
`${mimeType} supported`
);
const v = document.createElement('video');
v.autoplay = true;
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const stream1 = await getNoiseStream({ video: { signal: 100, width: 60, height: 60 } });
const [track1] = stream1.getTracks();
t.add_cleanup(() => track1.stop());
const transceiver = pc1.addTransceiver(track1, {
sendEncodings: [{ scalabilityMode: scalabilityMode }],
});
transceiver.setCodecPreferences(RTCRtpSender.getCapabilities('video').codecs.filter(c => c.mimeType == mimeType));
const haveTrackEvent = new Promise(r => pc2.ontrack = r);
exchangeIceCandidates(pc1, pc2);
await exchangeOfferAnswer(pc1, pc2);
v.srcObject = new MediaStream([(await haveTrackEvent).track]);
await new Promise(r => v.onloadedmetadata = r);
await detectSignal(t, v, 100);
const sendParams = pc1.getSenders()[0].getParameters();
assert_equals(sendParams.encodings[0].scalabilityMode, scalabilityMode);
}, `${mimeType} - ${scalabilityMode} should produce valid video content`);
}
}