1 description("Series of tests to ensure stroke() works with optional path parameter.");
3 var ctx = document.getElementById('canvas').getContext('2d');
5 function pixelDataAtPoint() {
6 return ctx.getImageData(75, 75, 1, 1).data;
9 function checkResult(expectedColors, sigma) {
10 for (var i = 0; i < 4; i++)
11 shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
14 function drawRectangleOn(contextOrPath) {
15 contextOrPath.rect(25, 25, 50, 50);
18 function formatName(path) {
19 return 'stroke(' + (path ? 'path' : '') + ')';
22 function testStrokeWith(path) {
23 debug('Testing ' + formatName(path));
24 ctx.fillStyle = 'rgb(255,0,0)';
26 ctx.fillRect(0, 0, 100, 100);
27 ctx.strokeStyle = 'rgb(0,255,0)';
37 checkResult([0, 255, 0, 255], 5);
41 function prepareTestScenario() {
42 var path = new Path2D();
43 drawRectangleOn(path);
48 // Test exception cases.
49 shouldThrow("ctx.stroke(null)");
50 shouldThrow("ctx.stroke(undefined)");
51 shouldThrow("ctx.stroke([])");
52 shouldThrow("ctx.stroke({})");
55 // Run test and allow variation of results.
56 prepareTestScenario();