| OLD | NEW |
| (Empty) |
| 1 description("Series of tests to ensure stroke() works with optional path paramet
er."); | |
| 2 | |
| 3 var ctx = document.getElementById('canvas').getContext('2d'); | |
| 4 | |
| 5 function pixelDataAtPoint() { | |
| 6 return ctx.getImageData(75, 75, 1, 1).data; | |
| 7 } | |
| 8 | |
| 9 function checkResult(expectedColors, sigma) { | |
| 10 for (var i = 0; i < 4; i++) | |
| 11 shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma)
; | |
| 12 } | |
| 13 | |
| 14 function drawRectangleOn(contextOrPath) { | |
| 15 contextOrPath.rect(25, 25, 50, 50); | |
| 16 } | |
| 17 | |
| 18 function formatName(path) { | |
| 19 return 'stroke(' + (path ? 'path' : '') + ')'; | |
| 20 } | |
| 21 | |
| 22 function testStrokeWith(path) { | |
| 23 debug('Testing ' + formatName(path)); | |
| 24 ctx.fillStyle = 'rgb(255,0,0)'; | |
| 25 ctx.beginPath(); | |
| 26 ctx.fillRect(0, 0, 100, 100); | |
| 27 ctx.strokeStyle = 'rgb(0,255,0)'; | |
| 28 ctx.lineWidth = 5; | |
| 29 if (path) { | |
| 30 ctx.stroke(path); | |
| 31 } else { | |
| 32 ctx.beginPath(); | |
| 33 drawRectangleOn(ctx); | |
| 34 ctx.stroke(); | |
| 35 } | |
| 36 debug(''); | |
| 37 checkResult([0, 255, 0, 255], 5); | |
| 38 } | |
| 39 | |
| 40 // Execute test. | |
| 41 function prepareTestScenario() { | |
| 42 var path = new Path2D(); | |
| 43 drawRectangleOn(path); | |
| 44 | |
| 45 testStrokeWith(); | |
| 46 testStrokeWith(path); | |
| 47 | |
| 48 // Test exception cases. | |
| 49 shouldThrow("ctx.stroke(null)"); | |
| 50 shouldThrow("ctx.stroke(undefined)"); | |
| 51 shouldThrow("ctx.stroke([])"); | |
| 52 shouldThrow("ctx.stroke({})"); | |
| 53 } | |
| 54 | |
| 55 // Run test and allow variation of results. | |
| 56 prepareTestScenario(); | |
| OLD | NEW |