Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries)
Setup JS var c = document .createElement ('canvas' );
c.width = 1700 ;
c.height = 1000 ;
var ctx = c.getContext ('2d' );
ctx.fillStyle = '#000' ;
ctx.fillRect (0 , 0 , 1700 , 1000 );
var fill, global ;
Teardown JS
var p = ctx.getImageData (0 , 0 , 1 , 1 );
if (p.data [3 ] != 0 ) throw ("canvas did not clear!" );
Test cases
Test #1 Title *
Async
Code * ctx.clearRect (0 , 0 , c.width , c.height );
Test #2 Title *
Async
Code * global = ctx.globalCompositeOperation ;
fill = ctx.fillStyle ;
ctx.globalCompositeOperation = 'copy' ;
ctx.fillStyle = 'rgba(0,0,0,0)' ;
ctx.fillRect (0 , 0 , c.width , c.height );
ctx.globalCompositeOperation = global ;
ctx.fillStyle = fill;
Title *
Async
Code * c.width = c.width ;
Title *
Async
Code *
ctx.save ();
ctx.setTransform (1 , 0 , 0 , 1 , 0 , 0 );
ctx.clearRect (0 , 0 , c.width , c.height );
ctx.restore ();
Title *
Async
Code * ctx.putImageData (ctx.createImageData (c.width , c.height ), 0 , 0 );
Title *
Async
Code *
ctx.setTransform (1 , 0 , 0 , 1 , 0 , 0 );
ctx.clearRect (0 , 0 , c.width , c.height );
ctx.setTransform (1 , 0 , 0 , 1 , 0 , 0 );