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