Bug 1479514 [wpt PR 12235] - Ship CreateImageBitmap resize options, a=testonly

Automatic update from web-platform-testsShip CreateImageBitmap resize options

This change removes the requirement of ExtendedImageBitmapOptions runtime
enabled feature for CreateImageBitmap resize options to work.

Bug: 762559
Change-Id: I6bd1e098e695116a66ef2387c07087da3cc91445
Reviewed-on: https://chromium-review.googlesource.com/1155164
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Commit-Queue: Mohammad Reza Zakerinasab <zakerinasab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582682}

--

wpt-commits: a87ede5b32181eae304aee0de4b09535f9c0c080
wpt-pr: 12235
This commit is contained in:
Reza.Zakerinasab 2018-08-15 10:02:39 +00:00 коммит произвёл moz-wptsync-bot
Родитель 1a7e48dd08
Коммит ff24754be3
4 изменённых файлов: 246 добавлений и 0 удалений

Просмотреть файл

@ -290651,6 +290651,11 @@
{}
]
],
"media/video.ogv": [
[
{}
]
],
"media/white.mp4": [
[
{}
@ -316627,6 +316632,18 @@
{}
]
],
"2dcontext/imagebitmap/canvas-createImageBitmap-resize.html": [
[
"/2dcontext/imagebitmap/canvas-createImageBitmap-resize.html",
{}
]
],
"2dcontext/imagebitmap/canvas-createImageBitmap-video-resize.html": [
[
"/2dcontext/imagebitmap/canvas-createImageBitmap-video-resize.html",
{}
]
],
"2dcontext/imagebitmap/createImageBitmap-bounds.html": [
[
"/2dcontext/imagebitmap/createImageBitmap-bounds.html",
@ -424466,6 +424483,14 @@
"1a86a8f2015aba3f68ebec7cd4227127e744f133",
"testharness"
],
"2dcontext/imagebitmap/canvas-createImageBitmap-resize.html": [
"ea30328a34da15177bcd79db599fae9e8a3f6f78",
"testharness"
],
"2dcontext/imagebitmap/canvas-createImageBitmap-video-resize.html": [
"366d1fd36e0cbeae4b2aca60d1c86c98844e69cc",
"testharness"
],
"2dcontext/imagebitmap/common.sub.js": [
"7f993963d8632b180cf80314adcfebdf55a5f9a4",
"support"
@ -607254,6 +607279,10 @@
"0c55f6c7226a2cd7b722100b2f0acf74922e88be",
"support"
],
"media/video.ogv": [
"5cb5f8784811ff0e20dce16e0726c5dda4aab0f6",
"support"
],
"media/white.mp4": [
"ef609e42813b93f644b26d5cede5ee2beb777a0c",
"support"

Просмотреть файл

@ -0,0 +1,159 @@
<!DOCTYPE HTML>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function checkNoCrop(imageBitmap)
{
var canvas = document.createElement("canvas");
canvas.width = 50;
canvas.height = 50;
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(imageBitmap, 0, 0);
var d = ctx.getImageData(0, 0, 1, 1).data;
assert_array_equals(d, [255, 0, 0, 255], "This pixel should be red.");
d = ctx.getImageData(39, 0, 1, 1).data;
assert_array_equals(d, [0, 255, 0, 255], "This pixel should be green.");
d = ctx.getImageData(0, 39, 1, 1).data;
assert_array_equals(d, [0, 0, 255, 255], "This pixel should be blue.");
d = ctx.getImageData(39, 39, 1, 1).data;
assert_array_equals(d, [0, 0, 0, 255], "This pixel should be black.");
d = ctx.getImageData(41, 41, 1, 1).data;
assert_array_equals(d, [0, 0, 0, 0], "This pixel should be transparent black.");
}
function checkCrop(imageBitmap)
{
var canvas = document.createElement("canvas");
canvas.width = 50;
canvas.height = 50;
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(imageBitmap, 0, 0);
var d = ctx.getImageData(0, 0, 1, 1).data;
assert_array_equals(d, [255, 0, 0, 255], "This pixel should be red.");
d = ctx.getImageData(19, 0, 1, 1).data;
assert_array_equals(d, [0, 255, 0, 255], "This pixel should be green.");
d = ctx.getImageData(0, 19, 1, 1).data;
assert_array_equals(d, [0, 0, 255, 255], "This pixel should be blue.");
d = ctx.getImageData(19, 19, 1, 1).data;
assert_array_equals(d, [0, 0, 0, 255], "This pixel should be black.");
d = ctx.getImageData(21, 21, 1, 1).data;
assert_array_equals(d, [0, 0, 0, 0], "This pixel should be transparent black.");
}
function compareBitmaps(bitmap1, bitmap2)
{
var canvas1 = document.createElement("canvas");
var canvas2 = document.createElement("canvas");
canvas1.width = 50;
canvas1.height = 50;
canvas2.width = 50;
canvas2.height = 50;
var ctx1 = canvas1.getContext("2d");
var ctx2 = canvas2.getContext("2d");
ctx1.clearRect(0, 0, canvas1.width, canvas1.height);
ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
ctx1.drawImage(bitmap1, 0, 0);
ctx2.drawImage(bitmap2, 0, 0);
var data1 = ctx1.getImageData(0, 0, 50, 50).data;
var data2 = ctx2.getImageData(0, 0, 50, 50).data;
var dataMatched = true;
for (var i = 0; i < data1.length; i++) {
if (data1[i] != data2[i]) {
dataMatched = false;
break;
}
}
assert_false(dataMatched);
}
function testImageBitmap(source)
{
return Promise.all([
createImageBitmap(source, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "high"}),
createImageBitmap(source, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "medium"}),
createImageBitmap(source, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "low"}),
createImageBitmap(source, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "pixelated"}),
createImageBitmap(source, 5, 5, 10, 10, {resizeWidth: 20, resizeHeight: 20, resizeQuality: "high"}),
createImageBitmap(source, 5, 5, 10, 10, {resizeWidth: 20, resizeHeight: 20, resizeQuality: "medium"}),
createImageBitmap(source, 5, 5, 10, 10, {resizeWidth: 20, resizeHeight: 20, resizeQuality: "low"}),
createImageBitmap(source, 5, 5, 10, 10, {resizeWidth: 20, resizeHeight: 20, resizeQuality: "pixelated"}),
]).then(([noCropHigh, noCropMedium, noCropLow, noCropPixelated, cropHigh, cropMedium, cropLow, cropPixelated]) => {
checkNoCrop(noCropHigh);
checkNoCrop(noCropMedium);
checkNoCrop(noCropLow);
checkNoCrop(noCropPixelated);
checkCrop(cropHigh);
checkCrop(cropMedium);
checkCrop(cropLow);
checkCrop(cropPixelated);
// Brute-force comparison among all bitmaps is too expensive
compareBitmaps(noCropHigh, noCropMedium);
compareBitmaps(noCropLow, noCropPixelated);
compareBitmaps(cropHigh, cropMedium);
compareBitmaps(cropLow, cropPixelated);
});
}
function initializeTestCanvas()
{
var testCanvas = document.createElement("canvas");
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);
return testCanvas;
}
// Blob
promise_test(function() {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open("GET", '/images/pattern.png');
xhr.responseType = 'blob';
xhr.send();
xhr.onload = function() {
resolve(xhr.response);
};
}).then(testImageBitmap);
}, 'createImageBitmap from a Blob with resize option.');
// HTMLCanvasElement
promise_test(function() {
var testCanvas = initializeTestCanvas();
return testImageBitmap(testCanvas);
}, 'createImageBitmap from a HTMLCanvasElement with resize option.');
// HTMLImageElement
promise_test(function() {
return new Promise((resolve, reject) => {
var image = new Image();
image.onload = function() {
resolve(image);
}
image.src = '/images/pattern.png'
}).then(testImageBitmap);
}, 'createImageBitmap from a HTMLImageElement with resize option.');
// ImageBitmap
promise_test(function() {
var testCanvas = initializeTestCanvas();
return createImageBitmap(testCanvas).then(testImageBitmap);
}, 'createImageBitmap from an ImageBitmap with resize option.');
// ImageData
promise_test(function() {
var canvas = initializeTestCanvas();
var ctx = canvas.getContext("2d");
var data = ctx.getImageData(0, 0, 20, 20);
return testImageBitmap(data);
}, 'createImageBitmap from an ImageData with resize option.');
</script>

