commit-queue@webkit.org | b7ac53f | 2010-11-26 11:52:32 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 | <html> |
| 3 | <head> |
mark.lam@apple.com | 104d993 | 2013-09-07 22:20:15 +0000 | [diff] [blame] | 4 | <script src="../../resources/js-test-pre.js"></script> |
commit-queue@webkit.org | b7ac53f | 2010-11-26 11:52:32 +0000 | [diff] [blame] | 5 | </head> |
| 6 | <body> |
ap@apple.com | 92352d0 | 2017-05-24 22:53:00 +0000 | [diff] [blame] | 7 | <script> |
| 8 | description("Ensure correct behavior of canvas with fillRect shadow"); |
| 9 | |
| 10 | function print(message, color) |
| 11 | { |
| 12 | var paragraph = document.createElement("div"); |
| 13 | paragraph.appendChild(document.createTextNode(message)); |
| 14 | paragraph.style.fontFamily = "monospace"; |
| 15 | if (color) |
| 16 | paragraph.style.color = color; |
| 17 | document.getElementById("console").appendChild(paragraph); |
| 18 | } |
| 19 | |
| 20 | function shouldBeAround(a, b) |
| 21 | { |
| 22 | var evalA; |
| 23 | try { |
| 24 | evalA = eval(a); |
| 25 | } catch(e) { |
| 26 | evalA = e; |
| 27 | } |
| 28 | |
| 29 | if (Math.abs(evalA - b) < 5) |
| 30 | print("PASS " + a + " is around " + b , "green") |
| 31 | else |
| 32 | print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red"); |
| 33 | } |
| 34 | |
| 35 | function shouldBeSmaller(a, b) |
| 36 | { |
| 37 | var evalA; |
| 38 | try { |
| 39 | evalA = eval(a); |
| 40 | } catch(e) { |
| 41 | evalA = e; |
| 42 | } |
| 43 | |
| 44 | if (evalA < b) |
| 45 | print("PASS " + a + " is smaller than " + b , "green") |
| 46 | else |
| 47 | print("FAIL " + a + " is not smaller than " + b + " (actual: " + evalA + ")", "red"); |
| 48 | } |
| 49 | |
| 50 | var canvas = document.createElement('canvas'); |
| 51 | document.body.appendChild(canvas); |
| 52 | canvas.setAttribute('width', '400'); |
| 53 | canvas.setAttribute('height', '650'); |
| 54 | var ctx = canvas.getContext('2d'); |
| 55 | |
| 56 | ctx.shadowOffsetX = 200; |
| 57 | ctx.fillStyle = 'rgba(0, 0, 255, 1)'; |
| 58 | |
| 59 | ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; |
| 60 | ctx.fillRect(50, 50, 100, 100); |
| 61 | |
| 62 | ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; |
| 63 | ctx.fillRect(50, 200, 100, 100); |
| 64 | |
| 65 | ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; |
| 66 | ctx.shadowBlur = 5; |
| 67 | ctx.fillRect(50, 350, 100, 100); |
| 68 | |
| 69 | ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; |
| 70 | ctx.fillRect(50, 500, 100, 100); |
| 71 | |
| 72 | var d; // imageData.data |
| 73 | |
| 74 | // Verify solid shadow. |
| 75 | d = ctx.getImageData(250, 50, 1, 1).data; |
| 76 | shouldBe('d[0]', '255'); |
| 77 | shouldBe('d[1]', '0'); |
| 78 | shouldBe('d[2]', '0'); |
| 79 | shouldBe('d[3]', '255'); |
| 80 | |
| 81 | d = ctx.getImageData(250, 149, 1, 1).data; |
| 82 | shouldBe('d[0]', '255'); |
| 83 | shouldBe('d[1]', '0'); |
| 84 | shouldBe('d[2]', '0'); |
| 85 | shouldBe('d[3]', '255'); |
| 86 | |
| 87 | d = ctx.getImageData(349, 50, 1, 1).data; |
| 88 | shouldBe('d[0]', '255'); |
| 89 | shouldBe('d[1]', '0'); |
| 90 | shouldBe('d[2]', '0'); |
| 91 | shouldBe('d[3]', '255'); |
| 92 | |
| 93 | d = ctx.getImageData(349, 149, 1, 1).data; |
| 94 | shouldBe('d[0]', '255'); |
| 95 | shouldBe('d[1]', '0'); |
| 96 | shouldBe('d[2]', '0'); |
| 97 | shouldBe('d[3]', '255'); |
| 98 | |
| 99 | // Verify solid alpha shadow. |
| 100 | d = ctx.getImageData(250, 200, 1, 1).data; |
| 101 | shouldBe('d[0]', '255'); |
| 102 | shouldBe('d[1]', '0'); |
| 103 | shouldBe('d[2]', '0'); |
| 104 | shouldBeAround('d[3]', '76'); |
| 105 | |
| 106 | d = ctx.getImageData(250, 299, 1, 1).data; |
| 107 | shouldBe('d[0]', '255'); |
| 108 | shouldBe('d[1]', '0'); |
| 109 | shouldBe('d[2]', '0'); |
| 110 | shouldBeAround('d[3]', '76'); |
| 111 | |
| 112 | d = ctx.getImageData(349, 200, 1, 1).data; |
| 113 | shouldBe('d[0]', '255'); |
| 114 | shouldBe('d[1]', '0'); |
| 115 | shouldBe('d[2]', '0'); |
| 116 | shouldBeAround('d[3]', '76'); |
| 117 | |
| 118 | d = ctx.getImageData(349, 299, 1, 1).data; |
| 119 | shouldBe('d[0]', '255'); |
| 120 | shouldBe('d[1]', '0'); |
| 121 | shouldBe('d[2]', '0'); |
| 122 | shouldBeAround('d[3]', '76'); |
| 123 | |
| 124 | // Verify blurry shadow. |
| 125 | d = ctx.getImageData(248, 348, 1, 1).data; |
| 126 | shouldBe('d[0]', '255'); |
| 127 | shouldBe('d[1]', '0'); |
| 128 | shouldBe('d[2]', '0'); |
| 129 | shouldBeSmaller('d[3]', '25'); |
| 130 | |
| 131 | d = ctx.getImageData(248, 451, 1, 1).data; |
| 132 | shouldBe('d[0]', '255'); |
| 133 | shouldBe('d[1]', '0'); |
| 134 | shouldBe('d[2]', '0'); |
| 135 | shouldBeSmaller('d[3]', '25'); |
| 136 | |
| 137 | d = ctx.getImageData(351, 348, 1, 1).data; |
| 138 | shouldBe('d[0]', '255'); |
| 139 | shouldBe('d[1]', '0'); |
| 140 | shouldBe('d[2]', '0'); |
| 141 | shouldBeSmaller('d[3]', '25'); |
| 142 | |
| 143 | d = ctx.getImageData(351, 451, 1, 1).data; |
| 144 | shouldBe('d[0]', '255'); |
| 145 | shouldBe('d[1]', '0'); |
| 146 | shouldBe('d[2]', '0'); |
| 147 | shouldBeSmaller('d[3]', '25'); |
| 148 | |
| 149 | // Verify blurry alpha shadow. |
| 150 | d = ctx.getImageData(248, 498, 1, 1).data; |
| 151 | shouldBe('d[0]', '255'); |
| 152 | shouldBe('d[1]', '0'); |
| 153 | shouldBe('d[2]', '0'); |
| 154 | shouldBeSmaller('d[3]', '10'); |
| 155 | |
| 156 | d = ctx.getImageData(248, 601, 1, 1).data; |
| 157 | shouldBe('d[0]', '255'); |
| 158 | shouldBe('d[1]', '0'); |
| 159 | shouldBe('d[2]', '0'); |
| 160 | shouldBeSmaller('d[3]', '10'); |
| 161 | |
| 162 | d = ctx.getImageData(351, 498, 1, 1).data; |
| 163 | shouldBe('d[0]', '255'); |
| 164 | shouldBe('d[1]', '0'); |
| 165 | shouldBe('d[2]', '0'); |
| 166 | shouldBeSmaller('d[3]', '10'); |
| 167 | |
| 168 | d = ctx.getImageData(351, 601, 1, 1).data; |
| 169 | shouldBe('d[0]', '255'); |
| 170 | shouldBe('d[1]', '0'); |
| 171 | shouldBe('d[2]', '0'); |
| 172 | shouldBeSmaller('d[3]', '10'); |
| 173 | </script> |
mark.lam@apple.com | 104d993 | 2013-09-07 22:20:15 +0000 | [diff] [blame] | 174 | <script src="../../resources/js-test-post.js"></script> |
commit-queue@webkit.org | b7ac53f | 2010-11-26 11:52:32 +0000 | [diff] [blame] | 175 | </body> |
| 176 | </html> |