Bug 1610610 part 1. Throw the right exception from MediaSource::SetDuration. r=jya

Differential Revision: https://phabricator.services.mozilla.com/D60595

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-01-22 00:47:38 +00:00
Родитель bf9e6875aa
Коммит ac3e49d4b8
2 изменённых файлов: 8 добавлений и 7 удалений

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

@ -207,7 +207,8 @@ void MediaSource::SetDuration(double aDuration, ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MSE_API("SetDuration(aDuration=%f, ErrorResult)", aDuration); MSE_API("SetDuration(aDuration=%f, ErrorResult)", aDuration);
if (aDuration < 0 || IsNaN(aDuration)) { if (aDuration < 0 || IsNaN(aDuration)) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR); nsPrintfCString error("Invalid duration value %f", aDuration);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(error));
return; return;
} }
if (mReadyState != MediaSourceReadyState::Open || if (mReadyState != MediaSourceReadyState::Open ||

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

@ -21,7 +21,7 @@
test.waitForExpectedEvents(function() test.waitForExpectedEvents(function()
{ {
if (expectedError) { if (expectedError) {
assert_throws(expectedError, assert_throws_js(expectedError,
function() { mediaSource.duration = testDurationValue; }, function() { mediaSource.duration = testDurationValue; },
"mediaSource.duration assignment throws an exception for " + testDurationValue); "mediaSource.duration assignment throws an exception for " + testDurationValue);
test.done(); test.done();
@ -50,14 +50,14 @@
DurationBoundaryConditionTest(Number.MAX_VALUE, null, "Set duration to Number.MAX_VALUE"); DurationBoundaryConditionTest(Number.MAX_VALUE, null, "Set duration to Number.MAX_VALUE");
DurationBoundaryConditionTest(Number.MIN_VALUE, null, "Set duration to Number.MIN_VALUE"); DurationBoundaryConditionTest(Number.MIN_VALUE, null, "Set duration to Number.MIN_VALUE");
DurationBoundaryConditionTest(Number.MAX_VALUE - 1, null, "Set duration to Number.MAX_VALUE - 1"); DurationBoundaryConditionTest(Number.MAX_VALUE - 1, null, "Set duration to Number.MAX_VALUE - 1");
DurationBoundaryConditionTest(Number.MIN_VALUE - 1, new TypeError(), "Set duration to Number.MIN_VALUE - 1"); DurationBoundaryConditionTest(Number.MIN_VALUE - 1, TypeError, "Set duration to Number.MIN_VALUE - 1");
DurationBoundaryConditionTest(Number.POSITIVE_INFINITY, null, "Set duration to Number.POSITIVE_INFINITY"); DurationBoundaryConditionTest(Number.POSITIVE_INFINITY, null, "Set duration to Number.POSITIVE_INFINITY");
DurationBoundaryConditionTest(Number.NEGATIVE_INFINITY, new TypeError(), "Set duration to Number.NEGATIVE_INFINITY"); DurationBoundaryConditionTest(Number.NEGATIVE_INFINITY, TypeError, "Set duration to Number.NEGATIVE_INFINITY");
DurationBoundaryConditionTest(-1 * Number.MAX_VALUE, new TypeError(), "Set duration to lowest value."); DurationBoundaryConditionTest(-1 * Number.MAX_VALUE, TypeError, "Set duration to lowest value.");
DurationBoundaryConditionTest(-101.9, new TypeError(), "Set duration to a negative double."); DurationBoundaryConditionTest(-101.9, TypeError, "Set duration to a negative double.");
DurationBoundaryConditionTest(101.9, null, "Set duration to a positive double."); DurationBoundaryConditionTest(101.9, null, "Set duration to a positive double.");
DurationBoundaryConditionTest(0, null, "Set duration to zero"); DurationBoundaryConditionTest(0, null, "Set duration to zero");
DurationBoundaryConditionTest(NaN, new TypeError(), "Set duration to NaN"); DurationBoundaryConditionTest(NaN, TypeError, "Set duration to NaN");
</script> </script>
</body> </body>
</html> </html>