blob: dda6dc314ddfe0af65927bbc6bba2753e1c854b8 [file] [log] [blame]
- name: 2d.state.saverestore.transformation
desc: save()/restore() affects the current transformation matrix
testing:
- 2d.state.transformation
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.save();
ctx.translate(200, 0);
ctx.restore();
ctx.fillStyle = '#f00';
ctx.fillRect(-200, 0, 100, 50);
@assert pixel 50,25 == 0,255,0,255;
expected: green
- name: 2d.state.saverestore.clip
desc: save()/restore() affects the clipping path
testing:
- 2d.state.clip
code: |
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
ctx.save();
ctx.rect(0, 0, 1, 1);
ctx.clip();
ctx.restore();
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
@assert pixel 50,25 == 0,255,0,255;
expected: green
- name: 2d.state.saverestore.path
desc: save()/restore() does not affect the current path
testing:
- 2d.state.path
code: |
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
ctx.save();
ctx.rect(0, 0, 100, 50);
ctx.restore();
ctx.fillStyle = '#0f0';
ctx.fill();
@assert pixel 50,25 == 0,255,0,255;
expected: green
- name: 2d.state.saverestore.bitmap
desc: save()/restore() does not affect the current bitmap
testing:
- 2d.state.bitmap
code: |
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
ctx.save();
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.restore();
@assert pixel 50,25 == 0,255,0,255;
expected: green
- name: 2d.state.saverestore.stack
desc: save()/restore() can be nested as a stack
testing:
- 2d.state.save
- 2d.state.restore
code: |
ctx.lineWidth = 1;
ctx.save();
ctx.lineWidth = 2;
ctx.save();
ctx.lineWidth = 3;
@assert ctx.lineWidth === 3;
ctx.restore();
@assert ctx.lineWidth === 2;
ctx.restore();
@assert ctx.lineWidth === 1;
- name: 2d.state.saverestore.stackdepth
desc: save()/restore() stack depth is not unreasonably limited
testing:
- 2d.state.save
- 2d.state.restore
code: |
var limit = 512;
for (var i = 1; i < limit; ++i)
{
ctx.save();
ctx.lineWidth = i;
}
for (var i = limit-1; i > 0; --i)
{
@assert ctx.lineWidth === i;
ctx.restore();
}
- name: 2d.state.saverestore.underflow
desc: restore() with an empty stack has no effect
testing:
- 2d.state.restore.underflow
code: |
for (var i = 0; i < 16; ++i)
ctx.restore();
ctx.lineWidth = 0.5;
ctx.restore();
@assert ctx.lineWidth === 0.5;