Skip to content

Commit

Permalink
Move 2d.state.saverestore.* and 2d.canvas.host.initial.* to yaml-new
Browse files Browse the repository at this point in the history
Bug: 40207206
Change-Id: Ie5cfa63d2681e6d3f80216db3c89dc461f368195
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5593168
Reviewed-by: Yi Xu <[email protected]>
Commit-Queue: Jean-Philippe Gravel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1309493}
  • Loading branch information
graveljp authored and chromium-wpt-export-bot committed Jun 4, 2024
1 parent 708284f commit 215c5cc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ <h1>2d.canvas.host.initial.reset.2dstate</h1>
ctx.globalCompositeOperation = "copy";
canvas.width = 100;
_assertSame(ctx.globalCompositeOperation, default_val, "ctx.globalCompositeOperation", "default_val");

t.done();

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ t.step(function() {
ctx.globalCompositeOperation = "copy";
canvas.width = 100;
_assertSame(ctx.globalCompositeOperation, default_val, "ctx.globalCompositeOperation", "default_val");

t.done();
});
done();
69 changes: 69 additions & 0 deletions html/canvas/tools/yaml-new/the-canvas-state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,72 @@
ctx.lineWidth = 0.5;
ctx.restore();
@assert ctx.lineWidth === 0.5;
- name: 2d.state.saverestore
desc: save()/restore() works for {{ variant_names[0] }}
code: |
// Test that restore() undoes any modifications
var old = ctx.{{ variant_names[0] }};
ctx.save();
ctx.{{ variant_names[0] }} = {{ value }};
ctx.restore();
_assertSame(ctx.{{ variant_names[0] }}, old, "ctx.{{ variant_names[0] }}", "old");
// Also test that save() doesn't modify the values
ctx.{{ variant_names[0] }} = {{ value }};
old = ctx.{{ variant_names[0] }};
// we're not interested in failures caused by get(set(x)) != x (e.g.
// from rounding), so compare against 'old' instead of against {{ value }}
ctx.save();
_assertSame(ctx.{{ variant_names[0] }}, old, "ctx.{{ variant_names[0] }}", "old");
ctx.restore();
variants:
- &2d_state_test_cases
strokeStyle:
value: '"#ff0000"'
fillStyle:
value: '"#ff0000"'
globalAlpha:
value: 0.5
lineWidth:
value: 0.5
lineCap:
value: '"round"'
lineJoin:
value: '"round"'
miterLimit:
value: 0.5
shadowOffsetX:
value: 5
shadowOffsetY:
value: 5
shadowBlur:
value: 5
shadowColor:
value: '"#ff0000"'
globalCompositeOperation:
value: '"copy"'
font:
canvas_types: ['HtmlCanvas']
value: '"25px serif"'
textAlign:
canvas_types: ['HtmlCanvas']
value: '"center"'
textBaseline:
canvas_types: ['HtmlCanvas']
value: '"bottom"'

- name: 2d.canvas.host.initial.reset.2dstate
desc: Resetting the canvas state resets 2D state variables
code: |
canvas.width = 100;
var default_val;
{% for state, params in states.items()
if not params['canvas_types'] or canvas_type in params['canvas_types'] %}
default_val = ctx.{{ state }};
ctx.{{ state }} = {{ params['value'] }};
canvas.width = 100;
@assert ctx.{{ state }} === default_val;
{% endfor %}
states: *2d_state_test_cases
59 changes: 1 addition & 58 deletions html/canvas/tools/yaml/element/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,63 +60,6 @@
"expected": expected
} )
- meta: |
state = [ # some non-default values to test with
('strokeStyle', '"#ff0000"'),
('fillStyle', '"#ff0000"'),
('globalAlpha', 0.5),
('lineWidth', 0.5),
('lineCap', '"round"'),
('lineJoin', '"round"'),
('miterLimit', 0.5),
('shadowOffsetX', 5),
('shadowOffsetY', 5),
('shadowBlur', 5),
('shadowColor', '"#ff0000"'),
('globalCompositeOperation', '"copy"'),
('font', '"25px serif"'),
('textAlign', '"center"'),
('textBaseline', '"bottom"'),
]
for key,value in state:
tests.append( {
'name': '2d.state.saverestore.%s' % key,
'desc': 'save()/restore() works for %s' % key,
'code':
"""// Test that restore() undoes any modifications
var old = ctx.%(key)s;
ctx.save();
ctx.%(key)s = %(value)s;
ctx.restore();
@assert ctx.%(key)s === old;
// Also test that save() doesn't modify the values
ctx.%(key)s = %(value)s;
old = ctx.%(key)s;
// we're not interested in failures caused by get(set(x)) != x (e.g.
// from rounding), so compare against 'old' instead of against %(value)s
ctx.save();
@assert ctx.%(key)s === old;
ctx.restore();
""" % { 'key':key, 'value':value }
} )
tests.append( {
'name': '2d.canvas.host.initial.reset.2dstate',
'desc': 'Resetting the canvas state resets 2D state variables',
'code':
"""canvas.width = 100;
var default_val;
""" + "".join(
"""
default_val = ctx.%(key)s;
ctx.%(key)s = %(value)s;
canvas.width = 100;
@assert ctx.%(key)s === default_val;
""" % { 'key':key, 'value':value }
for key,value in state),
} )
- meta: |
# Composite operation tests
# <http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-March/010608.html>
Expand Down Expand Up @@ -530,4 +473,4 @@
@assert ctx.fillStyle =~ /^#(?!(FF0000|ff0000|f00)$)/; // test that it's not red
""" % (string,),
}
tests.append(test)
tests.append(test)
55 changes: 0 additions & 55 deletions html/canvas/tools/yaml/offscreen/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
- meta: |
state = [ # some non-default values to test with
('strokeStyle', '"#ff0000"'),
('fillStyle', '"#ff0000"'),
('globalAlpha', 0.5),
('lineWidth', 0.5),
('lineCap', '"round"'),
('lineJoin', '"round"'),
('miterLimit', 0.5),
('shadowOffsetX', 5),
('shadowOffsetY', 5),
('shadowBlur', 5),
('shadowColor', '"#ff0000"'),
('globalCompositeOperation', '"copy"'),
]
for key,value in state:
tests.append( {
'name': '2d.state.saverestore.%s' % key,
'desc': 'save()/restore() works for %s' % key,
'code':
"""// Test that restore() undoes any modifications
var old = ctx.%(key)s;
ctx.save();
ctx.%(key)s = %(value)s;
ctx.restore();
@assert ctx.%(key)s === old;
// Also test that save() doesn't modify the values
ctx.%(key)s = %(value)s;
old = ctx.%(key)s;
// we're not interested in failures caused by get(set(x)) != x (e.g.
// from rounding), so compare against 'old' instead of against %(value)s
ctx.save();
@assert ctx.%(key)s === old;
ctx.restore();
t.done();
""" % { 'key':key, 'value':value }
} )
tests.append( {
'name': '2d.canvas.host.initial.reset.2dstate',
'desc': 'Resetting the canvas state resets 2D state variables',
'code':
"""canvas.width = 100;
var default_val;
""" + "".join(
"""
default_val = ctx.%(key)s;
ctx.%(key)s = %(value)s;
canvas.width = 100;
@assert ctx.%(key)s === default_val;
""" % { 'key':key, 'value':value }
for key,value in state) + "\nt.done();",
} )
- meta: |
# Composite operation tests
# <http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-March/010608.html>
Expand Down

0 comments on commit 215c5cc

Please sign in to comment.