| OLD | NEW |
| (Empty) |
| 1 description("Ensure correct behavior of canvas with fillRect+shadow after scalin
g. A blue and red checkered pattern should be displayed."); | |
| 2 | |
| 3 function print(message, color) | |
| 4 { | |
| 5 var paragraph = document.createElement("div"); | |
| 6 paragraph.appendChild(document.createTextNode(message)); | |
| 7 paragraph.style.fontFamily = "monospace"; | |
| 8 if (color) | |
| 9 paragraph.style.color = color; | |
| 10 document.getElementById("console").appendChild(paragraph); | |
| 11 } | |
| 12 | |
| 13 function shouldBeAround(a, b) | |
| 14 { | |
| 15 var evalA; | |
| 16 try { | |
| 17 evalA = eval(a); | |
| 18 } catch(e) { | |
| 19 evalA = e; | |
| 20 } | |
| 21 | |
| 22 if (Math.abs(evalA - b) < 20) | |
| 23 print("PASS " + a + " is around " + b , "green") | |
| 24 else | |
| 25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")",
"red"); | |
| 26 } | |
| 27 | |
| 28 var canvas = document.createElement('canvas'); | |
| 29 document.body.appendChild(canvas); | |
| 30 canvas.setAttribute('width', '1000'); | |
| 31 canvas.setAttribute('height', '1000'); | |
| 32 var ctx = canvas.getContext('2d'); | |
| 33 | |
| 34 ctx.scale(2, 2); | |
| 35 ctx.shadowOffsetX = 100; | |
| 36 ctx.shadowOffsetY = 100; | |
| 37 ctx.fillStyle = 'rgba(0, 0, 255, 1)'; | |
| 38 | |
| 39 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
| 40 ctx.fillRect(50, 50, 50, 50); | |
| 41 | |
| 42 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; | |
| 43 ctx.fillRect(50, 150, 50, 50); | |
| 44 | |
| 45 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
| 46 ctx.shadowBlur = 10; | |
| 47 ctx.fillRect(150, 50, 50, 50); | |
| 48 | |
| 49 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; | |
| 50 ctx.fillRect(150, 150, 50, 50); | |
| 51 | |
| 52 var d; // imageData.data | |
| 53 | |
| 54 // Verify solid shadow. | |
| 55 d = ctx.getImageData(201, 205, 1, 1).data; | |
| 56 shouldBe('d[0]', '255'); | |
| 57 shouldBe('d[1]', '0'); | |
| 58 shouldBe('d[2]', '0'); | |
| 59 shouldBe('d[3]', '255'); | |
| 60 | |
| 61 d = ctx.getImageData(298, 298, 1, 1).data; | |
| 62 shouldBe('d[0]', '255'); | |
| 63 shouldBe('d[1]', '0'); | |
| 64 shouldBe('d[2]', '0'); | |
| 65 shouldBe('d[3]', '255'); | |
| 66 | |
| 67 d = ctx.getImageData(201, 298, 1, 1).data; | |
| 68 shouldBe('d[0]', '255'); | |
| 69 shouldBe('d[1]', '0'); | |
| 70 shouldBe('d[2]', '0'); | |
| 71 shouldBe('d[3]', '255'); | |
| 72 | |
| 73 // Verify solid alpha shadow. | |
| 74 d = ctx.getImageData(201, 405, 1, 1).data; | |
| 75 shouldBe('d[0]', '255'); | |
| 76 shouldBe('d[1]', '0'); | |
| 77 shouldBe('d[2]', '0'); | |
| 78 shouldBeAround('d[3]', '76'); | |
| 79 | |
| 80 d = ctx.getImageData(298, 405, 1, 1).data; | |
| 81 shouldBe('d[0]', '255'); | |
| 82 shouldBe('d[1]', '0'); | |
| 83 shouldBe('d[2]', '0'); | |
| 84 shouldBeAround('d[3]', '76'); | |
| 85 | |
| 86 d = ctx.getImageData(205, 498, 1, 1).data; | |
| 87 shouldBe('d[0]', '255'); | |
| 88 shouldBe('d[1]', '0'); | |
| 89 shouldBe('d[2]', '0'); | |
| 90 shouldBeAround('d[3]', '76'); | |
| 91 | |
| 92 // Verify blurry shadow. | |
| 93 d = ctx.getImageData(398, 205, 1, 1).data; | |
| 94 shouldBe('d[0]', '255'); | |
| 95 shouldBe('d[1]', '0'); | |
| 96 shouldBe('d[2]', '0'); | |
| 97 shouldBeAround('d[3]', '83'); | |
| 98 | |
| 99 d = ctx.getImageData(501, 205, 1, 1).data; | |
| 100 shouldBe('d[0]', '255'); | |
| 101 shouldBe('d[1]', '0'); | |
| 102 shouldBe('d[2]', '0'); | |
| 103 shouldBeAround('d[3]', '83'); | |
| 104 | |
| 105 d = ctx.getImageData(500, 300, 1, 1).data; | |
| 106 shouldBe('d[0]', '255'); | |
| 107 shouldBe('d[1]', '0'); | |
| 108 shouldBe('d[2]', '0'); | |
| 109 shouldBeAround('d[3]', '53'); | |
| 110 | |
| 111 // Verify blurry alpha shadow. | |
| 112 d = ctx.getImageData(398, 405, 1, 1).data; | |
| 113 shouldBe('d[0]', '255'); | |
| 114 shouldBe('d[1]', '0'); | |
| 115 shouldBe('d[2]', '0'); | |
| 116 shouldBeAround('d[3]', '24'); | |
| 117 | |
| 118 d = ctx.getImageData(405, 501, 1, 1).data; | |
| 119 shouldBe('d[0]', '255'); | |
| 120 shouldBe('d[1]', '0'); | |
| 121 shouldBe('d[2]', '0'); | |
| 122 shouldBeAround('d[3]', '24'); | |
| 123 | |
| 124 d = ctx.getImageData(405, 501, 1, 1).data; | |
| 125 shouldBe('d[0]', '255'); | |
| 126 shouldBe('d[1]', '0'); | |
| 127 shouldBe('d[2]', '0'); | |
| 128 shouldBeAround('d[3]', '24'); | |
| OLD | NEW |