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