Skip to content
Permalink
Browse files
Import W3C Web Platform Tests for createImageBitmap
https://bugs.webkit.org/show_bug.cgi?id=178509
<rdar://problem/35070583>

Reviewed by Antoine Quint.

* resources/import-expectations.json:
* web-platform-tests/2dcontext/imagebitmap/common.js: Added.
(testCanvasDisplayingPattern):
(testDrawImageBitmap):
(initializeImageData):
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-sizeOverflow-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-sizeOverflow.html: Added.
* web-platform-tests/2dcontext/imagebitmap/w3c-import.log: Added.

Canonical link: https://commits.webkit.org/194704@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223686 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
grorg committed Oct 19, 2017
1 parent f84f10e commit ef0f041e36bc8b50ad0c06c9a4668e79310b87a4
@@ -1,3 +1,24 @@
2017-10-19 Dean Jackson <dino@apple.com>

Import W3C Web Platform Tests for createImageBitmap
https://bugs.webkit.org/show_bug.cgi?id=178509
<rdar://problem/35070583>

Reviewed by Antoine Quint.

* resources/import-expectations.json:
* web-platform-tests/2dcontext/imagebitmap/common.js: Added.
(testCanvasDisplayingPattern):
(testDrawImageBitmap):
(initializeImageData):
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-sizeOverflow-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-sizeOverflow.html: Added.
* web-platform-tests/2dcontext/imagebitmap/w3c-import.log: Added.

2017-10-18 Chris Dumez <cdumez@apple.com>

Align ImageData constructor with the specification
@@ -1,6 +1,7 @@
{
"css/geometry-1": "import",
"web-platform-tests/2dcontext": "skip",
"web-platform-tests/2dcontext/imagebitmap": "import",
"web-platform-tests/2dcontext/transformations/canvas_transformations_reset_001-ref.html": "import",
"web-platform-tests/2dcontext/transformations/canvas_transformations_reset_001.html": "import",
"web-platform-tests/DOM-parsing": "skip",
@@ -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,10 @@

Harness Error (TIMEOUT), message = null

FAIL createImageBitmap from a HTMLImageElement, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
FAIL createImageBitmap from a Blob, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
FAIL createImageBitmap from a HTMLCanvasElement, and drawImage on the created ImageBitmap Can't find variable: createImageBitmap
FAIL createImageBitmap from an ImageBitmap, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
FAIL createImageBitmap from an ImageData, and drawImage on the created ImageBitmap Can't find variable: createImageBitmap
TIMEOUT createImageBitmap from a HTMLVideoElement, and drawImage on the created ImageBitmap Test timed out

@@ -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);
return 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>
@@ -0,0 +1,32 @@

Harness Error (TIMEOUT), message = null

FAIL createImageBitmap with a HTMLImageElement source and sw set to 0 rejects with a RangeError. promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
FAIL createImageBitmap with a HTMLImageElement source and sh set to 0 rejects with a RangeError. promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
FAIL createImageBitmap with a HTMLImageElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException. promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: createImageBitmap"
TIMEOUT createImageBitmap with a HTMLVideoElement source and sw set to 0 rejects with a RangeError. Test timed out
NOTRUN createImageBitmap with a HTMLVideoElement source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a HTMLVideoElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with a HTMLCanvasElement source and sw set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a HTMLCanvasElement source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a HTMLCanvasElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with a OffscreenCanvas source and sw set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a OffscreenCanvas source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a OffscreenCanvas source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with a ImageData source and sw set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a ImageData source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a ImageData source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with a ImageBitmap source and sw set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a ImageBitmap source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a ImageBitmap source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with a Blob source and sw set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a Blob source and sh set to 0 rejects with a RangeError.
NOTRUN createImageBitmap with a Blob source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.
NOTRUN createImageBitmap with undefined image source rejects with a TypeError.
NOTRUN createImageBitmap with null image source rejects with a TypeError.
NOTRUN createImageBitmap with empty image source rejects with a InvalidStateError.
NOTRUN createImageBitmap with empty video source rejects with a InvalidStateError.
NOTRUN createImageBitmap with an oversized canvas source rejects with a RangeError.
NOTRUN createImageBitmap with an invalid OffscreenCanvas source rejects with a RangeError.
NOTRUN createImageBitmap with an undecodable blob source rejects with an InvalidStateError.

@@ -0,0 +1,187 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>

function makeCanvas() {
return new Promise(resolve => {
let canvas = document.createElement('canvas');
canvas.setAttribute('width', '10');
canvas.setAttribute('height', '10');
resolve(canvas);
});
}

