OLD | NEW |
| (Empty) |
1 description("Test for canvas regression where gradient clips were not cleared ht
tps://bugs.webkit.org/show_bug.cgi?id=21498") | |
2 | |
3 function pixelValueAt(context, x, y) { | |
4 var imageData = context.getImageData(x, y, 1, 1); | |
5 return imageData.data; | |
6 } | |
7 | |
8 function pixelToString(p) { | |
9 return "[" + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + "]" | |
10 } | |
11 | |
12 function pixelShouldBe(context, x, y, expectedPixelString) { | |
13 var pixel = pixelValueAt(context, x, y); | |
14 var expectedPixel = eval(expectedPixelString); | |
15 | |
16 var pixelString = "pixel " + x + ", " + y; | |
17 if (areArraysEqual(pixel, expectedPixel)) { | |
18 testPassed(pixelString + " is " + pixelToString(pixel)); | |
19 } else { | |
20 testFailed(pixelString + " should be " + pixelToString(expectedPixel) +
" was " + pixelToString(pixel)); | |
21 } | |
22 } | |
23 | |
24 function fillWithColor(context, color) { | |
25 context.save(); | |
26 context.fillStyle = color; | |
27 context.fillRect(0, 0, canvas.width, canvas.height); | |
28 context.restore(); | |
29 } | |
30 | |
31 var canvas = document.createElement("canvas"); | |
32 canvas.height = 100; | |
33 canvas.width = 100; | |
34 canvas.style.height = "100"; | |
35 canvas.style.width = "100"; | |
36 | |
37 document.body.appendChild(canvas); | |
38 | |
39 var greenImage = document.createElement("canvas"); | |
40 greenImage.height = 10; | |
41 greenImage.width = 10; | |
42 var greenCtx = greenImage.getContext('2d'); | |
43 fillWithColor(greenCtx, "green"); | |
44 var greenPixel = pixelValueAt(greenCtx, 0, 0); | |
45 | |
46 | |
47 var ctx = canvas.getContext('2d'); | |
48 var gradient = ctx.createLinearGradient(0, 0, 10, 0); | |
49 gradient.addColorStop(0, "blue"); | |
50 gradient.addColorStop(1, "red"); | |
51 ctx.fillStyle = gradient; | |
52 ctx.beginPath(); | |
53 ctx.moveTo(0, 0); | |
54 ctx.lineTo(10, 5); | |
55 ctx.lineTo(10, 10); | |
56 ctx.lineTo(5, 10); | |
57 ctx.closePath(); | |
58 ctx.fill(); | |
59 | |
60 ctx.fillStyle = "green"; | |
61 ctx.fillRect(20, 20, 10, 10); | |
62 | |
63 pixelShouldBe(ctx, 20, 20, "greenPixel"); | |
OLD | NEW |