Source/WebCore: Unwarranted DOM Exception when canvas2D drawImage is called with src

rect out of bounds
https://bugs.webkit.org/show_bug.cgi?id=65709

Patch by Justin Novosad <junov@chromium.org> on 2011-09-23
Reviewed by Oliver Hunt.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):
Return early without throwing an exception if source rectangle is out of
bounds to match the spec.

LayoutTests: Unwarranted DOM Exception when canvas2D drawImage is called with src
rect is out of bounds
https://bugs.webkit.org/show_bug.cgi?id=65709

Patch by Justin Novosad <junov@chromium.org> on 2011-09-23
Reviewed by Oliver Hunt.

* fast/canvas/drawImage-with-invalid-args-expected.txt:
* fast/canvas/drawImage-with-invalid-args.html:
This test covers (among other things) cases where the source rectangle is
_completely_ outside the bounds of the source image.  It was modified to no
longer expect DOM exceptions
* platform/chromium/test_expectations.txt:
Out-dated test canvas/philip/tests/2d.drawImage.outsidesource.html
is now expected to fail
* platform/mac/Skipped:
Skipping canvas/philip/tests/2d.drawImage.outsidesource.html

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95899 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 09b5142d
2011-09-23 Justin Novosad <junov@chromium.org>
Unwarranted DOM Exception when canvas2D drawImage is called with src
rect is out of bounds
https://bugs.webkit.org/show_bug.cgi?id=65709
Reviewed by Oliver Hunt.
* fast/canvas/drawImage-with-invalid-args-expected.txt:
* fast/canvas/drawImage-with-invalid-args.html:
This test covers (among other things) cases where the source rectangle is
_completely_ outside the bounds of the source image. It was modified to no
longer expect DOM exceptions
* platform/chromium/test_expectations.txt:
Out-dated test canvas/philip/tests/2d.drawImage.outsidesource.html
is now expected to fail
* platform/mac/Skipped:
Skipping canvas/philip/tests/2d.drawImage.outsidesource.html
2011-09-23 Mihai Parparita <mihaip@chromium.org>
[Chromium] REGRESSION (r95725): Resizing a window doesn't resize the contents
......@@ -15,16 +15,16 @@ PASS: null image, got exception as expected
PASS: null image, got exception as expected
PASS: null image, got exception as expected
PASS: null image, got exception as expected
PASS: imageRect does not contain sourceRect on the left side, got exception as expected
PASS: imageRect does not contain sourceRect on the right side, got exception as expected
PASS: imageRect does not contain sourceRect on top, got exception as expected
PASS: imageRect does not contain sourceRect on bottom, got exception as expected
PASS: sourceRect is bigger than imageSource on every side, got exception as expected
PASS: negative size of source, imageRect does not contain sourceRect on the left side, got exception as expected
PASS: negative size of source, imageRect does not contain sourceRect on the right side, got exception as expected
PASS: negative size of source, imageRect does not contain sourceRect on top, got exception as expected
PASS: negative size of source, imageRect does not contain sourceRect on bottom, got exception as expected
PASS: negative size of source, imageRect does not contain sourceRect on every side, got exception as expected
PASS: imageRect does not contain sourceRect on the left side
PASS: imageRect does not contain sourceRect on the right side
PASS: imageRect does not contain sourceRect on top
PASS: imageRect does not contain sourceRect on bottom
PASS: sourceRect is bigger than imageSource on every side
PASS: negative size of source, imageRect does not contain sourceRect on the left side
PASS: negative size of source, imageRect does not contain sourceRect on the right side
PASS: negative size of source, imageRect does not contain sourceRect on top
PASS: negative size of source, imageRect does not contain sourceRect on bottom
PASS: negative size of source, imageRect does not contain sourceRect on every side
Test complete.
......@@ -114,63 +114,63 @@
}
try{
ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20);
print("FAIL");
print("PASS: imageRect does not contain sourceRect on the left side");
} catch (e) {
print("PASS: imageRect does not contain sourceRect on the left side, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20);
print("FAIL");
print("PASS: imageRect does not contain sourceRect on the right side");
} catch (e) {
print("PASS: imageRect does not contain sourceRect on the right side, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20);
print("FAIL");
print("PASS: imageRect does not contain sourceRect on top");
} catch (e) {
print("PASS: imageRect does not contain sourceRect on top, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20);
print("FAIL");
print("PASS: imageRect does not contain sourceRect on bottom");
} catch (e) {
print("PASS: imageRect does not contain sourceRect on bottom, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20);
print("FAIL");
print("PASS: sourceRect is bigger than imageSource on every side");
} catch (e) {
print("PASS: sourceRect is bigger than imageSource on every side, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20);
print("FAIL");
print("PASS: negative size of source, imageRect does not contain sourceRect on the left side");
} catch (e) {
print("PASS: negative size of source, imageRect does not contain sourceRect on the left side, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20);
print("FAIL");
print("PASS: negative size of source, imageRect does not contain sourceRect on the right side");
} catch (e) {
print("PASS: negative size of source, imageRect does not contain sourceRect on the right side, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20);
print("FAIL");
print("PASS: negative size of source, imageRect does not contain sourceRect on top");
} catch (e) {
print("PASS: negative size of source, imageRect does not contain sourceRect on top, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20);
print("FAIL");
print("PASS: negative size of source, imageRect does not contain sourceRect on bottom");
} catch (e) {
print("PASS: negative size of source, imageRect does not contain sourceRect on bottom, got exception as expected");
print("FAIL");
}
try{
ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20);
print("FAIL");
print("PASS: negative size of source, imageRect does not contain sourceRect on every side");
} catch (e) {
print("PASS: negative size of source, imageRect does not contain sourceRect on every side, got exception as expected");
print("FAIL");
}
ctx.fillStyle = 'green';
ctx.fillRect(0,0,150,150);
......
......@@ -234,6 +234,11 @@ WONTFIX SKIP : storage/private-browsing-noread-nowrite.html = PASS
// We don't let anyone set status in the browser.
WONTFIX SKIP : plugins/set-status.html = TEXT
// This test is out of date with respect to the latest version of the HTML5 spec
// Test had to be decommissioned to fix https://bugs.webkit.org/show_bug.cgi?id=65709
// We can re-enable the test when it gets changed upstream to become spec-compliant
WONTFIX : canvas/philip/tests/2d.drawImage.outsidesource.html = TEXT
// We don't care about dashboard compatibility mode.
WONTFIX SKIP : http/tests/xmlhttprequest/default-content-type-dashboard.html = FAIL
WONTFIX SKIP : http/tests/xmlhttprequest/svg-created-by-xhr-disallowed-in-dashboard.html = FAIL
......
......@@ -162,6 +162,12 @@ canvas/philip/tests/2d.composite.uncovered.pattern.copy.html
canvas/philip/tests/2d.imageData.object.round.html
canvas/philip/tests/2d.imageData.object.wrap.html
# This canvas test is skipped because it is out of date with respect to
# the current spec, and the fix for https://bugs.webkit.org/show_bug.cgi?id=65709
# which complies with the current spec, makes this test fail by no longer throwing
# exceptions that were previously expected
canvas/philip/tests/2d.drawImage.outsidesource.html
# IndexedDB is not yet enabled.
storage/indexeddb
......
2011-09-23 Justin Novosad <junov@chromium.org>
Unwarranted DOM Exception when canvas2D drawImage is called with src
rect out of bounds
https://bugs.webkit.org/show_bug.cgi?id=65709
Reviewed by Oliver Hunt.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):
Return early without throwing an exception if source rectangle is out of
bounds to match the spec.
2011-09-23 Lukasz Slachciak <l.slachciak@samsung.com>
Printing of notImplemented() when logging enabled.
......@@ -1271,10 +1271,12 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
FloatRect normalizedDstRect = normalizeRect(dstRect);
FloatRect imageRect = FloatRect(FloatPoint(), size(image));
if (!imageRect.contains(normalizedSrcRect) || !srcRect.width() || !srcRect.height()) {
if (!srcRect.width() || !srcRect.height()) {
ec = INDEX_SIZE_ERR;
return;
}
if (!imageRect.contains(normalizedSrcRect))
return;
GraphicsContext* c = drawingContext();
if (!c)
......@@ -1333,14 +1335,14 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const
return;
}
if (!srcCanvasRect.contains(normalizeRect(srcRect)) || !srcRect.width() || !srcRect.height()) {
if (!srcRect.width() || !srcRect.height()) {
ec = INDEX_SIZE_ERR;
return;
}
ec = 0;
if (!dstRect.width() || !dstRect.height())
if (!srcCanvasRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
return;
GraphicsContext* c = drawingContext();
......@@ -1414,12 +1416,12 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRec
return;
FloatRect videoRect = FloatRect(FloatPoint(), size(video));
if (!videoRect.contains(normalizeRect(srcRect)) || !srcRect.width() || !srcRect.height()) {
if (!srcRect.width() || !srcRect.height()) {
ec = INDEX_SIZE_ERR;
return;
}
if (!dstRect.width() || !dstRect.height())
if (!videoRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
return;
GraphicsContext* c = drawingContext();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment