Make generated canvas test parameters importable as Jinja templates
In the Canvas WPT test generator, the test body can have Jinja tags
referring to other test parameters. For instance:
code: |
@assert pixel 50,25 == {{ expected_color }};
expected_color: 'rgba(0, 255, 0, {{ alpha }})'
alpha: 1.0
Here, the `expected_color` parameter is first rendered, expanding the
`{{ alpha }}` tag. This result is then inserted into the `code`
template. This is useful to reuse values in multiple places. It however
doesn't allow reusing Jinja macros. Indeed, if `expected_color`
contained a `{% macro ... %}` tag, that tag would get lost as the
`expected_color` gets rendered (the macro itself is not part of the
rendering result).
To be able to reuse macros, we would need to use an `{% import ... %}`
tag. This CL makes this possible by registering the test parameters as
templates loadable by the Jinja environment. Thus, the following
becomes possible:
macros: |
{% macro calculate_color(...) %}
...
{% endmacro %}
code: |
{% import 'macros' as m %}
@assert pixel 50,25 == {{ m.calculate_color(...) }};
expected: |
{% import 'macros' as m %}
size 100 50
cr.set_source_rgba({{ m.calculate_color(...) }})
Bug: 40207206
Change-Id: Idff8495efffbcde1840256b5ac5bded1d7e6de55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6204442
Reviewed-by: Andres Ricardo Perez <andresrperez@chromium.org>
Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1420621}
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.
The project's web site is https://www.chromium.org.
To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.
Documentation in the source is rooted in docs/README.md.
Learn how to Get Around the Chromium Source Code Directory Structure.
For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.
If you found a bug, please file it at https://crbug.com/new.