Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <script src="../../resources/js-test.js"></script> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <script src="../../resources/testharnessreport.js"></script> | |
| 2 <script type='text/javascript'> | 3 <script type='text/javascript'> |
| 3 description("Test the handling of invalid arguments in canvas toBlob()."); | 4 async_test(t => { |
| 4 | 5 |
| 5 if (window.testRunner) { | 6 var numAsyncCalls = 2; |
| 6 testRunner.dumpAsText(); | 7 function finishOneAsyncCall() |
| 7 testRunner.waitUntilDone(); | 8 { |
| 8 } | 9 if (--numAsyncCalls == 0) |
| 10 t.done(); | |
| 11 } | |
| 12 | |
| 13 var canvas = document.createElement('canvas'); | |
| 14 var ctx = canvas.getContext("2d"); | |
| 15 ctx.strokeStyle = "red"; | |
| 16 ctx.strokeRect(0, 0, 50, 50); | |
| 17 | |
| 18 assert_throws(new TypeError(), function() {canvas.toBlob();}, "TypeError: Fa iled to execute 'toBlob' on 'HTMLCanvasElement': 1 argument required, but only 0 present."); | |
|
Justin Novosad
2017/02/16 22:32:42
Nit: better not to use the third argument of asser
| |
| 19 assert_throws(new TypeError(), function() {canvas.toBlob(null);}, "TypeError : Failed to execute 'toBlob' on 'HTMLCanvasElement': The callback provided as pa rameter 1 is not a function."); | |
| 20 assert_throws(new TypeError(), function() {canvas.toBlob(undefined);}, "Type Error: Failed to execute 'toBlob' on 'HTMLCanvasElement': The callback provided as parameter 1 is not a function."); | |
| 9 | 21 |
| 10 var numAsyncCalls = 2; | 22 // Passing the callback argument without blob handle silently fails. |
| 11 function finishOneAsyncCall() | 23 canvas.toBlob(function() { finishOneAsyncCall(); }); |
| 12 { | 24 |
| 13 numAsyncCalls--; | 25 // Invalid quality argument will fall back to default value |
| 14 if (numAsyncCalls == 0 && window.testRunner) { | 26 canvas.toBlob(function(blob) { finishOneAsyncCall(); }, 'image/jpeg', 500); |
| 15 testRunner.notifyDone(); | 27 |
| 16 } | 28 }, "Test the handling of invalid arguments in canvas toBlob()."); |
| 17 } | |
| 18 | |
| 19 var canvas = document.createElement('canvas'); | |
| 20 var ctx = canvas.getContext("2d"); | |
| 21 ctx.strokeStyle = "red"; | |
| 22 ctx.strokeRect(0, 0, 50, 50); | |
| 23 | |
| 24 shouldThrow("canvas.toBlob();"); | |
| 25 shouldThrow("canvas.toBlob(null);"); | |
| 26 shouldThrow("canvas.toBlob(undefined);"); | |
| 27 // Passing the callback argument without blob handle silently fails. | |
| 28 shouldNotThrow("canvas.toBlob(function() { finishOneAsyncCall(); });"); | |
| 29 | |
| 30 // Invalid quality argument will fall back to default value | |
| 31 shouldNotThrow("canvas.toBlob(function(blob) { finishOneAsyncCall(); }, 'image/j peg', 500)"); | |
| 32 </script> | 29 </script> |
| OLD | NEW |