Bug 1816160: Warn (and no-op) on setParameters with empty encodings if the compat mode is enabled. r=jib

Also add some wpt for this (invalid) case.

Differential Revision: https://phabricator.services.mozilla.com/D169505
This commit is contained in:
Byron Campen 2023-02-10 23:34:33 +00:00
Родитель 75d8636439
Коммит ce0852bb68
3 изменённых файлов: 42 добавлений и 10 удалений

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

@ -621,15 +621,21 @@ already_AddRefed<Promise> RTCRtpSender::SetParameters(
// This could conceivably happen if we are allowing the old setParameters
// behavior.
if (!paramsCopy.mEncodings.Length()) {
if (!mHaveFailedBecauseNoEncodings) {
mHaveFailedBecauseNoEncodings = true;
mozilla::glean::rtcrtpsender_setparameters::fail_no_encodings
.AddToNumerator(1);
}
nsCString error("Cannot set an empty encodings array");
if (!mAllowOldSetParameters) {
if (!mHaveFailedBecauseNoEncodings) {
mHaveFailedBecauseNoEncodings = true;
mozilla::glean::rtcrtpsender_setparameters::fail_no_encodings
.AddToNumerator(1);
}
p->MaybeRejectWithInvalidModificationError(
"Cannot set an empty encodings array");
return p.forget();
p->MaybeRejectWithInvalidModificationError(error);
return p.forget();
}
// TODO: Add some warning telemetry here
WarnAboutBadSetParameters(error);
// Just don't do this; it's stupid.
paramsCopy.mEncodings = oldParams->mEncodings;
}
// TODO: Verify remaining read-only parameters

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

@ -313,7 +313,7 @@ const tests = [
} catch (e) {
}
let newRate = await GleanTest.rtcrtpsenderSetparameters.failNoEncodings.testGetValue();
is(newRate.numerator, oldRate.numerator + 1, "Glean should have recorded an error due to stale transactionId in setParameters");
is(newRate.numerator, oldRate.numerator, "Glean should not have recorded an error due to empty encodings in setParameters");
// Glean should only record the error once per sender!
oldRate = newRate;
@ -324,7 +324,7 @@ const tests = [
} catch (e) {
}
newRate = await GleanTest.rtcrtpsenderSetparameters.failNoEncodings.testGetValue();
is(newRate.numerator, oldRate.numerator, "Glean should not have recorded another error due to stale transactionId in setParameters");
is(newRate.numerator, oldRate.numerator, "Glean should not have recorded an error due empty encodings in setParameters");
},
async function checkBadSetParametersOtherError() {

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

@ -422,6 +422,32 @@
sender.setParameters(param));
}, `sender.setParameters() with encodings unset should reject with TypeError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
param.encodings = [];
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with empty encodings should reject with InvalidModificationError (video)`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('audio');
const param = sender.getParameters();
param.encodings = [];
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with empty encodings should reject with InvalidModificationError (audio)`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());