OLD | NEW |
1 description("Ensure correct behavior when drawing a canvas on a canvas with shad
ows. A blue and red checkered pattern should be displayed."); | 1 description("Ensure correct behavior when drawing a canvas on a canvas with shad
ows. A blue and red checkered pattern should be displayed."); |
2 | 2 |
3 function print(message, color) | 3 function print(message, color) |
4 { | 4 { |
5 var paragraph = document.createElement("div"); | 5 var paragraph = document.createElement("div"); |
6 paragraph.appendChild(document.createTextNode(message)); | 6 paragraph.appendChild(document.createTextNode(message)); |
7 paragraph.style.fontFamily = "monospace"; | 7 paragraph.style.fontFamily = "monospace"; |
8 if (color) | 8 if (color) |
9 paragraph.style.color = color; | 9 paragraph.style.color = color; |
10 document.getElementById("console").appendChild(paragraph); | 10 document.getElementById("console").appendChild(paragraph); |
11 } | 11 } |
12 | 12 |
13 function shouldBeAround(a, b) | 13 function shouldBeAround(a, b) |
14 { | 14 { |
15 var evalA; | 15 var evalA; |
16 try { | 16 try { |
17 evalA = eval(a); | 17 evalA = eval(a); |
18 } catch(e) { | 18 } catch(e) { |
19 evalA = e; | 19 evalA = e; |
20 } | 20 } |
21 | 21 |
22 if (Math.abs(evalA - b) < 15) | 22 if (Math.abs(evalA - b) < 20) |
23 print("PASS " + a + " is around " + b , "green") | 23 print("PASS " + a + " is around " + b , "green") |
24 else | 24 else |
25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")",
"red"); | 25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")",
"red"); |
26 } | 26 } |
27 | 27 |
28 var canvas = document.createElement('canvas'); | 28 var canvas = document.createElement('canvas'); |
29 document.body.appendChild(canvas); | 29 document.body.appendChild(canvas); |
30 canvas.setAttribute('width', '600'); | 30 canvas.setAttribute('width', '600'); |
31 canvas.setAttribute('height', '600'); | 31 canvas.setAttribute('height', '600'); |
32 var ctx = canvas.getContext('2d'); | 32 var ctx = canvas.getContext('2d'); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 shouldBe('d[0]', '255'); | 124 shouldBe('d[0]', '255'); |
125 shouldBe('d[1]', '0'); | 125 shouldBe('d[1]', '0'); |
126 shouldBe('d[2]', '0'); | 126 shouldBe('d[2]', '0'); |
127 shouldBeAround('d[3]', '50'); | 127 shouldBeAround('d[3]', '50'); |
128 | 128 |
129 d = ctx.getImageData(450, 500, 1, 1).data; | 129 d = ctx.getImageData(450, 500, 1, 1).data; |
130 shouldBe('d[0]', '255'); | 130 shouldBe('d[0]', '255'); |
131 shouldBe('d[1]', '0'); | 131 shouldBe('d[1]', '0'); |
132 shouldBe('d[2]', '0'); | 132 shouldBe('d[2]', '0'); |
133 shouldBeAround('d[3]', '50'); | 133 shouldBeAround('d[3]', '50'); |
OLD | NEW |