OLD | NEW |
1 <!DOCTYPE html> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | 3 <script> |
4 <script src="../../resources/js-test.js"></script> | 4 test(function(t) { |
5 </head> | 5 |
6 <body> | 6 var ctx = document.createElement('canvas').getContext('2d'); |
7 <script src="script-tests/canvas-imageSmoothingEnabled.js"></script> | 7 assert_equals(ctx.imageSmoothingEnabled, true); |
| 8 |
| 9 ctx.imageSmoothingEnabled = false; |
| 10 assert_equals(ctx.imageSmoothingEnabled, false); |
| 11 |
| 12 ctx.save(); |
| 13 ctx.imageSmoothingEnabled = true; |
| 14 ctx.restore(); |
| 15 assert_equals(ctx.imageSmoothingEnabled, false); |
| 16 |
| 17 var image = document.createElement('canvas'); |
| 18 image.width = 2; |
| 19 image.height = 1; |
| 20 |
| 21 // We use this to color the individual pixels |
| 22 var dotter = ctx.createImageData(1, 1); |
| 23 |
| 24 // Color the left pixel black. |
| 25 dotter.data.fill(0); |
| 26 dotter.data[3] = 255; |
| 27 image.getContext('2d').putImageData(dotter, 0, 0); |
| 28 |
| 29 // Color the right pixel white. |
| 30 dotter.data.fill(255); |
| 31 image.getContext('2d').putImageData(dotter, 1, 0); |
| 32 |
| 33 var canvas = document.createElement('canvas'); |
| 34 canvas.width = 4; |
| 35 canvas.height = 1; |
| 36 ctx = canvas.getContext('2d'); |
| 37 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); |
| 38 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); |
| 39 |
| 40 assert_not_equals(left_of_center_pixel.data[0], 0); |
| 41 assert_not_equals(left_of_center_pixel.data[1], 0); |
| 42 assert_not_equals(left_of_center_pixel.data[2], 0); |
| 43 |
| 44 ctx.imageSmoothingEnabled = false; |
| 45 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); |
| 46 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); |
| 47 |
| 48 assert_equals(left_of_center_pixel.data[0], 0); |
| 49 assert_equals(left_of_center_pixel.data[1], 0); |
| 50 assert_equals(left_of_center_pixel.data[2], 0); |
| 51 |
| 52 ctx.imageSmoothingEnabled = true; |
| 53 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); |
| 54 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); |
| 55 |
| 56 assert_not_equals(left_of_center_pixel.data[0], 0); |
| 57 assert_not_equals(left_of_center_pixel.data[1], 0); |
| 58 assert_not_equals(left_of_center_pixel.data[2], 0); |
| 59 |
| 60 ctx.imageSmoothingEnabled = false; |
| 61 ctx.save(); |
| 62 ctx.imageSmoothingEnabled = true; |
| 63 ctx.restore(); |
| 64 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); |
| 65 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); |
| 66 assert_equals(left_of_center_pixel.data[0], 0); |
| 67 assert_equals(left_of_center_pixel.data[1], 0); |
| 68 assert_equals(left_of_center_pixel.data[2], 0); |
| 69 |
| 70 }, "Tests for the imageSmoothingEnabled attribute."); |
| 71 </script> |
8 </body> | 72 </body> |
9 </html> | |
OLD | NEW |