function makeOffscreenCanvas() {
return new Promise(resolve => {
let canvas = new OffscreenCanvas(10, 10);
resolve(canvas);
});
}

function makeOversizedCanvas() {

return new Promise(resolve => {
let canvas = document.createElement('canvas');
canvas.setAttribute('width', '100000000');
canvas.setAttribute('height', '100000000');
resolve(canvas);
});
}

function makeOversizedOffscreenCanvas() {
return new Promise(resolve =>{
let canvas = new OffscreenCanvas(100000000, 100000000);
resolve(canvas);
});
}

function makeVideo() {
return new Promise(resolve => {
let video = document.createElement('video');
video.addEventListener('canplaythrough', resolve.bind(undefined, video), false);
video.src = '/media/A4.ogv';
});
}

function makeImage() {
return makeCanvas().then(canvas => {
let image = new Image();
image.src = canvas.toDataURL();
return new Promise(resolve => {
image.onload = resolve.bind(undefined, image);
});
});
}

function makeImageData() {
return makeCanvas().then(canvas => {
return new Promise(function(resolve, reject) {
resolve(canvas.getContext('2d').getImageData(0, 0, 10, 10));
});
});
}

function makeImageBitmap() {
return makeCanvas().then(canvas => {
return createImageBitmap(canvas);
});
}

function makeBlob() {
return makeCanvas().then(canvas => {
return new Promise(resolve => {
canvas.toBlob(resolve);
});
});
}

function makeInvalidBlob() {
return new Promise(resolve => {
resolve(new Blob()); // Blob with no data cannot be decoded.
});
}

imageSourceTypes = [
{ name: 'HTMLImageElement', factory: makeImage },
{ name: 'HTMLVideoElement', factory: makeVideo },
{ name: 'HTMLCanvasElement', factory: makeCanvas },
{ name: 'OffscreenCanvas', factory: makeOffscreenCanvas },
{ name: 'ImageData', factory: makeImageData },
{ name: 'ImageBitmap', factory: makeImageBitmap },
{ name: 'Blob', factory: makeBlob },
];

testCases = [
{
description: 'createImageBitmap with a <sourceType> source and sw set to ' +
'0 rejects with a RangeError.',
promiseTestFunction:
(source, t) => {
return promise_rejects(t, new RangeError(),
createImageBitmap(source, 0, 0, 0, 10));
}
},
{
description: 'createImageBitmap with a <sourceType> source and sh set to ' +
'0 rejects with a RangeError.',
promiseTestFunction:
(source, t) => {
return promise_rejects(t, new RangeError(),
createImageBitmap(source, 0, 0, 10, 0));
}
},
{
// This case is not explicitly documented in the specification for
// createImageBitmap, but it is expected that internal failures cause
//
description: 'createImageBitmap with a <sourceType> source and oversized ' +
'(unallocatable) crop region rejects with an InvalidStateError ' +
'DOMException.',
promiseTestFunction:
(source, t) => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(source, 0, 0, 100000000, 100000000));
}
},
];

// Generate the test matrix for each sourceType + testCase combo.
imageSourceTypes.forEach(imageSourceType => {
testCases.forEach(testCase => {
let description = testCase.description.replace('<sourceType>',
imageSourceType.name);
promise_test( t => {
return imageSourceType.factory().then(source => {
return testCase.promiseTestFunction(source, t);
});
}, description);
});
});

promise_test( t => {
return promise_rejects(t, new TypeError(), createImageBitmap(undefined));
}, "createImageBitmap with undefined image source rejects with a TypeError.");

promise_test( t => {
return promise_rejects(t, new TypeError(), createImageBitmap(null));
}, "createImageBitmap with null image source rejects with a TypeError.");

promise_test( t => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(new Image()));
}, "createImageBitmap with empty image source rejects with a InvalidStateError.");

promise_test( t => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(document.createElement('video')));
}, "createImageBitmap with empty video source rejects with a InvalidStateError.");

promise_test( t => {
return makeOversizedCanvas().then(canvas => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(canvas));
});
}, "createImageBitmap with an oversized canvas source rejects with a RangeError.");

promise_test( t => {
return makeOversizedOffscreenCanvas().then(offscreenCanvas => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(offscreenCanvas));
});
}, "createImageBitmap with an invalid OffscreenCanvas source rejects with a RangeError.");

promise_test( t => {
return makeInvalidBlob().then(blob => {
return promise_rejects(t, new DOMException('', 'InvalidStateError'),
createImageBitmap(blob));
});
}, "createImageBitmap with an undecodable blob source rejects with an InvalidStateError.");

</script>
</body>
</html>

0 comments on commit ef0f041

Please sign in to comment.