OLD | NEW |
1 <!DOCTYPE HTML> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | 3 <script type="text/javascript" src="canvas-blending-helpers.js"></script> |
4 <script type="text/javascript"> | 4 <script> |
5 if (window.testRunner) | 5 function drawElement(context, i) { |
6 testRunner.waitUntilDone(); | 6 if (i >= blendModes.length) |
7 window.jsTestIsAsync = true | 7 return; |
8 </script> | 8 context.clearRect(0, 0, 10, 10); |
9 </head> | 9 context.save(); |
10 <body> | 10 drawBackdropColorPatternInContext(context, |
11 <script src="../../resources/js-test.js"></script> | 11 function() { |
12 <script type="text/javascript" src="canvas-blending-helpers.js"></script> | 12 context.globalCompositeOperation = blendModes[i]; |
13 <script type="text/javascript"> | 13 drawSourceColorGradientInContext(context); |
| 14 checkBlendModeResult(i, context, 5); |
| 15 context.restore(); |
| 16 drawElement(context, ++i); |
| 17 }); |
| 18 } |
14 | 19 |
15 description("Series of tests to ensure correct results on applying diffe
rent blend modes when drawing a gradient on top of an pattern."); | 20 test(function(t) { |
| 21 var canvas = document.createElement('canvas'); |
| 22 var sigma = 5; |
| 23 canvas.width = 10; |
| 24 canvas.height = 10; |
| 25 context = canvas.getContext('2d'); |
| 26 drawElement(context, 0); |
16 | 27 |
17 var context; | 28 }, 'Series of tests to ensure correct results on applying different blend modes
when drawing a gradient on top of an pattern.'); |
18 function actualColor(x, y) { | 29 </script> |
19 return context.getImageData(x, y, 1, 1).data; | |
20 } | |
21 | |
22 function checkBlendModeResult(i, context, sigma) { | |
23 var expectedColor = blendColors([129 / 255, 1, 129 / 255, 1], [1, 12
9 / 255, 129 / 255, 1], i); | |
24 var ac = "actualColor(0, 0)"; | |
25 shouldBeCloseTo(ac + "[0]", expectedColor[0], sigma); | |
26 shouldBeCloseTo(ac + "[1]", expectedColor[1], sigma); | |
27 shouldBeCloseTo(ac + "[2]", expectedColor[2], sigma); | |
28 shouldBeCloseTo(ac + "[3]", expectedColor[3], sigma); | |
29 } | |
30 | |
31 function drawElement(context, i) { | |
32 if (i >= blendModes.length) { | |
33 finishJSTest(); | |
34 return; | |
35 } | |
36 debug("Testing blend mode " + blendModes[i]); | |
37 | |
38 context.clearRect(0, 0, 10, 10); | |
39 context.save(); | |
40 drawBackdropColorPatternInContext(context, | |
41 function() { | |
42 context.globalCompositeOperation = blendModes[i]; | |
43 drawSourceColorGradientInContext(context); | |
44 checkBlendModeResult(i, context, 5); | |
45 context.restore(); | |
46 debug(''); | |
47 drawElement(context, ++i); | |
48 }); | |
49 } | |
50 | |
51 function runTest() { | |
52 var canvas = document.createElement("canvas"); | |
53 var sigma = 5; | |
54 canvas.width = 10; | |
55 canvas.height = 10; | |
56 context = canvas.getContext("2d"); | |
57 drawElement(context, 0); | |
58 } | |
59 | |
60 runTest(); | |
61 </script> | |
62 </body> | |
63 </html> | |
OLD | NEW |