Bug 1629381 - CanvasRenderingContext2D.drawImage shouldn't throw for e.g <video> if there's no valid surface to draw. r=sotaro

As per spec see comment.

Differential Revision: https://phabricator.services.mozilla.com/D103157
This commit is contained in:
Emilio Cobos Álvarez 2021-05-25 10:39:51 +00:00
Родитель 98c195c65e
Коммит 3f1ed5cd9c
5 изменённых файлов: 23 добавлений и 15 удалений

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

@ -4540,11 +4540,16 @@ void CanvasRenderingContext2D::DrawImage(const CanvasImageSource& aImage,
}
if (!res.mSourceSurface && !res.mDrawInfo.mImgContainer) {
// The spec says to silently do nothing in the following cases:
// https://html.spec.whatwg.org/#check-the-usability-of-the-image-argument:
//
// Only throw if the request is broken and the element is an
// HTMLImageElement / SVGImageElement. Note that even for those the spec
// says to silently do nothing in the following cases:
// - The element is still loading.
// - The image is bad, but it's not in the broken state (i.e., we could
// decode the headers and get the size).
if (!res.mIsStillLoading && !res.mHasSize) {
if (!res.mIsStillLoading && !res.mHasSize &&
(aImage.IsHTMLImageElement() || aImage.IsSVGImageElement())) {
aError.ThrowInvalidStateError("Passed-in image is \"broken\"");
}
return;

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

@ -27,13 +27,15 @@ function startTest(test, token)
canvas.height = video.videoHeight;
document.body.appendChild(canvas);
var ctx = canvas.getContext("2d");
var threwError = false;
try {
ctx.drawImage(video, 0, 0);
} catch (ex) {
threwError = true;
ctx.drawImage(video, 0, 0);
if (canvas.width || canvas.height) {
let pixels = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
for (let byte of pixels) {
if (byte != 0) {
ok(false, "Should not draw EME video to canvas");
}
}
}
ok(threwError, TimeStamp(token) + " - Should throw an error when trying to draw EME video to canvas.");
p1.resolve();
});

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

@ -33,14 +33,13 @@ function onLoadedData_Audio(e) {
is(t.mozPaintedFrames, 0, t.name + ": mozPaintedFrames should be zero when there is no video.");
is(t.mozFrameDelay, 0, t.name + ": mozFrameDelay should be zero when there is no video.");
var c = document.getElementsByTagName("canvas")[0].getContext("2d");
var threw = false;
try {
c.drawImage(t, 0, 0, t.videoHeight, t.videoWidth);
} catch (ex) {
ok(true, t.name + ": Trying to draw to a canvas should throw, since we don't have a frame anymore");
finish(t);
return;
threw = true;
}
ok(false, t.name + ": We should not succeed to draw a video frame on the canvas.");
ok(!threw, t.name + ": Even though we don't succeed to draw a video frame on the canvas, we shouldn't throw.");
finish(t);
}

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

@ -3,6 +3,7 @@
if (os == "win") and fission and debug: ["OK", "TIMEOUT"]
if (os == "win") and fission and not debug: ["OK", "TIMEOUT"]
if (os == "mac") and not debug: ["OK", "TIMEOUT"]
if (os == "android"): ["OK", "TIMEOUT"]
[Signal detector detects track change within reasonable time]
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1526207
expected:
@ -10,5 +11,4 @@
if (os == "win") and fission and debug: ["PASS", "TIMEOUT"]
if (os == "win") and fission and not debug: ["PASS", "TIMEOUT"]
if (os == "mac") and not debug: ["PASS", "TIMEOUT"]
if os == "android": FAIL
if os == "android": ["FAIL", "TIMEOUT"]

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

@ -1,5 +1,7 @@
[RTCRtpSender-replaceTrack.https.html]
expected:
if (os == "android") and nightly_build: [OK, TIMEOUT]
[ReplaceTrack transmits the new track not the old track]
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1526207
expected:
if (os == "android") and nightly_build: FAIL
if (os == "android") and nightly_build: [FAIL, TIMEOUT]