| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 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=600 height=300 style="border:5px solid black"> | 4 <canvas id="canvas" width=600 height=300 style="border:5px solid black"> |
| 8 <script src="canvas-lineWidth.js"></script> | 5 <script> |
| 6 // Compare sections of a <canvas> to assert they are identical, or nearly so. |
| 7 function compareRows(ctx, y0, y1, width, height, allowableDifference) { |
| 8 var data0 = ctx.getImageData(0, y0, width, height).data; |
| 9 var data1 = ctx.getImageData(0, y1, width, height).data; |
| 10 for (var i = 0; i < data0.length; ++i) |
| 11 assert_approx_equals(data0[i], data1[i], allowableDifference); |
| 12 } |
| 13 |
| 14 ctx = document.getElementById("canvas").getContext("2d"); |
| 15 ctx.strokeStyle = 'blue'; |
| 16 |
| 17 test(function(t) { |
| 18 |
| 19 for (var j = 0; j < 3; ++j) { |
| 20 ctx.beginPath(); |
| 21 for (var i = 0; i < 60; ++i) { |
| 22 var x = i * 10; |
| 23 var y = j * 100 + 30 + (i % 15); |
| 24 if (i == 0) { |
| 25 ctx.moveTo(x, y); |
| 26 } else { |
| 27 ctx.lineTo(x, y); |
| 28 } |
| 29 } |
| 30 ctx.stroke(); |
| 31 |
| 32 if (j == 0) { |
| 33 assert_equals(ctx.lineWidth, 1); |
| 34 ctx.lineWidth = ctx.lineWidth; |
| 35 assert_equals(ctx.lineWidth, 1); |
| 36 } else { |
| 37 assert_equals(ctx.lineWidth, 1); |
| 38 ctx.lineWidth = 1; |
| 39 assert_equals(ctx.lineWidth, 1); |
| 40 } |
| 41 } |
| 42 |
| 43 // Make sure that all rows are nearly identical. |
| 44 // (Tiny variations are OK.) |
| 45 compareRows(ctx, 0, 100, 600, 100, 1); |
| 46 compareRows(ctx, 0, 200, 600, 100, 1); |
| 47 |
| 48 }, 'Test that the default lineWidth is consistent.'); |
| 49 </script> |
| 9 </body> | 50 </body> |
| 10 </html> | |
| OLD | NEW |