2d.fillStyle.toStringFunctionCallback.html (1814B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <meta charset="UTF-8"> 4 <title>OffscreenCanvas test: 2d.fillStyle.toStringFunctionCallback</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/html/canvas/resources/canvas-tests.js"></script> 8 9 <h1>2d.fillStyle.toStringFunctionCallback</h1> 10 <p class="desc">Passing a function in to ctx.fillStyle or ctx.strokeStyle with a toString callback works as specified</p> 11 12 13 <script> 14 var t = async_test("Passing a function in to ctx.fillStyle or ctx.strokeStyle with a toString callback works as specified"); 15 var t_pass = t.done.bind(t); 16 var t_fail = t.step_func(function(reason) { 17 throw reason; 18 }); 19 t.step(function() { 20 21 var canvas = new OffscreenCanvas(100, 50); 22 var ctx = canvas.getContext('2d'); 23 24 ctx.fillStyle = { toString: function() { return "#008000"; } }; 25 _assertSame(ctx.fillStyle, "#008000", "ctx.fillStyle", "\"#008000\""); 26 ctx.fillStyle = {}; 27 _assertSame(ctx.fillStyle, "#008000", "ctx.fillStyle", "\"#008000\""); 28 ctx.fillStyle = 800000; 29 _assertSame(ctx.fillStyle, "#008000", "ctx.fillStyle", "\"#008000\""); 30 assert_throws_js(TypeError, function() { ctx.fillStyle = { toString: function() { throw new TypeError; } }; }); 31 ctx.strokeStyle = { toString: function() { return "#008000"; } }; 32 _assertSame(ctx.strokeStyle, "#008000", "ctx.strokeStyle", "\"#008000\""); 33 ctx.strokeStyle = {}; 34 _assertSame(ctx.strokeStyle, "#008000", "ctx.strokeStyle", "\"#008000\""); 35 ctx.strokeStyle = 800000; 36 _assertSame(ctx.strokeStyle, "#008000", "ctx.strokeStyle", "\"#008000\""); 37 assert_throws_js(TypeError, function() { ctx.strokeStyle = { toString: function() { throw new TypeError; } }; }); 38 t.done(); 39 40 }); 41 </script>