| OLD | NEW |
| (Empty) |
| 1 description("Tests for the imageSmoothingEnabled attribute."); | |
| 2 var ctx = document.createElement('canvas').getContext('2d'); | |
| 3 | |
| 4 debug("Test that the default value is true."); | |
| 5 shouldBe("ctx.webkitImageSmoothingEnabled", "true"); | |
| 6 | |
| 7 debug("Test that false is returned after a the attribute is set to false."); | |
| 8 ctx.webkitImageSmoothingEnabled = false; | |
| 9 shouldBe("ctx.webkitImageSmoothingEnabled", "false"); | |
| 10 | |
| 11 debug("Test that restore works. We save a false state; create, then save a true
state; and then finally restore."); | |
| 12 ctx.save(); | |
| 13 ctx.webkitImageSmoothingEnabled = true; | |
| 14 ctx.restore(); | |
| 15 shouldBe("ctx.webkitImageSmoothingEnabled", "false"); | |
| 16 | |
| 17 var image = document.createElement('canvas'); | |
| 18 image.width = 2; | |
| 19 image.height = 1; | |
| 20 | |
| 21 // We use this to colour the individual pixels | |
| 22 var dotter = ctx.createImageData(1, 1); | |
| 23 | |
| 24 // Colour the left pixel black. | |
| 25 dotter.data[0] = 0; | |
| 26 dotter.data[1] = 0; | |
| 27 dotter.data[2] = 0; | |
| 28 dotter.data[3] = 255; | |
| 29 image.getContext('2d').putImageData(dotter, 0, 0); | |
| 30 | |
| 31 // Colour the right pixel white. | |
| 32 dotter.data[0] = 255; | |
| 33 dotter.data[1] = 255; | |
| 34 dotter.data[2] = 255; | |
| 35 dotter.data[3] = 255; | |
| 36 image.getContext('2d').putImageData(dotter, 1, 0); | |
| 37 | |
| 38 | |
| 39 debug("New canvas element created."); | |
| 40 var canvas = document.createElement('canvas'); | |
| 41 canvas.width = 4; | |
| 42 canvas.height = 1; | |
| 43 ctx = canvas.getContext('2d'); | |
| 44 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | |
| 45 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); | |
| 46 | |
| 47 debug("Test that the image is smoothed by default. We check by making sure the p
ixel just to the left of the middle line is not completely black."); | |
| 48 shouldBe("left_of_center_pixel.data[0] !== 0", "true"); | |
| 49 shouldBe("left_of_center_pixel.data[1] !== 0", "true"); | |
| 50 shouldBe("left_of_center_pixel.data[2] !== 0", "true"); | |
| 51 | |
| 52 ctx.webkitImageSmoothingEnabled = false; | |
| 53 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | |
| 54 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); | |
| 55 debug("Test that nearest neighbour is used when imageSmoothingEnabled is set to
false. We check this by making sure the pixel just to the left of the middle lin
e is completely black."); | |
| 56 shouldBe("left_of_center_pixel.data[0]", "0"); | |
| 57 shouldBe("left_of_center_pixel.data[1]", "0"); | |
| 58 shouldBe("left_of_center_pixel.data[2]", "0"); | |
| 59 | |
| 60 ctx.webkitImageSmoothingEnabled = true; | |
| 61 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | |
| 62 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); | |
| 63 debug("Test that the image is smoothed when imageSmoothingEnabled is set to true
."); | |
| 64 shouldBe("left_of_center_pixel.data[0] !== 0", "true"); | |
| 65 shouldBe("left_of_center_pixel.data[1] !== 0", "true"); | |
| 66 shouldBe("left_of_center_pixel.data[2] !== 0", "true"); | |
| 67 | |
| 68 debug("Test that restoring actually changes smoothing and not just the attribute
value. We are restoring to a point where imageSmoothingEnabled is set to false.
"); | |
| 69 ctx.webkitImageSmoothingEnabled = false; | |
| 70 ctx.save(); | |
| 71 ctx.webkitImageSmoothingEnabled = true; | |
| 72 ctx.restore(); | |
| 73 ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | |
| 74 left_of_center_pixel = ctx.getImageData(1, 0, 1, 1); | |
| 75 shouldBe("left_of_center_pixel.data[0]", "0"); | |
| 76 shouldBe("left_of_center_pixel.data[1]", "0"); | |
| 77 shouldBe("left_of_center_pixel.data[2]", "0"); | |
| 78 | |
| OLD | NEW |