mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255
This commit is contained in:
parent
b2a5225831
commit
1a81b18b9f
12321 changed files with 544385 additions and 6 deletions
86
tests/wpt/web-platform-tests/common/canvas-tests.js
Normal file
86
tests/wpt/web-platform-tests/common/canvas-tests.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
function _valToString(val)
|
||||
{
|
||||
if (val === undefined || val === null)
|
||||
return '[' + typeof(val) + ']';
|
||||
return val.toString() + '[' + typeof(val) + ']';
|
||||
}
|
||||
|
||||
function _assert(cond, text)
|
||||
{
|
||||
assert_true(!!cond, text);
|
||||
}
|
||||
|
||||
function _assertSame(a, b, text_a, text_b)
|
||||
{
|
||||
var msg = text_a + ' === ' + text_b + ' (got ' + _valToString(a) +
|
||||
', expected ' + _valToString(b) + ')';
|
||||
assert_equals(a, b, msg);
|
||||
}
|
||||
|
||||
function _assertDifferent(a, b, text_a, text_b)
|
||||
{
|
||||
var msg = text_a + ' !== ' + text_b + ' (got ' + _valToString(a) +
|
||||
', expected not ' + _valToString(b) + ')';
|
||||
assert_not_equals(a, b, msg);
|
||||
}
|
||||
|
||||
|
||||
function _getPixel(canvas, x,y)
|
||||
{
|
||||
var ctx = canvas.getContext('2d');
|
||||
var imgdata = ctx.getImageData(x, y, 1, 1);
|
||||
return [ imgdata.data[0], imgdata.data[1], imgdata.data[2], imgdata.data[3] ];
|
||||
}
|
||||
|
||||
function _assertPixel(canvas, x,y, r,g,b,a, pos, colour)
|
||||
{
|
||||
var c = _getPixel(canvas, x,y);
|
||||
assert_equals(c[0], r, 'Red channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_equals(c[1], g, 'Green channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_equals(c[2], b, 'Blue channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_equals(c[3], a, 'Alpha channel of the pixel at (' + x + ', ' + y + ')');
|
||||
}
|
||||
|
||||
function _assertPixelApprox(canvas, x,y, r,g,b,a, pos, colour, tolerance)
|
||||
{
|
||||
var c = _getPixel(canvas, x,y);
|
||||
assert_approx_equals(c[0], r, tolerance, 'Red channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_approx_equals(c[1], g, tolerance, 'Green channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_approx_equals(c[2], b, tolerance, 'Blue channel of the pixel at (' + x + ', ' + y + ')');
|
||||
assert_approx_equals(c[3], a, tolerance, 'Alpha channel of the pixel at (' + x + ', ' + y + ')');
|
||||
}
|
||||
|
||||
function _addTest(testFn)
|
||||
{
|
||||
var deferred = false;
|
||||
window.deferTest = function () { deferred = true; };
|
||||
on_event(window, "load", function()
|
||||
{
|
||||
t.step(function() {
|
||||
var canvas = document.getElementById('c');
|
||||
var ctx = canvas.getContext('2d');
|
||||
t.step(testFn, window, canvas, ctx);
|
||||
});
|
||||
|
||||
if (!deferred) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _assertGreen(ctx, canvasWidth, canvasHeight)
|
||||
{
|
||||
var testColor = function(d, idx, expected) {
|
||||
assert_equals(d[idx], expected, "d[" + idx + "]", String(expected));
|
||||
};
|
||||
var imagedata = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
|
||||
var w = imagedata.width, h = imagedata.height, d = imagedata.data;
|
||||
for (var i = 0; i < h; ++i) {
|
||||
for (var j = 0; j < w; ++j) {
|
||||
testColor(d, 4 * (w * i + j) + 0, 0);
|
||||
testColor(d, 4 * (w * i + j) + 1, 255);
|
||||
testColor(d, 4 * (w * i + j) + 2, 0);
|
||||
testColor(d, 4 * (w * i + j) + 3, 255);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue