mirror of
https://github.com/servo/servo.git
synced 2025-08-20 12:55:33 +01:00
Update web-platform-tests to revision 58eb04cecbbec2e18531ab440225e38944a9c444
This commit is contained in:
parent
25e8bf69e6
commit
665817d2a6
35333 changed files with 1818077 additions and 16036 deletions
58
tests/wpt/web-platform-tests/2dcontext/imagebitmap/common.js
Normal file
58
tests/wpt/web-platform-tests/2dcontext/imagebitmap/common.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
function testCanvasDisplayingPattern(canvas)
|
||||
{
|
||||
var tolerance = 5; // for creating ImageBitmap from a video, the tolerance needs to be high
|
||||
_assertPixelApprox(canvas, 5,5, 255,0,0,255, "5,5", "255,0,0,255", tolerance);
|
||||
_assertPixelApprox(canvas, 15,5, 0,255,0,255, "15,5", "0,255,0,255", tolerance);
|
||||
_assertPixelApprox(canvas, 5,15, 0,0,255,255, "5,15", "0,0,255,255", tolerance);
|
||||
_assertPixelApprox(canvas, 15,15, 0,0,0,255, "15,15", "0,0,0,255", tolerance);
|
||||
}
|
||||
|
||||
function testDrawImageBitmap(source)
|
||||
{
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = 20;
|
||||
canvas.height = 20;
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
return createImageBitmap(source).then(imageBitmap => {
|
||||
ctx.drawImage(imageBitmap, 0, 0);
|
||||
testCanvasDisplayingPattern(canvas);
|
||||
});
|
||||
}
|
||||
|
||||
function initializeTestCanvas(testCanvas)
|
||||
{
|
||||
testCanvas.width = 20;
|
||||
testCanvas.height = 20;
|
||||
var testCtx = testCanvas.getContext("2d");
|
||||
testCtx.fillStyle = "rgb(255, 0, 0)";
|
||||
testCtx.fillRect(0, 0, 10, 10);
|
||||
testCtx.fillStyle = "rgb(0, 255, 0)";
|
||||
testCtx.fillRect(10, 0, 10, 10);
|
||||
testCtx.fillStyle = "rgb(0, 0, 255)";
|
||||
testCtx.fillRect(0, 10, 10, 10);
|
||||
testCtx.fillStyle = "rgb(0, 0, 0)";
|
||||
testCtx.fillRect(10, 10, 10, 10);
|
||||
}
|
||||
|
||||
function initializeImageData(imgData, width, height)
|
||||
{
|
||||
for (var i = 0; i < width * height * 4; i+=4) {
|
||||
imgData.data[i] = 0;
|
||||
imgData.data[i + 1] = 0;
|
||||
imgData.data[i + 2] = 0;
|
||||
imgData.data[i + 3] = 255; //alpha channel: 255
|
||||
}
|
||||
var halfWidth = width/2;
|
||||
var halfHeight = height/2;
|
||||
// initialize to R, G, B, Black, with each one 10*10 pixels
|
||||
for (var i = 0; i < halfHeight; i++)
|
||||
for (var j = 0; j < halfWidth; j++)
|
||||
imgData.data[i * width * 4 + j * 4] = 255;
|
||||
for (var i = 0; i < halfHeight; i++)
|
||||
for (var j = halfWidth; j < width; j++)
|
||||
imgData.data[i * width * 4 + j * 4 + 1] = 255;
|
||||
for (var i = halfHeight; i < height; i++)
|
||||
for (var j = 0; j < halfWidth; j++)
|
||||
imgData.data[i * width * 4 + j * 4 + 2] = 255;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<title>createImageBitmap + drawImage test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/canvas-tests.js"></script>
|
||||
<script src="common.js"></script>
|
||||
<link rel="stylesheet" href="/common/canvas-tests.css">
|
||||
<body>
|
||||
<script>
|
||||
(function() {
|
||||
promise_test(function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var img = new Image();
|
||||
img.onload = function() { resolve(img); };
|
||||
img.src = "/images/pattern.png";
|
||||
}).then(function(img) {
|
||||
return testDrawImageBitmap(img);
|
||||
});
|
||||
}, "createImageBitmap from a HTMLImageElement, and drawImage on the created ImageBitmap");
|
||||
|
||||
promise_test(function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", '/images/pattern.png');
|
||||
xhr.responseType = 'blob';
|
||||
xhr.send();
|
||||
xhr.onload = function() {
|
||||
blob = xhr.response;
|
||||
resolve(blob);
|
||||
};
|
||||
}).then(function(blob) {
|
||||
return testDrawImageBitmap(blob);
|
||||
});
|
||||
}, "createImageBitmap from a Blob, and drawImage on the created ImageBitmap");
|
||||
|
||||
promise_test(function() {
|
||||
var testCanvas = document.createElement("canvas");
|
||||
initializeTestCanvas(testCanvas);
|
||||
testDrawImageBitmap(testCanvas);
|
||||
}, "createImageBitmap from a HTMLCanvasElement, and drawImage on the created ImageBitmap");
|
||||
|
||||
promise_test(function() {
|
||||
var testCanvas = document.createElement("canvas");
|
||||
initializeTestCanvas(testCanvas);
|
||||
return new Promise(function(resolve, reject) {
|
||||
createImageBitmap(testCanvas).then(function(bitmap) {
|
||||
resolve(bitmap);
|
||||
});
|
||||
}).then(function(bitmap) {
|
||||
return testDrawImageBitmap(bitmap);
|
||||
});
|
||||
}, "createImageBitmap from an ImageBitmap, and drawImage on the created ImageBitmap");
|
||||
|
||||
promise_test(function() {
|
||||
var imgData = new ImageData(20, 20);
|
||||
initializeImageData(imgData, 20, 20);
|
||||
return testDrawImageBitmap(imgData);
|
||||
}, "createImageBitmap from an ImageData, and drawImage on the created ImageBitmap");
|
||||
|
||||
promise_test(function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var video = document.createElement("video");
|
||||
video.oncanplaythrough = function() {
|
||||
resolve(video);
|
||||
};
|
||||
video.src = "/images/pattern.ogv";
|
||||
}).then(function(video) {
|
||||
return testDrawImageBitmap(video);
|
||||
});
|
||||
}, "createImageBitmap from a HTMLVideoElement, and drawImage on the created ImageBitmap");
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue