| OLD | NEW |
| (Empty) |
| 1 description("Series of tests to ensure fill() works with path and winding rule p
arameters."); | |
| 2 | |
| 3 var ctx = document.getElementById('canvas').getContext('2d'); | |
| 4 | |
| 5 function pixelDataAtPoint() { | |
| 6 return ctx.getImageData(50, 50, 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 drawRectanglesOn(contextOrPath) { | |
| 15 contextOrPath.rect(0, 0, 100, 100); | |
| 16 contextOrPath.rect(25, 25, 50, 50); | |
| 17 } | |
| 18 | |
| 19 function formatName(fillRule, path) { | |
| 20 return 'fill(' + (path ? 'path' : '') + (fillRule && path ? ', ' : '') + | |
| 21 (fillRule ? '"' + fillRule + '"' : '') + ')'; | |
| 22 } | |
| 23 | |
| 24 function testFillWith(fillRule, path) { | |
| 25 debug('Testing ' + formatName(fillRule, path)); | |
| 26 ctx.fillStyle = 'rgb(255,0,0)'; | |
| 27 ctx.beginPath(); | |
| 28 ctx.fillRect(0, 0, 100, 100); | |
| 29 ctx.fillStyle = 'rgb(0,255,0)'; | |
| 30 if (path) { | |
| 31 if (fillRule) { | |
| 32 ctx.fill(path, fillRule); | |
| 33 } else { | |
| 34 ctx.fill(path); | |
| 35 } | |
| 36 } else { | |
| 37 ctx.beginPath(); | |
| 38 drawRectanglesOn(ctx); | |
| 39 if (fillRule) { | |
| 40 ctx.fill(fillRule); | |
| 41 } else { | |
| 42 ctx.fill(); | |
| 43 } | |
| 44 } | |
| 45 if (fillRule == 'evenodd') { | |
| 46 checkResult([255, 0, 0, 255], 5); | |
| 47 } else { | |
| 48 checkResult([0, 255, 0, 255], 5); | |
| 49 } | |
| 50 debug(''); | |
| 51 } | |
| 52 | |
| 53 // Execute test. | |
| 54 function prepareTestScenario() { | |
| 55 fillRules = [undefined, 'nonzero', 'evenodd']; | |
| 56 path = new Path2D(); | |
| 57 drawRectanglesOn(path); | |
| 58 | |
| 59 for (var i = 0; i < fillRules.length; i++) { | |
| 60 testFillWith(fillRules[i]); | |
| 61 testFillWith(fillRules[i], path); | |
| 62 } | |
| 63 | |
| 64 // Test exception cases. | |
| 65 shouldThrow("ctx.fill(null)"); | |
| 66 shouldThrow("ctx.fill(null, null)"); | |
| 67 shouldThrow("ctx.fill(null, 'nonzero')"); | |
| 68 shouldThrow("ctx.fill(path, null)"); | |
| 69 shouldThrow("ctx.fill([], 'nonzero')"); | |
| 70 shouldThrow("ctx.fill({}, 'nonzero')"); | |
| 71 shouldThrow("ctx.fill(null, 'evenodd')"); | |
| 72 shouldThrow("ctx.fill([], 'evenodd')"); | |
| 73 shouldThrow("ctx.fill({}, 'evenodd')"); | |
| 74 shouldThrow("ctx.fill('gazonk')"); | |
| 75 shouldThrow("ctx.fill(path, 'gazonk')"); | |
| 76 shouldThrow("ctx.fill(undefined, undefined)"); | |
| 77 shouldThrow("ctx.fill(undefined, path)"); | |
| 78 } | |
| 79 | |
| 80 // Run test and allow variation of results. | |
| 81 prepareTestScenario(); | |
| OLD | NEW |