Skip to content

Commit

Permalink
Consolidate reference_file and is_test_reference into a single param
Browse files Browse the repository at this point in the history
The Canvas WPT test generator was using two variables to control how a
test file links to it's reference file: 'reference_file' and
'is_test_reference'. In the context of documenting all parameters,
having to explain why we have two different parameters to do this one
thing is awkward. The logic and documentation will be simpler by using a
single 'reference_file_link' parameter.

Bug: 393561071
Change-Id: Id4523455f72ceb94684799cd672d11d87c106653
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6219871
Reviewed-by: Andres Ricardo Perez <[email protected]>
Commit-Queue: Jean-Philippe Gravel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1423298}
  • Loading branch information
graveljp authored and chromium-wpt-export-bot committed Feb 22, 2025
1 parent 5bcf44c commit 463424c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions html/canvas/tools/gentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,17 @@ def _write_reference_test(self, jinja_env: jinja2.Environment,
else f'{output_files.offscreen}-expected.html'),
}
for canvas_type, params in self._canvas_type_params.items():
params['reference_file'] = pathlib.Path(
ref_output_paths[canvas_type]).name
_render(jinja_env, test_templates[canvas_type], params,
test_output_paths[canvas_type])

# Generate reference file.
if canvas_type != _CanvasType.WORKER or needs_worker_reference:
params['is_test_reference'] = True
_render(jinja_env, ref_templates[self.template_type], params,
ref_output_paths[canvas_type])

# Generate test file, with a link to the reference file.
params['reference_file_link'] = pathlib.Path(
ref_output_paths[canvas_type]).name
_render(jinja_env, test_templates[canvas_type], params,
test_output_paths[canvas_type])

def _write_testharness_test(self, jinja_env: jinja2.Environment,
output_files: _OutputPaths):
grid = '_grid' if len(self.variants) > 1 else ''
Expand Down
6 changes: 3 additions & 3 deletions html/canvas/tools/templates/reftest_element.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<meta charset="UTF-8">
{% if test_type == 'promise' %}<html class="reftest-wait">
{% endif %}
{% if not is_test_reference %}
<link rel="match" href="{{ reference_file }}">
{% if reference_file_link %}
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% endif %}
Expand All @@ -21,7 +21,7 @@ <h1>{{ name }}</h1>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d'{% if attributes %}, {{ attributes }}{% endif %});

{{ reference | trim | indent(2) if is_test_reference else
{{ reference | trim | indent(2) if not reference_file_link else
code | trim | indent(2) }}
{% if test_type == 'promise' %}
document.documentElement.classList.remove("reftest-wait");
Expand Down
6 changes: 3 additions & 3 deletions html/canvas/tools/templates/reftest_element_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{% if test_type == 'promise' %}<html class="reftest-wait">
<script>pending_tests = {{ variants | length }};</script>
{% endif %}
{% if not is_test_reference %}
<link rel="match" href="{{ reference_file }}">
{% if reference_file_link %}
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% endif %}
Expand Down Expand Up @@ -41,7 +41,7 @@ <h1>{{ name }}</h1>
const ctx = canvas.getContext('2d'{%
if variant.attributes %}, {{ variant.attributes }}{% endif %});

{{ variant.reference | trim | indent(4) if is_test_reference else
{{ variant.reference | trim | indent(4) if not reference_file_link else
variant.code | trim | indent(4) }}
{% if test_type == 'promise' %}
if (--pending_tests == 0) {
Expand Down
2 changes: 1 addition & 1 deletion html/canvas/tools/templates/reftest_offscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta charset="UTF-8">
{% if test_type == 'promise' %}<html class="reftest-wait">
{% endif %}
<link rel="match" href="{{ reference_file }}">
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% if timeout %}<meta name="timeout" content="{{ timeout }}">
Expand Down
2 changes: 1 addition & 1 deletion html/canvas/tools/templates/reftest_offscreen_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if test_type == 'promise' %}<html class="reftest-wait">
<script>pending_tests = {{ variants | length }};</script>
{% endif %}
<link rel="match" href="{{ reference_file }}">
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% if timeout %}<meta name="timeout" content="{{ timeout }}">
Expand Down
2 changes: 1 addition & 1 deletion html/canvas/tools/templates/reftest_worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<html class="reftest-wait">
<link rel="match" href="{{ reference_file }}">
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% if timeout %}<meta name="timeout" content="{{ timeout }}">
Expand Down
2 changes: 1 addition & 1 deletion html/canvas/tools/templates/reftest_worker_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta charset="UTF-8">
<html class="reftest-wait">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<link rel="match" href="{{ reference_file }}">
<link rel="match" href="{{ reference_file_link }}">
{% if fuzzy %}<meta name=fuzzy content="{{ fuzzy }}">
{% endif %}
{% if timeout %}<meta name="timeout" content="{{ timeout }}">
Expand Down

0 comments on commit 463424c

Please sign in to comment.