Skip to content

Commit

Permalink
Fix flaky tests in canvas and add a new test template
Browse files Browse the repository at this point in the history
Added a new template for promised tests and revert changes made in
https://chromium-review.googlesource.com/c/chromium/src/+/4304361.

Promise tests can be enabled by using test_type = promise. If
test_type is missing, it uses the async test template as default.

All fetch images tests passed now, removed the expected to fail .ini
files.

Bug: 1426642,1428963

Change-Id: I2a8ef9e4c291a4d4ec67cd5ea7a8eea82d84ec4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4421006
Reviewed-by: Jean-Philippe Gravel <[email protected]>
Commit-Queue: Yi Xu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1137619}
  • Loading branch information
Yi Xu authored and chromium-wpt-export-bot committed Apr 30, 2023
1 parent 797e759 commit 71aca13
Show file tree
Hide file tree
Showing 656 changed files with 13,185 additions and 14,687 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ <h1>2d.composite.globalAlpha.canvas</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.drawImage(canvas2, 0, 0);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
// Avoiding any potential alpha = 0 optimisations.
ctx.globalAlpha = 0.01;
ctx.drawImage(canvas2, 0, 0);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ <h1>2d.composite.globalAlpha.canvascopy</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#0f0';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);

ctx.globalCompositeOperation = 'copy'
ctx.globalAlpha = 0.51;
ctx.drawImage(canvas2, 0, 0);
_assertPixelApprox(canvas, 50,25, 0,255,0,130, 2);

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#0f0';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);

ctx.globalCompositeOperation = 'copy'
ctx.globalAlpha = 0.51;
ctx.drawImage(canvas2, 0, 0);
_assertPixelApprox(canvas, 50,25, 0,255,0,130, 2);

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ <h1>2d.composite.globalAlpha.canvaspattern</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = ctx.createPattern(canvas2, 'no-repeat');
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 50;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = ctx.createPattern(canvas2, 'no-repeat');
// Avoiding any potential alpha = 0 optimisations.
ctx.globalAlpha = 0.01;
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ <h1>2d.composite.globalAlpha.default</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

_assertSame(ctx.globalAlpha, 1.0, "ctx.globalAlpha", "1.0");

_assertSame(ctx.globalAlpha, 1.0, "ctx.globalAlpha", "1.0");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ <h1>2d.composite.globalAlpha.fill</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
// Avoiding any potential alpha = 0 optimisations.
ctx.globalAlpha = 0.01;
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ <h1>2d.composite.globalAlpha.image</h1>
<p class="output expectedtext">Expected output:<p><img src="/images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("");
_addTest(function(canvas, ctx) {
promise_test(async t => {

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.drawImage(document.getElementById('red.png'), 0, 0);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
// Avoiding any potential alpha = 0 optimisations.
ctx.globalAlpha = 0.01;
const response = await fetch('/images/red.png');
const blob = await response.blob();
const bitmap = await createImageBitmap(blob);

});
ctx.drawImage(bitmap, 0, 0);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

}, "");
</script>
<img src="/images/red.png" id="red.png" class="resource">

Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ <h1>2d.composite.globalAlpha.imagepattern</h1>
<p class="output expectedtext">Expected output:<p><img src="/images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("");
_addTest(function(canvas, ctx) {
promise_test(async t => {

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = ctx.createPattern(document.getElementById('red.png'), 'no-repeat');
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
const response = await fetch('/images/red.png');
const blob = await response.blob();
const bitmap = await createImageBitmap(blob);

});
ctx.fillStyle = ctx.createPattern(bitmap, 'no-repeat');
// Avoiding any potential alpha = 0 optimisations.
ctx.globalAlpha = 0.01;
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 2,253,0,255, 2);

}, "");
</script>
<img src="/images/red.png" id="red.png" class="resource">

Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ <h1>2d.composite.globalAlpha.invalid</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalAlpha = 0.5;
var a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons
ctx.globalAlpha = Infinity;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = -Infinity;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = NaN;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");

ctx.globalAlpha = 0.5;
// This may not set it to exactly 0.5 if it is rounded/quantised, so
// remember for future comparisons.
var a = ctx.globalAlpha;
ctx.globalAlpha = Infinity;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = -Infinity;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = NaN;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");

});
</script>
Expand Down
24 changes: 13 additions & 11 deletions html/canvas/element/compositing/2d.composite.globalAlpha.range.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ <h1>2d.composite.globalAlpha.range</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalAlpha = 0.5;
var a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons
ctx.globalAlpha = 1.1;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = -0.1;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = 0;
_assertSame(ctx.globalAlpha, 0, "ctx.globalAlpha", "0");
ctx.globalAlpha = 1;
_assertSame(ctx.globalAlpha, 1, "ctx.globalAlpha", "1");

ctx.globalAlpha = 0.5;
// This may not set it to exactly 0.5 if it is rounded/quantised, so
// remember for future comparisons.
var a = ctx.globalAlpha;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = 1.1;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = -0.1;
_assertSame(ctx.globalAlpha, a, "ctx.globalAlpha", "a");
ctx.globalAlpha = 0;
_assertSame(ctx.globalAlpha, 0, "ctx.globalAlpha", "0");
ctx.globalAlpha = 1;
_assertSame(ctx.globalAlpha, 1, "ctx.globalAlpha", "1");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.casesensitive</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'Source-over';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'Source-over';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.clear</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'clear';
_assertSame(ctx.globalCompositeOperation, 'clear', "ctx.globalCompositeOperation", "'clear'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'clear';
_assertSame(ctx.globalCompositeOperation, 'clear', "ctx.globalCompositeOperation", "'clear'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.darker</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'darker';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'darker';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ <h1>2d.composite.operation.default</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

_assertSame(ctx.globalCompositeOperation, 'source-over', "ctx.globalCompositeOperation", "'source-over'");

_assertSame(ctx.globalCompositeOperation, 'source-over', "ctx.globalCompositeOperation", "'source-over'");

});
</script>
Expand Down
17 changes: 8 additions & 9 deletions html/canvas/element/compositing/2d.composite.operation.get.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ <h1>2d.composite.operation.get</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

var modes = ['source-atop', 'source-in', 'source-out', 'source-over',
'destination-atop', 'destination-in', 'destination-out', 'destination-over',
'lighter', 'copy', 'xor'];
for (var i = 0; i < modes.length; ++i)
{
ctx.globalCompositeOperation = modes[i];
_assertSame(ctx.globalCompositeOperation, modes[i], "ctx.globalCompositeOperation", "modes[\""+(i)+"\"]");
}

var modes = ['source-atop', 'source-in', 'source-out', 'source-over',
'destination-atop', 'destination-in', 'destination-out', 'destination-over',
'lighter', 'copy', 'xor'];
for (var i = 0; i < modes.length; ++i)
{
ctx.globalCompositeOperation = modes[i];
_assertSame(ctx.globalCompositeOperation, modes[i], "ctx.globalCompositeOperation", "modes[\""+(i)+"\"]");
}

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.highlight</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'highlight';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'highlight';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.nullsuffix</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'source-over\0';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'source-over\0';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.over</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'over';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'over';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ <h1>2d.composite.operation.unrecognised</h1>
var t = async_test("");
_addTest(function(canvas, ctx) {

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'nonexistent';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'nonexistent';
_assertSame(ctx.globalCompositeOperation, 'xor', "ctx.globalCompositeOperation", "'xor'");

});
</script>
Expand Down
Loading

0 comments on commit 71aca13

Please sign in to comment.