mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 663194 - Calling drawImage with zero-size canvas should throw INVALID_STATE_ERR; r=sicking
This commit is contained in:
parent
a2b407958f
commit
a6c4503b05
@ -3291,8 +3291,14 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
|
||||
}
|
||||
|
||||
double sx,sy,sw,sh;
|
||||
double dx,dy,dw,dh;
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(imgElt);
|
||||
nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(content);
|
||||
if (canvas) {
|
||||
nsIntSize size = canvas->GetSize();
|
||||
if (size.width == 0 || size.height == 0) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
gfxMatrix matrix;
|
||||
nsRefPtr<gfxPattern> pattern;
|
||||
@ -3334,6 +3340,8 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
}
|
||||
}
|
||||
|
||||
double sx,sy,sw,sh;
|
||||
double dx,dy,dw,dh;
|
||||
if (optional_argc == 0) {
|
||||
dx = a1;
|
||||
dy = a2;
|
||||
|
@ -79,6 +79,7 @@ _TEST_FILES_0 = \
|
||||
test_2d.composite.uncovered.image.destination-in.html \
|
||||
test_2d.composite.uncovered.image.source-in.html \
|
||||
test_2d.composite.uncovered.image.source-out.html \
|
||||
test_2d.drawImage.zerocanvas.html \
|
||||
test_toDataURL_lowercase_ascii.html \
|
||||
test_toDataURL_parameters.html \
|
||||
test_mozGetAsFile.html \
|
||||
|
56
content/canvas/test/test_2d.drawImage.zerocanvas.html
Normal file
56
content/canvas/test/test_2d.drawImage.zerocanvas.html
Normal file
@ -0,0 +1,56 @@
|
||||
<!DOCTYPE HTML>
|
||||
<title>Canvas test: 2d.drawImage.zerocanvas</title>
|
||||
<script src="/MochiKit/MochiKit.js"></script>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
<body>
|
||||
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||
<script>
|
||||
function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
|
||||
var pixel = ctx.getImageData(x, y, 1, 1);
|
||||
var pr = pixel.data[0],
|
||||
pg = pixel.data[1],
|
||||
pb = pixel.data[2],
|
||||
pa = pixel.data[3];
|
||||
ok(r-d <= pr && pr <= r+d &&
|
||||
g-d <= pg && pg <= g+d &&
|
||||
b-d <= pb && pb <= b+d &&
|
||||
a-d <= pa && pa <= a+d,
|
||||
"pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
MochiKit.DOM.addLoadEvent(function () {
|
||||
|
||||
var canvas = document.getElementById('c');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.fillStyle = '#0f0';
|
||||
ctx.fillRect(0, 0, 100, 50);
|
||||
|
||||
var canvas2 = document.createElement('canvas');
|
||||
canvas2.width = 0;
|
||||
canvas2.height = 10;
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(canvas2, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
|
||||
|
||||
canvas2.width = 10;
|
||||
canvas2.height = 0;
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(canvas2, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
|
||||
|
||||
canvas2.width = 0;
|
||||
canvas2.height = 0;
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(canvas2, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
|
||||
|
||||
isPixel(ctx, 50,25, 0,255,0,255, "50,25", "0,255,0,255", 2);
|
||||
|
||||
SimpleTest.finish();
|
||||
|
||||
});
|
||||
</script>
|
||||
|
@ -68,6 +68,13 @@ public:
|
||||
nsHTMLCanvasElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLCanvasElement();
|
||||
|
||||
static nsHTMLCanvasElement* FromContent(nsIContent* aPossibleCanvas)
|
||||
{
|
||||
if (!aPossibleCanvas || !aPossibleCanvas->IsHTML(nsGkAtoms::canvas)) {
|
||||
return nsnull;
|
||||
}
|
||||
return static_cast<nsHTMLCanvasElement*>(aPossibleCanvas);
|
||||
}
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user