Commit a8274ee6 authored by yiyix's avatar yiyix Committed by Commit Bot

Move tests from fast/canvas-api to wpt tests

Moved 5 more tests from fast/canvas-api to wpt tests: Deleted 1 due to
duplications, arc-crash.html, created 4 new tests.

Bug: 1071659

Change-Id: Ie6f0b3b5854533f81dd8a576ff7e03ae3692b53a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405314
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: default avatarAaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808660}
parent 49bd7ad7
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<canvas id='c' style="padding-right: 4294967292; border-right: 124px solid black;"></canvas>
<script>
test(function(t) {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
ctx.getImageData(0, 0, 1, 1);
}, '// The test case passes by not crashing.')
</script>
\ No newline at end of file
<!DOCTYPE html>
<body>
<p>Tests that the close method of ImageBitmap does dispose the image data.</p>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(function(t) {
var worker = new Worker('worker-onmessage-noop.js');
var imgHeight = 10;
var imgWidth = 10;
var imageData = new ImageData(10, 10);
var bitmap;
var ctx;
return createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");
// Apply structured clone to the bitmap, nothing should be changed
worker.postMessage({data: bitmap});
assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");
// After calling close, the image data associated with the bitmap should no longer exist
bitmap.close();
assert_equals(bitmap.width, 0, "bitmap.width = 0");
assert_equals(bitmap.height, 0, "bitmap.height = 0");
var canvas = document.createElement("canvas");
canvas.width = imgWidth;
canvas.height = imgHeight;
ctx = canvas.getContext("2d");
assert_throws_dom("InvalidStateError", function() { ctx.drawImage(bitmap, 0, 0); });
// Try to apply structured clone to an already closed bitmap
try {
worker.postMessage({data: bitmap});
throw new Error("Apply clone to an closed bitmap should be rejected");
}
catch(ex) {
// Apply structured clone to an already closed bitmap is rejected as expected.
}
// Try to apply transferring to an already closed bitmap
try {
worker.postMessage({data: bitmap}, [bitmap]);
throw new Error("Apply transferring to an closed bitmap should be rejected");
} catch(ex) {
// Apply structured clone to an already closed bitmap is rejected as expected.
}
// Calling createImageBitmap from a closed bitmap should be rejected
return createImageBitmap(bitmap).then(function() {
throw new Error("createImageBitmap from a closed bitmap should be rejected");
}, ex => {
// Calling createImageBitmap from a closed ImageBitmap is rejected as expected.
});
}).then(() => {
// Call close to a already closed bitmap should be noop.
bitmap.close();
assert_equals(bitmap.width, 0, "bitmap.height = 0");
assert_equals(bitmap.height, 0, "bitmap.height = 0");
return createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");
// Transfer the bitmap to a worker
worker.postMessage({data: bitmap}, [bitmap]);
// After transferring, the bitmap is neutered.
assert_equals(bitmap.width, 0, "bitmap.height = 0");
assert_equals(bitmap.height, 0, "bitmap.height = 0");
// Calling close to a neutered bitmap should be noop.
bitmap.close();
assert_equals(bitmap.width, 0, "bitmap.height = 0");
assert_equals(bitmap.height, 0, "bitmap.height = 0");
});
}).catch(function(ex) {
throw new Error("No exception should be thrown.");
})
});
</script>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<canvas id="canvas" width="0" height="0"></canvas>
<body>
<script>
test(function(t) {
test(function() {
var context = document.getElementById("canvas").getContext("2d");
context.fillStyle = "green";
}, 'This test ensures that accessing the context of a zero sized canvas does not crash.');
......
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id="test" width="100" height="100"></canvas><br />
<script>
test(function(t) {
var canvas = document.getElementById('test');
var context = canvas.getContext('2d');
context.fillStyle = '#f00';
context.fillRect(0, 0, canvas.width, canvas.height);
try {
context.arc(10, 10, 20, 20, 1.0/0.0, true);
context.arc(10, 10, 20, 20, 1.0/0.0, true);
context.arc(10, 10, 1.0/0.0, 20, 20, true);
context.arc(10, 10, 20, 1.0/0.0, 20, true);
context.arc(10, 1.0/0.0, 10, 20, 20, true);
context.arc(1.0/0.0, 10, 10, 20, 20, true);
context.arc(10, 10, 20, 20, 1.0/0.0, false);
context.arc(10, 10, 1.0/0.0, 20, 20, false);
context.arc(10, 10, 20, 1.0/0.0, 20, false);
context.arc(10, 1.0/0.0, 10, 20, 20, false);
context.arc(1.0/0.0, 10, 10, 20, 20, false);
} catch (e) {
}
context.fillStyle = '#0f0';
context.fillRect(0, 0, canvas.width, canvas.height);
}, "This tests that we don't crash when passing inf as a parameter to arc");
</script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id='c' style="padding-right: 4294967292; border-right: 124px solid black;"></canvas>
<script>
test(function(t) {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
ctx.getImageData(0, 0, 1, 1);
}, 'Regression test for crbug.com/544329. Test passes by not crashing.');
</script>
\ No newline at end of file
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
jsTestIsAsync = true;
var worker = new Worker('./resources/worker-onmessage-noop.js');
description("Tests that the close method of ImageBitmap does dispose the image data");
var imgHeight = 10;
var imgWidth = 10;
var imageData = new ImageData(10, 10);
var bitmap;
var ctx;
createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// Apply structured clone to the bitmap, nothing should be changed
worker.postMessage({data: bitmap});
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// After calling close, the image data associated with the bitmap should no longer exist
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
var canvas = document.createElement("canvas");
canvas.width = imgWidth;
canvas.height = imgHeight;
ctx = canvas.getContext("2d");
shouldThrow("ctx.drawImage(bitmap, 0, 0)");
// Try to apply structured clone to an already closed bitmap
try {
worker.postMessage({data: bitmap});
testFailed("Apply structured clone to an already closed bitmap passed unexpectedly");
} catch(ex) {
testPassed("Apply structured clone to an already closed bitmap is rejected as expected: " + ex);
}
// Try to apply transferring to an already closed bitmap
try {
worker.postMessage({data: bitmap}, [bitmap]);
testFailed("Apply transferring to an already closed bitmap passed unexpectedly");
} catch(ex) {
testPassed("Apply transferring to an already closed bitmap is rejected as expected: " + ex);
}
// Calling createImageBitmap from a closed bitmap should be rejected
return createImageBitmap(bitmap).then(function() {
testFailed("Promise accepted, expected to be rejected");
finishJSTest();
}, ex => {
testPassed("createImageBitmap from a closed ImageBitmap was rejected. " + ex);
});
}).then(() => {
// Call close to a already closed bitmap should be noop.
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
return createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// Transfer the bitmap to a worker
worker.postMessage({data: bitmap}, [bitmap]);
// After transferring, the bitmap is neutered.
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
// Calling close to a neutered bitmap should be noop.
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
});
}).catch(function(ex) {
testFailed("Unexpected failure: " + ex);
}).then(() => { finishJSTest(); });
</script>
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