6 changed files with 127 additions and 1 deletions
@ -0,0 +1,64 @@ |
|||
|
|||
window.onload = runTests; |
|||
|
|||
function get(id) { |
|||
return document.getElementById(id); |
|||
} |
|||
|
|||
function create(type) { |
|||
return document.createElement(type); |
|||
} |
|||
|
|||
function runTests() { |
|||
var table = get('tests'); |
|||
for (var name in tests) { |
|||
var canvas = create('canvas') |
|||
, tr = create('tr') |
|||
, tds = [create('td'), create('td')]; |
|||
canvas.width = 200; |
|||
canvas.height = 200; |
|||
tds[1].appendChild(canvas); |
|||
tr.appendChild(tds[0]); |
|||
tr.appendChild(tds[1]); |
|||
table.appendChild(tr); |
|||
runTest(name, canvas, tds[0]); |
|||
} |
|||
} |
|||
|
|||
function runTest(name, canvas, dest) { |
|||
var fn = tests[name]; |
|||
fn(canvas.getContext('2d')); |
|||
renderOnServer(name, canvas, function(res){ |
|||
if (res.error) { |
|||
var p = create('p'); |
|||
p.innerText = res.error; |
|||
dest.appendChild(p); |
|||
} else if (res.data) { |
|||
var img = create('image'); |
|||
img.src = res.data; |
|||
img.alt = name; |
|||
dest.appendChild(img); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
function renderOnServer(name, canvas, fn) { |
|||
var req = new XMLHttpRequest |
|||
, json = JSON.stringify({ |
|||
fn: tests[name].toString() |
|||
, width: canvas.width |
|||
, height: canvas.height |
|||
}); |
|||
req.open('POST', '/render'); |
|||
req.setRequestHeader('Content-Type', 'application/json'); |
|||
req.onreadystatechange = function(){ |
|||
if (4 == req.readyState) { |
|||
try { |
|||
fn(JSON.parse(req.responseText)); |
|||
} catch (err) { |
|||
fn({ error: err }); |
|||
} |
|||
} |
|||
}; |
|||
req.send(json); |
|||
} |
@ -0,0 +1,33 @@ |
|||
|
|||
var tests = {}; |
|||
|
|||
tests['linear gradients'] = function(ctx){ |
|||
var lingrad = ctx.createLinearGradient(0,0,0,150); |
|||
lingrad.addColorStop(0, '#00ABEB'); |
|||
lingrad.addColorStop(0.5, '#fff'); |
|||
lingrad.addColorStop(0.5, '#26C000'); |
|||
lingrad.addColorStop(1, '#fff'); |
|||
|
|||
var lingrad2 = ctx.createLinearGradient(0,50,0,95); |
|||
lingrad2.addColorStop(0.5, '#000'); |
|||
lingrad2.addColorStop(1, 'rgba(0,0,0,0)'); |
|||
|
|||
ctx.fillStyle = lingrad; |
|||
ctx.strokeStyle = lingrad2; |
|||
|
|||
ctx.fillRect(10,10,130,130); |
|||
ctx.strokeRect(50,50,50,50); |
|||
}; |
|||
|
|||
tests['global alpha'] = function(ctx){ |
|||
ctx.globalAlpha = 0.5; |
|||
ctx.fillStyle = 'rgba(0,0,0,0.5)'; |
|||
ctx.strokeRect(0,0,50,50); |
|||
|
|||
ctx.globalAlpha = 0.8; |
|||
ctx.fillRect(20,20,20,20); |
|||
|
|||
ctx.fillStyle = 'black'; |
|||
ctx.globalAlpha = 1; |
|||
ctx.fillRect(25,25,10,10); |
|||
}; |
@ -1,5 +1,12 @@ |
|||
h1 node-canvas |
|||
|
|||
p.msg |
|||
| The tests below assert visual and api integrity by running the |
|||
em exact |
|||
| same code utilizing the client canvas api, as well as node-canvas. |
|||
| same code utilizing the client canvas api, as well as node-canvas. |
|||
|
|||
table#tests |
|||
thead |
|||
th node-canvas |
|||
th target |
|||
tbody |
Loading…
Reference in new issue