зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
50e0643986
Коммит
96e56e3d39
|
@ -4518,11 +4518,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,13 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче