Skip to content

Commit

Permalink
Unify template to create canvas and offscreencanvas tests (#31822)
Browse files Browse the repository at this point in the history
The typical way to add tests for canvas and offscreencanvas is as
following:
- write the test in yaml/element (create the test for canvas)
- copy the the test to yaml/offscreencanvas
- add t.done() to the end of test (create the test for offscreencanvas)

This is because the API for canvas and offscreencanvas are mostly the
same.

This cl updates templates and gentestutils to allow the framework of
generate canvas and offscreencanvas test from test.

I removed both yaml/element/color_space.yaml and
yaml/offscreencanvas/color_space.yaml and add yaml_new/color_space.yaml.
Now the yaml_new/color_space.yaml generates the same results as before.

Note that it's possible to add test for a particular canvas type
by using canvasType as keyword.

Bug: 1275750
Change-Id: I6bf48ec3081f5fe3669bf585f92b39a712045c6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3307080
Reviewed-by: Fernando Serboncini <[email protected]>
Reviewed-by: Juanmi Huertas <[email protected]>
Commit-Queue: Yi Xu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#947713}

Co-authored-by: Yi Xu <[email protected]>
  • Loading branch information
chromium-wpt-export-bot and yiyix committed Dec 4, 2021
1 parent e9a0e96 commit ff72283
Show file tree
Hide file tree
Showing 12 changed files with 609 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ <h1>2d.color.space.p3.to.p3</h1>
_addTest(function(canvas, ctx) {

var color_style = 'rgb(50, 100, 150)';
var epsilon = 2;
// [0.24304, 0.38818, 0.57227, 1.0] * 255 = [62, 99, 146, 255]
var pixel_expected = [62, 99, 146, 255];
var epsilon = 2;
ctx.fillStyle = color_style;
ctx.fillRect(0, 0, 10, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ <h1>2d.color.space.p3.to.srgb</h1>
_addTest(function(canvas, ctx) {

var color_style = 'rgb(50, 100, 150)';
var epsilon = 2;
var pixel_expected = [50, 100, 150, 255];
var epsilon = 2;
ctx.fillStyle = color_style;
ctx.fillRect(0, 0, 10, 10);

Expand Down
6 changes: 4 additions & 2 deletions html/canvas/tools/gentest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from gentestutils import genTestUtils
from gentestutilsunion import genTestUtils_union

genTestUtils('../element', '../element', 'templates.yaml', 'name2dir.yaml', False)
genTestUtils('../offscreen', '../offscreen', 'templates-offscreen.yaml', 'name2dir-offscreen.yaml', True)
genTestUtils('../element', '../element', 'templates.yaml', 'name2dir-canvas.yaml', False)
genTestUtils('../offscreen', '../offscreen', 'templates.yaml', 'name2dir-offscreen.yaml', True)
genTestUtils_union('templates-new.yaml', 'name2dir-canvas.yaml')
3 changes: 3 additions & 0 deletions html/canvas/tools/gentest_union.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from gentestutilsunion import genTestUtils_union

genTestUtils_union('templates-new.yaml', 'name2dir-canvas.yaml')
8 changes: 5 additions & 3 deletions html/canvas/tools/gentestutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,15 @@ def expand_test_code(code):
'fallback':fallback, 'attributes':attributes,
'context_args': context_args
}

f = codecs.open('%s/%s%s.html' % (TESTOUTPUTDIR, mapped_name, name_variant), 'w', 'utf-8')
f.write(templates['w3c'] % template_params)
if ISOFFSCREENCANVAS:
f = codecs.open('%s/%s%s.html' % (TESTOUTPUTDIR, mapped_name, name_variant), 'w', 'utf-8')
f.write(templates['w3coffscreencanvas'] % template_params)
timeout = '// META: timeout=%s\n' % test['timeout'] if 'timeout' in test else ''
template_params['timeout'] = timeout
f = codecs.open('%s/%s%s.worker.js' % (TESTOUTPUTDIR, mapped_name, name_variant), 'w', 'utf-8')
f.write(templates['w3cworker'] % template_params)
else:
f = codecs.open('%s/%s%s.html' % (TESTOUTPUTDIR, mapped_name, name_variant), 'w', 'utf-8')
f.write(templates['w3ccanvas'] % template_params)

print()
Loading

0 comments on commit ff72283

Please sign in to comment.