Commit 4962b834 authored by zakerinasab's avatar zakerinasab Committed by Commit bot

Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests.

This change replaces js-test.js assertions with testharness.js assertions.
The expectation files are removed as they are not needed anymore.
To simplify review and landing, each change corrects at most 10 tests.

BUG=639732

Review-Url: https://codereview.chromium.org/2700823002
Cr-Commit-Position: refs/heads/master@{#453237}
parent 45d10534
This test ensures that changing the context does not crash.
This test ensures that changing the context does not crash. <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id="canvas"></canvas><br /> <canvas id="canvas"></canvas><br />
<script>
if (window.testRunner)
testRunner.dumpAsText();
var canvas = document.getElementById("canvas");
var ctx1 = canvas.getContext("2d");
var ctx2 = canvas.getContext("");
ctx1.save();
canvas.parentNode.removeChild(canvas); <script>
test(function(t) {
if (window.GCController) var canvas = document.getElementById("canvas");
GCController.collect(); var ctx1 = canvas.getContext("2d");
var ctx2 = canvas.getContext("");
ctx1.save();
ctx1.save(); canvas.parentNode.removeChild(canvas);
if (window.GCController)
GCController.collect();
ctx1.save();
}, 'This test ensures that changing the context does not crash.');
</script> </script>
</body>
PASS canvas.drawFocusIfNeeded(null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Element'..
PASS canvas.drawFocusIfNeeded(); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': 1 argument required, but only 0 present..
PASS canvas.drawFocusIfNeeded(null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Element'..
PASS data[0] != 0 || data[1] != 0 || data[2] != 0 is true
PASS data[0] == 0 && data[1] == 0 && data[2] == 0 is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML> <script src="../../resources/testharness.js"></script>
<p>This test passes by not crashing.</p> <script src="../../resources/testharnessreport.js"></script>
<canvas id="canvas"> <canvas id="canvas">
<button id="button"></button> <button id="button"></button>
</canvas> </canvas>
<script> <script>
if (window.testRunner) test(function(t) {
testRunner.dumpAsText();
var button = document.getElementById("button"); var button = document.getElementById("button");
button.focus(); button.focus();
var canvas = document.getElementById("canvas") var canvas = document.getElementById("canvas")
var ctx = canvas.getContext("2d"); var ctx = canvas.getContext("2d");
ctx.rect(0, 0, 10, 10); ctx.rect(0, 0, 10, 10);
canvas.style.display = "none"; canvas.style.display = "none";
ctx.drawFocusIfNeeded(button); ctx.drawFocusIfNeeded(button);
</script>
}, 'Test that drawFocusIfNeeded does not crash.');
</script>
\ No newline at end of file
PASS data[0] != 0 || data[1] != 0 || data[2] != 0 is true
PASS data[0] == 0 && data[1] == 0 && data[2] == 0 is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<title>Canvas test: drawFocusIfNeeded</title>
<script src="../../resources/js-test.js"></script>
</head>
<body style="padding: 0; margin: 0">
<canvas id="canvas" class="output" width="300" height="350"> <canvas id="canvas" class="output" width="300" height="350">
<button id="button1"></button> <button id="button1"></button>
<button id="button2"></button> <button id="button2"></button>
</canvas> </canvas>
<script> <script>
if (window.testRunner)
testRunner.dumpAsText();
var canvas = document.getElementById("canvas").getContext("2d"); var canvas = document.getElementById("canvas").getContext("2d");
document.getElementById("button1").addEventListener('focus', function() { document.getElementById("button1").addEventListener('focus', function() {
...@@ -28,17 +21,21 @@ document.getElementById("button1").addEventListener('focus', function() { ...@@ -28,17 +21,21 @@ document.getElementById("button1").addEventListener('focus', function() {
canvas.drawFocusIfNeeded(document.getElementById("button2")); canvas.drawFocusIfNeeded(document.getElementById("button2"));
}); });
document.getElementById("button1").focus(); test(function(t) {
// The top rect's focus ring is tied to button1, which is focused.
// It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data;
shouldBe("data[0] != 0 || data[1] != 0 || data[2] != 0", "true");
// The bottom rect"s focus ring is tied to button2, which is not focused. document.getElementById("button1").focus();
imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data; // The top rect's focus ring is tied to button1, which is focused.
shouldBe("data[0] == 0 && data[1] == 0 && data[2] == 0", "true"); // It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data;
assert_true(data[0] != 0 || data[1] != 0 || data[2] != 0);
// The bottom rect"s focus ring is tied to button2, which is not focused.
imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data;
assert_true(data[0] == 0 && data[1] == 0 && data[2] == 0);
}, 'Test that drawFocusIfNeeded does not crash on event.');
</script> </script>
</body> </body>
PASS window.pageXOffset is 0
PASS window.pageXOffset is >= minXOffset
PASS maxXOffset is >= window.pageXOffset
PASS window.pageXOffset is >= minXOffset
PASS maxXOffset is >= window.pageXOffset
PASS window.pageXOffset is >= minXOffset
PASS maxXOffset is >= window.pageXOffset
PASS successfullyParsed is true
TEST COMPLETE
1000-pixel box
<!DOCTYPE HTML> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<title>Canvas test: drawFocusIfNeeded scrolls</title>
<script src="../../resources/js-test.js"></script>
</head>
<body style="padding: 0; margin: 0">
<div style="width: 6500px;"> <div style="width: 6500px;">
<div style="float: left; border: 1px solid #000; width: 1000px; height: 300px"> <div style="float: left; border: 1px solid #000; width: 1000px; height: 300px">
1000-pixel box 1000-pixel box
...@@ -13,49 +10,50 @@ ...@@ -13,49 +10,50 @@
<button id="right_button"></button> <button id="right_button"></button>
</canvas> </canvas>
</div> </div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var LEFT_BUTTON_X_POS = 50;
var RIGHT_BUTTON_X_POS = 4750;
function draw() {
context.beginPath();
context.rect(LEFT_BUTTON_X_POS, 50, 200, 100);
context.fillStyle = "#ccf";
context.fill();
context.drawFocusIfNeeded(document.getElementById("left_button"));
context.beginPath();
context.rect(RIGHT_BUTTON_X_POS, 50, 200, 100);
context.fillStyle = "#fcc";
context.fill();
context.drawFocusIfNeeded(document.getElementById("right_button"));
}
document.getElementById("right_button").focus();
window.scrollTo(0, 0);
shouldBe("window.pageXOffset", "0");
draw();
var minXOffset = RIGHT_BUTTON_X_POS + canvas.offsetLeft - window.innerWidth;
var maxXOffset = RIGHT_BUTTON_X_POS + canvas.offsetLeft;
shouldBeGreaterThanOrEqual("window.pageXOffset", "minXOffset");
shouldBeGreaterThanOrEqual("maxXOffset", "window.pageXOffset");
document.getElementById("left_button").focus();
shouldBeGreaterThanOrEqual("window.pageXOffset", "minXOffset");
shouldBeGreaterThanOrEqual("maxXOffset", "window.pageXOffset");
draw();
minXOffset = LEFT_BUTTON_X_POS + canvas.offsetLeft - window.innerWidth;
maxXOffset = LEFT_BUTTON_X_POS + canvas.offsetLeft;
shouldBeGreaterThanOrEqual("window.pageXOffset", "minXOffset");
shouldBeGreaterThanOrEqual("maxXOffset", "window.pageXOffset");
<script>
test(function(t) {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var LEFT_BUTTON_X_POS = 50;
var RIGHT_BUTTON_X_POS = 4750;
function draw() {
context.beginPath();
context.rect(LEFT_BUTTON_X_POS, 50, 200, 100);
context.fillStyle = "#ccf";
context.fill();
context.drawFocusIfNeeded(document.getElementById("left_button"));
context.beginPath();
context.rect(RIGHT_BUTTON_X_POS, 50, 200, 100);
context.fillStyle = "#fcc";
context.fill();
context.drawFocusIfNeeded(document.getElementById("right_button"));
}
document.getElementById("right_button").focus();
window.scrollTo(0, 0);
assert_true(window.pageXOffset == 0);
draw();
var minXOffset = RIGHT_BUTTON_X_POS + canvas.offsetLeft - window.innerWidth;
var maxXOffset = RIGHT_BUTTON_X_POS + canvas.offsetLeft;
assert_true(window.pageXOffset >= minXOffset);
assert_true(maxXOffset >= window.pageXOffset);
document.getElementById("left_button").focus();
assert_true(window.pageXOffset >= minXOffset);
assert_true(maxXOffset >= window.pageXOffset);
draw();
minXOffset = LEFT_BUTTON_X_POS + canvas.offsetLeft - window.innerWidth;
maxXOffset = LEFT_BUTTON_X_POS + canvas.offsetLeft;
assert_true(window.pageXOffset >= minXOffset);
assert_true(maxXOffset >= window.pageXOffset);
}, 'Canvas test: drawFocusIfNeeded scrolls');
</script> </script>
</body> </body>
PASS canvas.drawFocusIfNeeded(undefined); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Element'..
PASS canvas.drawFocusIfNeeded(undefined, undefined); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'..
PASS canvas.drawFocusIfNeeded(null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Element'..
PASS canvas.drawFocusIfNeeded(null, null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'..
PASS canvas.drawFocusIfNeeded(); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': 1 argument required, but only 0 present..
PASS canvas.drawFocusIfNeeded(null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Element'..
PASS canvas.drawFocusIfNeeded(null, null); threw exception TypeError: Failed to execute 'drawFocusIfNeeded' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'..
PASS data[0] != 0 || data[1] != 0 || data[2] != 0 is true
PASS data[0] == 0 && data[1] == 0 && data[2] == 0 is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<title>Canvas test: drawFocusIfNeeded with Path2D</title>
<script src="../../resources/js-test.js"></script>
</head>
<body style="padding: 0; margin: 0">
<canvas id="canvas" class="output" width="300" height="350"> <canvas id="canvas" class="output" width="300" height="350">
<button id="button1"></button> <button id="button1"></button>
<button id="button2"></button> <button id="button2"></button>
</canvas> </canvas>
<script>
if (window.testRunner)
testRunner.dumpAsText();
document.getElementById("button1").focus();
var canvas = document.getElementById("canvas").getContext("2d");
shouldThrow('canvas.drawFocusIfNeeded(undefined);'); <script>
shouldThrow('canvas.drawFocusIfNeeded(undefined, undefined);'); test(function(t) {
shouldThrow('canvas.drawFocusIfNeeded(null);');
shouldThrow('canvas.drawFocusIfNeeded(null, null);');
shouldThrow('canvas.drawFocusIfNeeded();');
var path = new Path2D();
path.rect(50, 50, 200, 100);
canvas.fillStyle = "#ccf";
canvas.fill(path);
// re-test null case after having defined a path (regression test for crbug.com/353248)
shouldThrow('canvas.drawFocusIfNeeded(null);');
shouldThrow('canvas.drawFocusIfNeeded(null, null);');
canvas.drawFocusIfNeeded(path, document.getElementById("button1"));
path = new Path2D();
path.rect(50, 200, 200, 100);
canvas.fillStyle = "#cfc";
canvas.fill(path);
canvas.drawFocusIfNeeded(path, document.getElementById("button2"));
// The top rect"s focus ring is tied to button1, which is focused.
// It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data;
shouldBe("data[0] != 0 || data[1] != 0 || data[2] != 0", "true");
// The bottom rect"s focus ring is tied to button2, which is not focused. document.getElementById("button1").focus();
imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data; var canvas = document.getElementById("canvas").getContext("2d");
shouldBe("data[0] == 0 && data[1] == 0 && data[2] == 0", "true");
assert_throws(null, function(){canvas.drawFocusIfNeeded(undefined);});
assert_throws(null, function(){canvas.drawFocusIfNeeded(undefined, undefined);});
assert_throws(null, function(){canvas.drawFocusIfNeeded(null);});
assert_throws(null, function(){canvas.drawFocusIfNeeded(null, null);});
assert_throws(null, function(){canvas.drawFocusIfNeeded();});
var path = new Path2D();
path.rect(50, 50, 200, 100);
canvas.fillStyle = "#ccf";
canvas.fill(path);
// re-test null case after having defined a path (regression test for crbug.com/353248)
assert_throws(null, function(){canvas.drawFocusIfNeeded(null);});
assert_throws(null, function(){canvas.drawFocusIfNeeded(null, null);});
canvas.drawFocusIfNeeded(path, document.getElementById("button1"));
path = new Path2D();
path.rect(50, 200, 200, 100);
canvas.fillStyle = "#cfc";
canvas.fill(path);
canvas.drawFocusIfNeeded(path, document.getElementById("button2"));
// The top rect"s focus ring is tied to button1, which is focused.
// It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data;
assert_true(data[0] != 0 || data[1] != 0 || data[2] != 0);
// The bottom rect"s focus ring is tied to button2, which is not focused.
imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data;
assert_true(data[0] == 0 && data[1] == 0 && data[2] == 0);
}, 'Canvas test: drawFocusIfNeeded with Path2D');
</script> </script>
</body> </body>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<head> <head>
<title>Canvas test: drawFocusIfNeeded</title> <script src="../../resources/testharness.js"></script>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body style="padding: 0; margin: 0">
<canvas id="canvas" class="output" width="300" height="350"> <canvas id="canvas" class="output" width="300" height="350">
<button id="button1"></button> <button id="button1"></button>
<button id="button2"></button> <button id="button2"></button>
</canvas> </canvas>
<script> <script>
if (window.testRunner) test(function(t) {
testRunner.dumpAsText();
document.getElementById("button1").focus(); document.getElementById("button1").focus();
var canvas = document.getElementById("canvas").getContext("2d"); var canvas = document.getElementById("canvas").getContext("2d");
shouldThrow('canvas.drawFocusIfNeeded(null);'); assert_throws(null, function(){canvas.drawFocusIfNeeded(null);});
shouldThrow('canvas.drawFocusIfNeeded();'); assert_throws(null, function(){canvas.drawFocusIfNeeded();});
canvas.beginPath(); canvas.beginPath();
canvas.rect(50, 50, 200, 100); canvas.rect(50, 50, 200, 100);
canvas.fillStyle = "#ccf"; canvas.fillStyle = "#ccf";
canvas.fill(); canvas.fill();
// re-test null case after having defined a path (regression test for crbug.com/353248) // re-test null case after having defined a path (regression test for crbug.com/353248)
shouldThrow('canvas.drawFocusIfNeeded(null);'); assert_throws(null, function(){canvas.drawFocusIfNeeded(null);});
canvas.drawFocusIfNeeded(document.getElementById("button1")); canvas.drawFocusIfNeeded(document.getElementById("button1"));
canvas.beginPath(); canvas.beginPath();
canvas.rect(50, 200, 200, 100); canvas.rect(50, 200, 200, 100);
canvas.fillStyle = "#cfc"; canvas.fillStyle = "#cfc";
canvas.fill(); canvas.fill();
canvas.drawFocusIfNeeded(document.getElementById("button2")); canvas.drawFocusIfNeeded(document.getElementById("button2"));
// The top rect"s focus ring is tied to button1, which is focused. // The top rect's focus ring is tied to button1, which is focused.
// It should have an outline in some color other than the background color. // It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1); var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data; var data = imageData.data;
shouldBe("data[0] != 0 || data[1] != 0 || data[2] != 0", "true"); assert_true(data[0] != 0 || data[1] != 0 || data[2] != 0);
// The bottom rect"s focus ring is tied to button2, which is not focused. // The bottom rect"s focus ring is tied to button2, which is not focused.
imageData = canvas.getImageData(49, 200, 1, 1); imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data; data = imageData.data;
shouldBe("data[0] == 0 && data[1] == 0 && data[2] == 0", "true"); assert_true(data[0] == 0 && data[1] == 0 && data[2] == 0);
}, 'Canvas test: drawFocusIfNeeded');
</script> </script>
</body> </body>
This test checks behavior of drawImage on a canvas that failed to allocate its backing store. This test passes by not crashing.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <script src="../../resources/testharness.js"></script>
<html> <script src="../../resources/testharnessreport.js"></script>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<script> <script>
description("This test checks behavior of drawImage on a canvas that failed to allocate its backing store. This test passes by not crashing."); test(function(){
var canvas1 = document.createElement("canvas"); var canvas1 = document.createElement("canvas");
var ctx1 = canvas1.getContext('2d'); var ctx1 = canvas1.getContext('2d');
var canvas2 = document.createElement("canvas"); var canvas2 = document.createElement("canvas");
...@@ -13,6 +12,6 @@ ...@@ -13,6 +12,6 @@
canvas2.height = 1000000; canvas2.height = 1000000;
var ctx2 = canvas2.getContext('2d'); var ctx2 = canvas2.getContext('2d');
ctx2.drawImage(canvas1, 0, 0); ctx2.drawImage(canvas1, 0, 0);
}, "This test checks behavior of drawImage on a canvas that failed to allocate its backing store. This test passes by not crashing.");
</script> </script>
</body>
</html>
This test checks behavior of Canvas::drawImage with a broken source image.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS ctx.drawImage(null, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(null, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(undefined, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(undefined, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'.
PASS ctx.drawImage(invalidImage, 0, 0) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 20, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 0, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 0, 20, 0, 0, 20, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <script src="../../resources/testharness.js"></script>
<html> <script src="../../resources/testharnessreport.js"></script>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<script> <script>
window.jsTestIsAsync = true;
description("This test checks behavior of Canvas::drawImage with a broken source image.");
// Create an image with invalid data. // Create an image with invalid data.
var invalidImage = new Image(); var invalidImage = new Image();
invalidImage.src = 'resources/shadow-offset.js'; invalidImage.src = 'resources/shadow-offset.js';
invalidImage.onerror = draw;
var ctx = document.createElement("canvas").getContext('2d'); var ctx = document.createElement("canvas").getContext('2d');
function draw() { function draw() {
// null and undefined images should throw TypeError // null and undefined images should throw TypeError
shouldThrow("ctx.drawImage(null, 0, 0)"); assert_throws(null, function() {ctx.drawImage(null, 0, 0)});
shouldThrow("ctx.drawImage(null, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(null, 0, 0, 20, 20)});
shouldThrow("ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20)});
shouldThrow("ctx.drawImage(undefined, 0, 0)"); assert_throws(null, function() {ctx.drawImage(undefined, 0, 0)});
shouldThrow("ctx.drawImage(undefined, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(undefined, 0, 0, 20, 20)});
shouldThrow("ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20)});
// broken images should not throw // broken images should not throw
shouldThrow("ctx.drawImage(invalidImage, 0, 0)"); assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0)});
shouldThrow("ctx.drawImage(invalidImage, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 20, 20)});
shouldThrow("ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20)});
shouldThrow("ctx.drawImage(invalidImage, 0, 0, 0, 20)"); assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 0, 20)});
shouldThrow("ctx.drawImage(invalidImage, 0, 0, 0, 20, 0, 0, 20, 20)"); assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 0, 20, 0, 0, 20, 20)});
}
async_test(t => {
invalidImage.onerror = function() {
t.step(draw);
t.done();
}
}, "This test checks behavior of Canvas::drawImage with a broken source image.");
finishJSTest();
}
</script> </script>
</body> </body>
</html> </html>
Series of tests to ensure correct behaviour on negative source/destination of a HTMLCanvasElement
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS imgdata[4] is 0
PASS imgdata[5] is 255
PASS imgdata[6] is 0
PASS imgdata[0] is 255
PASS imgdata[1] is 0
PASS imgdata[2] is 0
PASS imgdata[4] is 0
PASS imgdata[5] is 0
PASS imgdata[6] is 0
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!-- Test based on that found at <!-- Test based on that found at
http://philip.html5.org/tests/canvas/suite/tests/2d.drawImage.negativesource.html http://philip.html5.org/tests/canvas/suite/tests/2d.drawImage.negativesource.html
--> -->
<html> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<canvas id="canvas" width="100" height="100"></canvas> <canvas id="canvas" width="100" height="100"></canvas>
<script src="drawImage-with-negative-source-destination.js"></script> <script>
</body>
</html> test(function(){
var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 100;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);
ctx2.fillStyle = '#0f0';
ctx2.fillRect(0, 50, 100, 50);
var canvas = document.getElementById('canvas').getContext('2d');
canvas.drawImage(canvas2, 100, 50, -50, 50, 0, 0, 50, 50);
canvas.drawImage(canvas2, 100, 100, -50, -50, 0, 100, 50, -50);
canvas.drawImage(canvas2, 0, 100, 100, -50, 100, 100, -50, -50);
canvas.drawImage(canvas2, 0, 50, 100, 50, 100, 0, -50, 50);
var imageData = canvas.getImageData(1, 0, 1, 1).data;
assert_array_equals(imageData.slice(0,3), [0, 255, 0]);
// test width or height -1
canvas.fillStyle = '#000';
canvas.fillRect(0, 0, 1, 2);
canvas.drawImage(canvas2, 0, 0, 1, 1, 1, 1, -1, -1);
var imageData = canvas.getImageData(0, 0, 1, 2).data;
assert_array_equals(imageData.slice(0,3), [255, 0, 0]);
assert_array_equals(imageData.slice(4,7), [0, 0, 0]);
}, "Series of tests to ensure correct behaviour on negative source/destination of a HTMLCanvasElement");
</script>
\ No newline at end of file
description("Series of tests to ensure correct behaviour on negative source/destination of a HTMLCanvasElement");
var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 100;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);
ctx2.fillStyle = '#0f0';
ctx2.fillRect(0, 50, 100, 50);
var canvas = document.getElementById('canvas').getContext('2d');
canvas.drawImage(canvas2, 100, 50, -50, 50, 0, 0, 50, 50);
canvas.drawImage(canvas2, 100, 100, -50, -50, 0, 100, 50, -50);
canvas.drawImage(canvas2, 0, 100, 100, -50, 100, 100, -50, -50);
canvas.drawImage(canvas2, 0, 50, 100, 50, 100, 0, -50, 50);
var imageData = canvas.getImageData(0, 0, 100, 100);
var imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "255");
shouldBe("imgdata[6]", "0");
// test width or height -1
canvas.fillStyle = '#000';
canvas.fillRect(0, 0, 1, 2);
canvas.drawImage(canvas2, 0, 0, 1, 1, 1, 1, -1, -1);
var imageData = canvas.getImageData(0, 0, 1, 2);
var imgdata = imageData.data;
shouldBe("imgdata[0]", "255");
shouldBe("imgdata[1]", "0");
shouldBe("imgdata[2]", "0");
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "0");
shouldBe("imgdata[6]", "0");
This test checks behavior of valid arguments to Canvas::drawImage that use a valid source image.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS ctx.drawImage() threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': 3 arguments required, but only 0 present..
PASS ctx.drawImage(myImage) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': 3 arguments required, but only 1 present..
PASS ctx.drawImage(myImage, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': 3 arguments required, but only 2 present..
PASS ctx.drawImage(myImage, 0, 0) did not throw exception.
PASS ctx.drawImage(myImage, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 0, 0, 0, 0) did not throw exception.
PASS ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 0, 0) did not throw exception.
PASS ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0, 20, 20, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0, 0, 20) did not throw exception.
PASS ctx.drawImage(new Image(), 0, 0, 0, 20, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0, 0, 0) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 0, 0) did not throw exception.
PASS ctx.drawImage(bitmap, 20, 20, -20, 0, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 0, 20, 0, 20, 20, -20, -20) did not throw exception.
PASS ctx.drawImage(bitmap, 20, 20, -20, 0, 20, 20, -20, -20) did not throw exception.
PASS ctx.drawImage(bitmap, -10, 0, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 10, 0, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, -10, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 0, 10, 52, 64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, -10, -10, 72, 84, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 42, 64, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 62, 64, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 52, 54, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 52, 74, -52, -64, 0, 0, 20, 20) did not throw exception.
PASS ctx.drawImage(bitmap, 62, 74, -72, -84, 0, 0, 20, 20) did not throw exception.
PASS successfullyParsed is true
TEST COMPLETE
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