Просмотреть файл

@ -0,0 +1,58 @@
<!DOCTYPE HTML>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function createNewCanvas(width, height)
{
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
return ctx;
}
function checkLowResult(imageBitmap, bw, bh, video, sx, sy, sw, sh)
{
var ctx1 = createNewCanvas(bw, bh);
var ctx2 = createNewCanvas(bw, bh);
ctx1.drawImage(imageBitmap, 0, 0);
ctx2.drawImage(video, sx, sy, sw, sh, 0, 0, bw, bh);
var data1 = ctx1.getImageData(0, 0, bw, bh).data;
var data2 = ctx2.getImageData(0, 0, bw, bh).data;
var dataMatched = true;
for (var i = 0; i < data1.length; i++) {
// data1[i] is strictly the same as data2[i] on software rendering.
// But on GPU, the difference could be quite significant.
if (Math.abs(data1[i] - data2[i]) > 18) {
dataMatched = false;
break;
}
}
assert_true(dataMatched);
}
function generateTest()
{
bitmapWidth = video.videoWidth/2;
bitmapHeight = video.videoHeight/2;
return Promise.all([
createImageBitmap(video, {resizeWidth: bitmapWidth, resizeHeight: bitmapHeight, resizeQuality: "low"}),
createImageBitmap(video, 10, 10, bitmapWidth, bitmapHeight, {resizeWidth: bitmapWidth, resizeHeight: bitmapHeight, resizeQuality: "low"}),
]).then(t.step_func_done(([noCropLow, cropLow]) => {
checkLowResult(noCropLow, bitmapWidth, bitmapHeight, video, 0, 0, video.videoWidth, video.videoHeight);
checkLowResult(cropLow, bitmapWidth, bitmapHeight, video, 10, 10, bitmapWidth, bitmapHeight);
}), t.step_func_done(function() {
assert_true(false, 'Promise rejected');
}));
}
var t = async_test('createImageBitmap(HTMLVideoElement) with resize option');
// HTMLVideoElement
var video = document.createElement("video");
video.oncanplaythrough = t.step_func(function() {
return generateTest();
});
video.src = "/media/video.ogv";
</script>

Двоичные данные
testing/web-platform/tests/media/video.ogv Normal file

Двоичный файл не отображается.