Skip to content

Commit

Permalink
Implement createConicGradient for the new canvas 2d API
Browse files Browse the repository at this point in the history
Currently hidden behind the --new-canvas-2d-api flag.

https://github.com/fserb/canvas2D/blob/master/spec/conic-gradient.md
whatwg/html#5431

Bug: 1097034
Change-Id: I2267539087546b29f0fd04ecef7158e7a61bb97f
  • Loading branch information
mysteryDate authored and chromium-wpt-export-bot committed Jun 26, 2020
1 parent 1156b01 commit 0f2d473
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 4 deletions.
36 changes: 36 additions & 0 deletions html/canvas/element/fill-and-stroke-styles/2d.gradient.conic.html
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.gradient.conic</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">

<h1>2d.gradient.conic</h1>
<p class="desc">Conic gradient function exists</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<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("Conic gradient function exists");
_addTest(function(canvas, ctx) {

const g = ctx.createConicGradient(0, 0, 25);
g.addColorStop(0, "#0f0");
g.addColorStop(0.5, "#0f0");
g.addColorStop(0.51, "#f00");
g.addColorStop(1, "#f00");
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
_assertPixel(canvas, 25,25, 0,255,0,255, "25,25", "0,255,0,255");
_assertPixel(canvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255");
_assertPixel(canvas, 75,25, 0,255,0,255, "75,25", "0,255,0,255");


});
</script>

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.gradient.conic</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.gradient.conic</h1>
<p class="desc">Conic gradient function exists</p>


<script>
var t = async_test("Conic gradient function exists");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

const g = ctx.createConicGradient(0, 0, 25);
g.addColorStop(0, "#0f0");
g.addColorStop(0.5, "#0f0");
g.addColorStop(0.5, "#f00");
g.addColorStop(1, "#f00");
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
_assertPixel(offscreenCanvas, 25,25, 0,255,0,255, "25,25", "0,255,0,255");
_assertPixel(offscreenCanvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255");
_assertPixel(offscreenCanvas, 75,25, 0,255,0,255, "75,25", "0,255,0,255");
t.done();

});
</script>
@@ -0,0 +1,32 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.gradient.conic
// Description:Conic gradient function exists
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("Conic gradient function exists");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

const g = ctx.createConicGradient(0, 0, 25);
g.addColorStop(0, "#0f0");
g.addColorStop(0.5, "#0f0");
g.addColorStop(0.5, "#f00");
g.addColorStop(1, "#f00");
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
_assertPixel(offscreenCanvas, 25,25, 0,255,0,255, "25,25", "0,255,0,255");
_assertPixel(offscreenCanvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255");
_assertPixel(offscreenCanvas, 75,25, 0,255,0,255, "75,25", "0,255,0,255");
t.done();

});
done();
18 changes: 14 additions & 4 deletions html/canvas/tools/yaml/element/fill-and-stroke-styles.yaml
Expand Up @@ -1174,10 +1174,20 @@
@assert pixel 75,25 == 0,255,0,255;
expected: green





- name: 2d.gradient.conic
desc: Conic gradient function exists
code: |
const g = ctx.createConicGradient(0, 0, 25);
g.addColorStop(0, "#0f0");
g.addColorStop(0.5, "#0f0");
g.addColorStop(0.51, "#f00");
g.addColorStop(1, "#f00");
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
@assert pixel 25,25 == 0,255,0,255;
@assert pixel 50,25 == 0,255,0,255;
@assert pixel 75,25 == 0,255,0,255;
expected: green

- name: 2d.pattern.basic.type
testing:
Expand Down
16 changes: 16 additions & 0 deletions html/canvas/tools/yaml/offscreen/fill-and-stroke-styles.yaml
Expand Up @@ -928,6 +928,22 @@
@assert pixel 75,25 == 0,255,0,255;
t.done();
- name: 2d.gradient.conic
desc: Conic gradient function exists
code: |
const g = ctx.createConicGradient(0, 0, 25);
g.addColorStop(0, "#0f0");
g.addColorStop(0.5, "#0f0");
g.addColorStop(0.5, "#f00");
g.addColorStop(1, "#f00");
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
@assert pixel 25,25 == 0,255,0,255;
@assert pixel 50,25 == 0,255,0,255;
@assert pixel 75,25 == 0,255,0,255;
t.done();
expected: green

- name: 2d.pattern.basic.image
testing:
- 2d.pattern.painting
Expand Down

0 comments on commit 0f2d473

Please sign in to comment.