Skip to content

Commit

Permalink
[Canvas] Move some manual tests in text to generated tests
Browse files Browse the repository at this point in the history
In the auto generated canvas text folders, some tests there were written manually. It's hard for future maintenance. This cl adds them to the generation template.

Bug: 1275750

Change-Id: I0874195ace06f44af9752d19f73934cc0a02bdc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4727016
Reviewed-by: Jean-Philippe Gravel <[email protected]>
Commit-Queue: Yi Xu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1186679}
  • Loading branch information
Yi Xu authored and pull[bot] committed Aug 30, 2023
1 parent f52d1cd commit 895ed1d
Show file tree
Hide file tree
Showing 30 changed files with 575 additions and 472 deletions.
21 changes: 12 additions & 9 deletions html/canvas/element/text/2d.text.fontVariantCaps1-expected.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps1</title>
<h1>2d.text.fontVariantCaps1</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
ctx.fillText("Hello World", 20, 100);
</script>
27 changes: 14 additions & 13 deletions html/canvas/element/text/2d.text.fontVariantCaps1.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.text.fontVariantCaps1-expected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">

<canvas id="c"></canvas>

<title>Canvas test: 2d.text.fontVariantCaps1</title>
<h1>2d.text.fontVariantCaps1</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "32px serif";
ctx.fontVariantCaps = "small-caps";
// This should render the same as font = "small-caps 32px serif".
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "32px serif";
ctx.fontVariantCaps = "small-caps";
// This should render the same as font = "small-caps 32px serif".
ctx.fillText("Hello World", 20, 100);
</script>
12 changes: 0 additions & 12 deletions html/canvas/element/text/2d.text.fontVariantCaps2-unexpected.html

This file was deleted.

38 changes: 27 additions & 11 deletions html/canvas/element/text/2d.text.fontVariantCaps2.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<link rel="mismatch" href="2d.text.fontVariantCaps2-unexpected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps2</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<canvas id="c"></canvas>
<h1>2d.text.fontVariantCaps2</h1>
<p class="desc">Testing small caps setting in fontVariant</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>

<ul id="d"></ul>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
// "mismatch" test, to verify that small-caps does change the rendering.
ctx.fillText("Hello World", 20, 100);
var t = async_test("Testing small caps setting in fontVariant");
_addTest(function(canvas, ctx) {

ctx.font = "small-caps 32px serif";
// "mismatch" test, to verify that small-caps does change the rendering.
smallCaps_len = ctx.measureText("Hello World").width;

ctx.font = "32px serif";
normalCaps_len = ctx.measureText("Hello World").width;
_assert(smallCaps_len != normalCaps_len, "smallCaps_len != normalCaps_len");

});
</script>

21 changes: 12 additions & 9 deletions html/canvas/element/text/2d.text.fontVariantCaps3-expected.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps3</title>
<h1>2d.text.fontVariantCaps3</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
ctx.fillText("hello world", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
ctx.fillText("hello world", 20, 100);
</script>
29 changes: 15 additions & 14 deletions html/canvas/element/text/2d.text.fontVariantCaps3.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.text.fontVariantCaps3-expected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">

<canvas id="c"></canvas>

<title>Canvas test: 2d.text.fontVariantCaps3</title>
<h1>2d.text.fontVariantCaps3</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "32px serif";
ctx.fontVariantCaps = "all-small-caps";
// This should render the same as using font = "small-caps 32px serif"
// with all the underlying text in lowercase.
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "32px serif";
ctx.fontVariantCaps = "all-small-caps";
// This should render the same as using font = "small-caps 32px serif"
// with all the underlying text in lowercase.
ctx.fillText("Hello World", 20, 100);
</script>
21 changes: 12 additions & 9 deletions html/canvas/element/text/2d.text.fontVariantCaps4-expected.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps4</title>
<h1>2d.text.fontVariantCaps4</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
ctx.fillText("hello world", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
ctx.fillText("hello world", 20, 100);
</script>
29 changes: 15 additions & 14 deletions html/canvas/element/text/2d.text.fontVariantCaps4.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.text.fontVariantCaps4-expected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">

<canvas id="c"></canvas>

<title>Canvas test: 2d.text.fontVariantCaps4</title>
<h1>2d.text.fontVariantCaps4</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
// fontVariantCaps overrides the small-caps setting from the font attribute
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "all-small-caps";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
// fontVariantCaps overrides the small-caps setting from the font attribute
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "all-small-caps";
ctx.fillText("Hello World", 20, 100);
</script>
21 changes: 12 additions & 9 deletions html/canvas/element/text/2d.text.fontVariantCaps5-expected.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps5</title>
<h1>2d.text.fontVariantCaps5</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
ctx.fillText("Hello World", 20, 100);
</script>
29 changes: 15 additions & 14 deletions html/canvas/element/text/2d.text.fontVariantCaps5.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.text.fontVariantCaps5-expected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">

<canvas id="c"></canvas>

<title>Canvas test: 2d.text.fontVariantCaps5</title>
<h1>2d.text.fontVariantCaps5</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "small-caps 32px serif";
// fontVariantCaps 'normal' does not override the setting from the font attribute.
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "normal";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
// fontVariantCaps 'normal' does not override the setting from the font attribute.
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "normal";
ctx.fillText("Hello World", 20, 100);
</script>
21 changes: 12 additions & 9 deletions html/canvas/element/text/2d.text.fontVariantCaps6-expected.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps6</title>
<h1>2d.text.fontVariantCaps6</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "32px serif";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "32px serif";
ctx.fillText("Hello World", 20, 100);
</script>
29 changes: 15 additions & 14 deletions html/canvas/element/text/2d.text.fontVariantCaps6.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: the 'fontVariantCaps' property</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps">
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.text.fontVariantCaps6-expected.html">
<meta name="assert" content="text rendering respects the fontVariantCaps property">

<canvas id="c"></canvas>

<title>Canvas test: 2d.text.fontVariantCaps6</title>
<h1>2d.text.fontVariantCaps6</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
let ctx = c.getContext("2d");
// fontVariantCaps is reset when the font attribute is set.
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "all-small-caps";
ctx.font = "32px serif";
ctx.fillText("Hello World", 20, 100);
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

// fontVariantCaps is reset when the font attribute is set.
// (spec unclear, cf. https://github.com/whatwg/html/issues/8103)
ctx.fontVariantCaps = "all-small-caps";
ctx.font = "32px serif";
ctx.fillText("Hello World", 20, 100);
</script>
21 changes: 10 additions & 11 deletions html/canvas/offscreen/text/2d.text.fontVariantCaps1-expected.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML OffscreenCanvas reference</title>
<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">

<canvas id="c1"></canvas>
<br>
<canvas id="c2"></canvas>

<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.fontVariantCaps1</title>
<h1>2d.text.fontVariantCaps1</h1>
<p class="desc">Testing small caps setting in fontVariant</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
for (let c = 1; c <= 2; ++c) {
let ctx = document.getElementById("c" + c).getContext("2d");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.font = "small-caps 32px serif";
ctx.fillText("Hello World", 20, 100);
}
</script>
Loading

0 comments on commit 895ed1d

Please sign in to comment.