| OLD | NEW |
| 1 <!doctype html> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <head> | |
| 4 <script src="../../resources/js-test.js"></script> | |
| 5 </head> | |
| 6 <body> | 3 <body> |
| 7 <canvas id="canvas" width="200" height="200"></canvas> | 4 <canvas id="canvas" width="200" height="200"></canvas> |
| 8 <script src="script-tests/canvas-path-context-fill.js"></script> | 5 <script> |
| 6 |
| 7 var ctx = document.getElementById('canvas').getContext('2d'); |
| 8 |
| 9 function checkResult(expectedColors, sigma) { |
| 10 data = ctx.getImageData(50, 50, 1, 1).data; |
| 11 for (var i = 0; i < 4; i++) |
| 12 assert_approx_equals(data[i], expectedColors[i], sigma); |
| 13 } |
| 14 |
| 15 function drawRectanglesOn(contextOrPath) { |
| 16 contextOrPath.rect(0, 0, 100, 100); |
| 17 contextOrPath.rect(25, 25, 50, 50); |
| 18 } |
| 19 |
| 20 function testFillWith(fillRule, path) { |
| 21 ctx.fillStyle = 'rgb(255,0,0)'; |
| 22 ctx.beginPath(); |
| 23 ctx.fillRect(0, 0, 100, 100); |
| 24 ctx.fillStyle = 'rgb(0,255,0)'; |
| 25 if (path) { |
| 26 if (fillRule) { |
| 27 ctx.fill(path, fillRule); |
| 28 } else { |
| 29 ctx.fill(path); |
| 30 } |
| 31 } else { |
| 32 ctx.beginPath(); |
| 33 drawRectanglesOn(ctx); |
| 34 if (fillRule) { |
| 35 ctx.fill(fillRule); |
| 36 } else { |
| 37 ctx.fill(); |
| 38 } |
| 39 } |
| 40 if (fillRule == 'evenodd') { |
| 41 checkResult([255, 0, 0, 255], 5); |
| 42 } else { |
| 43 checkResult([0, 255, 0, 255], 5); |
| 44 } |
| 45 } |
| 46 |
| 47 test(function(t) { |
| 48 fillRules = [undefined, 'nonzero', 'evenodd']; |
| 49 path = new Path2D(); |
| 50 drawRectanglesOn(path); |
| 51 |
| 52 for (var i = 0; i < fillRules.length; i++) { |
| 53 testFillWith(fillRules[i]); |
| 54 testFillWith(fillRules[i], path); |
| 55 } |
| 56 |
| 57 // Test exception cases. |
| 58 assert_throws(null, function() {ctx.fill(null);}); |
| 59 assert_throws(null, function() {ctx.fill(null, null);}); |
| 60 assert_throws(null, function() {ctx.fill(null, 'nonzero');}); |
| 61 assert_throws(null, function() {ctx.fill(path, null);}); |
| 62 assert_throws(null, function() {ctx.fill([], 'nonzero');}); |
| 63 assert_throws(null, function() {ctx.fill({}, 'nonzero');}); |
| 64 assert_throws(null, function() {ctx.fill(null, 'evenodd');}); |
| 65 assert_throws(null, function() {ctx.fill([], 'evenodd');}); |
| 66 assert_throws(null, function() {ctx.fill({}, 'evenodd');}); |
| 67 assert_throws(null, function() {ctx.fill('gazonk');}); |
| 68 assert_throws(null, function() {ctx.fill(path, 'gazonk');}); |
| 69 assert_throws(null, function() {ctx.fill(undefined, undefined);}); |
| 70 assert_throws(null, function() {ctx.fill(undefined, path);}); |
| 71 }, "Series of tests to ensure fill() works with path and winding rule parameters
."); |
| 72 </script> |
| 9 </body> | 73 </body> |
| OLD | NEW |