mirror of
https://github.com/servo/servo.git
synced 2025-08-16 19:05:33 +01:00
Update web-platform-tests to revision 68a256f49be380ca4add535ce8ece9de28820e6b
This commit is contained in:
parent
e54935c25a
commit
cd5bf022bd
178 changed files with 6082 additions and 795 deletions
|
@ -43,13 +43,34 @@ function makeVideo() {
|
|||
});
|
||||
}
|
||||
|
||||
function makeDataUrlVideo() {
|
||||
const toDataUrl = (type, buffer) => {
|
||||
const encoded = btoa(String.fromCodePoint(...new Uint8Array(buffer)));
|
||||
return `data:${type};base64,${encoded}`
|
||||
};
|
||||
|
||||
return fetch(getVideoURI("/images/pattern"))
|
||||
.then(response => Promise.all([response.headers.get("Content-Type"), response.arrayBuffer()]))
|
||||
.then(([type, data]) => {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var video = document.createElement("video");
|
||||
video.oncanplaythrough = function() {
|
||||
resolve(video);
|
||||
};
|
||||
video.onerror = reject;
|
||||
video.src = toDataUrl(type, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function makeMakeHTMLImage(src) {
|
||||
return function() {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
resolve(img);
|
||||
};
|
||||
img.onerror = reject;
|
||||
img.src = src;
|
||||
});
|
||||
}
|
||||
|
@ -115,6 +136,7 @@ function makeBlob() {
|
|||
var imageSourceTypes = [
|
||||
{ name: 'an HTMLCanvasElement', factory: makeCanvas },
|
||||
{ name: 'an HTMLVideoElement', factory: makeVideo },
|
||||
{ name: 'an HTMLVideoElement from a data URL', factory: makeDataUrlVideo },
|
||||
{ name: 'a bitmap HTMLImageElement', factory: makeMakeHTMLImage("/images/pattern.png") },
|
||||
{ name: 'a vector HTMLImageElement', factory: makeMakeHTMLImage("/images/pattern.svg") },
|
||||
{ name: 'a bitmap SVGImageElement', factory: makeMakeSVGImage("/images/pattern.png") },
|
||||
|
|
|
@ -10,25 +10,28 @@
|
|||
<link rel="stylesheet" href="/common/canvas-tests.css">
|
||||
<body>
|
||||
<script>
|
||||
function testCanvasDisplayingPattern(canvas)
|
||||
function testCanvasDisplayingPattern(canvas, width, height)
|
||||
{
|
||||
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);
|
||||
var tolerance = 10; // for creating ImageBitmap from a video, the tolerance needs to be high
|
||||
const check = (x, y, r, g, b, a) =>
|
||||
_assertPixelApprox(canvas, x,y, r,g,b,a, `${x},${y}`, `${r},${g},${b},${a}`, tolerance);
|
||||
check(1 * width / 4, 1 * height / 4, 255,0,0,255);
|
||||
check(3 * width / 4, 1 * height / 4, 0,255,0,255);
|
||||
check(1 * width / 4, 3 * height / 4, 0,0,255,255);
|
||||
check(3 * width / 4, 3 * height / 4, 0,0,0,255);
|
||||
}
|
||||
|
||||
function testDrawImageBitmap(source, args = [])
|
||||
function testDrawImageBitmap(source, args = [], { resizeWidth = 20, resizeHeight = 20 } = {})
|
||||
{
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = 20;
|
||||
canvas.height = 20;
|
||||
canvas.width = resizeWidth;
|
||||
canvas.height = resizeHeight;
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
return createImageBitmap(source, ...args).then(imageBitmap => {
|
||||
assert_equals(imageBitmap.width, resizeWidth);
|
||||
assert_equals(imageBitmap.height, resizeHeight);
|
||||
ctx.drawImage(imageBitmap, 0, 0);
|
||||
testCanvasDisplayingPattern(canvas);
|
||||
testCanvasDisplayingPattern(canvas, resizeWidth, resizeHeight);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -39,6 +42,27 @@ for (let { name, factory } of imageSourceTypes) {
|
|||
});
|
||||
}, `createImageBitmap from ${name}, and drawImage on the created ImageBitmap`);
|
||||
|
||||
promise_test(function() {
|
||||
return factory().then(function(img) {
|
||||
const options = { resizeWidth: 10, resizeHeight: 10 };
|
||||
return testDrawImageBitmap(img, [options], options);
|
||||
});
|
||||
}, `createImageBitmap from ${name} scaled down, and drawImage on the created ImageBitmap`);
|
||||
|
||||
promise_test(function() {
|
||||
return factory().then(function(img) {
|
||||
const options = { resizeWidth: 40, resizeHeight: 40 };
|
||||
return testDrawImageBitmap(img, [options], options);
|
||||
});
|
||||
}, `createImageBitmap from ${name} scaled up, and drawImage on the created ImageBitmap`);
|
||||
|
||||
promise_test(function() {
|
||||
return factory().then(function(img) {
|
||||
const options = { resizeWidth: 10, resizeHeight: 40 };
|
||||
return testDrawImageBitmap(img, [options], options);
|
||||
});
|
||||
}, `createImageBitmap from ${name} resized, and drawImage on the created ImageBitmap`);
|
||||
|
||||
promise_test(function() {
|
||||
return factory().then(function(img) {
|
||||
return testDrawImageBitmap(img, [20, 20, -20, -20]);
|
||||
|
|
|
@ -58,6 +58,18 @@ const arguments = [
|
|||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "redirected to cross-origin HTMLVideoElement",
|
||||
factory: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const video = document.createElement("video");
|
||||
video.oncanplaythrough = () => resolve(video);
|
||||
video.onerror = reject;
|
||||
video.src = "/common/redirect.py?location=" + getVideoURI("http://{{domains[www1]}}:{{ports[http][0]}}/media/movie_300");
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "unclean HTMLCanvasElement",
|
||||
factory: () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue