0

Consolidate reference_file and is_test_reference into a single param

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 <andresrperez@chromium.org>
Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1423298}
This commit is contained in:
Jean-Philippe Gravel
2025-02-21 11:59:52 -08:00
committed by Chromium LUCI CQ
parent cdc39d3567
commit cc2d59ed82
7 changed files with 17 additions and 16 deletions

@@ -860,16 +860,17 @@ class _VariantGrid:
else f'{output_files.offscreen}-expected.html'),
}
for canvas_type, params in self._canvas_type_params.items():
params['reference_file'] = pathlib.Path(
# Generate reference file.
if canvas_type != _CanvasType.WORKER or needs_worker_reference:
_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])
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])
def _write_testharness_test(self, jinja_env: jinja2.Environment,
output_files: _OutputPaths):
grid = '_grid' if len(self.variants) > 1 else ''

@@ -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 %}
@@ -21,7 +21,7 @@
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");

@@ -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 %}
@@ -41,7 +41,7 @@
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) {

@@ -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 }}">

@@ -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 }}">

@@ -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 }}">

@@ -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 }}">