commit 0618899bd2ddb8ec88a1de595f3d941e093c68c9 parent cf6966d1d2bf1b56fc41029cd8b1349490ec5a54 Author: Fredrik Söderquist <fs@opera.com> Date: Wed, 3 Dec 2025 14:41:13 +0000 Bug 2003304 [wpt PR 56369] - Fix CanvasRenderingContext2D.restore() on zero-size canvas, a=testonly Automatic update from web-platform-tests Fix CanvasRenderingContext2D.restore() on zero-size canvas Canvas2DRecorderContext::restore() would return without restoring the state stack if there was no PaintCanvas. Hoist the operations on the PaintCanvas out of PopAndRestore() into the respective callers and drop the PaintCanvas argument. Rename to PopStateStack(). Fixed: 463867637 Change-Id: I8376c9c1622710cb942b17df9357c36effb7bfba Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7205876 Auto-Submit: Fredrik Söderquist <fs@opera.com> Reviewed-by: Jean-Philippe Gravel <jpgravel@chromium.org> Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org> Cr-Commit-Position: refs/heads/main@{#1552155} -- wpt-commits: ac34fea8c013645f339be164c2451ef9434f469d wpt-pr: 56369 Diffstat:
40 files changed, 1060 insertions(+), 433 deletions(-)
diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.fillStyle.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.fillStyle.html @@ -6,19 +6,39 @@ <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.state.saverestore.fillStyle</h1> -<p class="desc">save()/restore() works for fillStyle</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for fillStyle"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.fillStyle; + ctx.save(); + ctx.fillStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.fillStyle = "#ff0000"; + old = ctx.fillStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + ctx.restore(); +}, "save()/restore() works for fillStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.fillStyle; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); ctx.restore(); +}, "save()/restore() works for fillStyle, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.font.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.font.html @@ -6,19 +6,39 @@ <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.state.saverestore.font</h1> -<p class="desc">save()/restore() works for font</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for font"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.font; + ctx.save(); + ctx.font = "25px serif"; + ctx.restore(); + _assertSame(ctx.font, old, "ctx.font", "old"); + + // Also test that save() doesn't modify the values + ctx.font = "25px serif"; + old = ctx.font; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "25px serif" + ctx.save(); + _assertSame(ctx.font, old, "ctx.font", "old"); + ctx.restore(); +}, "save()/restore() works for font, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.font; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.font, old, "ctx.font", "old"); ctx.restore(); +}, "save()/restore() works for font, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.globalAlpha.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.globalAlpha.html @@ -6,19 +6,39 @@ <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.state.saverestore.globalAlpha</h1> -<p class="desc">save()/restore() works for globalAlpha</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for globalAlpha"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.globalAlpha; + ctx.save(); + ctx.globalAlpha = 0.5; + ctx.restore(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + + // Also test that save() doesn't modify the values + ctx.globalAlpha = 0.5; + old = ctx.globalAlpha; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + ctx.restore(); +}, "save()/restore() works for globalAlpha, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalAlpha; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); ctx.restore(); +}, "save()/restore() works for globalAlpha, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html @@ -6,19 +6,39 @@ <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.state.saverestore.globalCompositeOperation</h1> -<p class="desc">save()/restore() works for globalCompositeOperation</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for globalCompositeOperation"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.globalCompositeOperation; + ctx.save(); + ctx.globalCompositeOperation = "copy"; + ctx.restore(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + + // Also test that save() doesn't modify the values + ctx.globalCompositeOperation = "copy"; + old = ctx.globalCompositeOperation; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "copy" + ctx.save(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + ctx.restore(); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalCompositeOperation; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); ctx.restore(); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineCap.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineCap.html @@ -6,19 +6,39 @@ <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.state.saverestore.lineCap</h1> -<p class="desc">save()/restore() works for lineCap</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for lineCap"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.lineCap; + ctx.save(); + ctx.lineCap = "round"; + ctx.restore(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + + // Also test that save() doesn't modify the values + ctx.lineCap = "round"; + old = ctx.lineCap; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + ctx.restore(); +}, "save()/restore() works for lineCap, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineCap; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); ctx.restore(); +}, "save()/restore() works for lineCap, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineJoin.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineJoin.html @@ -6,19 +6,39 @@ <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.state.saverestore.lineJoin</h1> -<p class="desc">save()/restore() works for lineJoin</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for lineJoin"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.lineJoin; + ctx.save(); + ctx.lineJoin = "round"; + ctx.restore(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + + // Also test that save() doesn't modify the values + ctx.lineJoin = "round"; + old = ctx.lineJoin; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + ctx.restore(); +}, "save()/restore() works for lineJoin, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineJoin; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); ctx.restore(); +}, "save()/restore() works for lineJoin, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineWidth.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.lineWidth.html @@ -6,19 +6,39 @@ <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.state.saverestore.lineWidth</h1> -<p class="desc">save()/restore() works for lineWidth</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for lineWidth"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.lineWidth; + ctx.save(); + ctx.lineWidth = 0.5; + ctx.restore(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + + // Also test that save() doesn't modify the values + ctx.lineWidth = 0.5; + old = ctx.lineWidth; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + ctx.restore(); +}, "save()/restore() works for lineWidth, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineWidth; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); ctx.restore(); +}, "save()/restore() works for lineWidth, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.miterLimit.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.miterLimit.html @@ -6,19 +6,39 @@ <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.state.saverestore.miterLimit</h1> -<p class="desc">save()/restore() works for miterLimit</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for miterLimit"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.miterLimit; + ctx.save(); + ctx.miterLimit = 0.5; + ctx.restore(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + + // Also test that save() doesn't modify the values + ctx.miterLimit = 0.5; + old = ctx.miterLimit; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + ctx.restore(); +}, "save()/restore() works for miterLimit, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.miterLimit; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); ctx.restore(); +}, "save()/restore() works for miterLimit, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowBlur.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowBlur.html @@ -6,19 +6,39 @@ <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.state.saverestore.shadowBlur</h1> -<p class="desc">save()/restore() works for shadowBlur</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for shadowBlur"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.shadowBlur; + ctx.save(); + ctx.shadowBlur = 5; + ctx.restore(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowBlur = 5; + old = ctx.shadowBlur; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + ctx.restore(); +}, "save()/restore() works for shadowBlur, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowBlur; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); ctx.restore(); +}, "save()/restore() works for shadowBlur, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowColor.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowColor.html @@ -6,19 +6,39 @@ <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.state.saverestore.shadowColor</h1> -<p class="desc">save()/restore() works for shadowColor</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for shadowColor"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.shadowColor; + ctx.save(); + ctx.shadowColor = "#ff0000"; + ctx.restore(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowColor = "#ff0000"; + old = ctx.shadowColor; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + ctx.restore(); +}, "save()/restore() works for shadowColor, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowColor; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); ctx.restore(); +}, "save()/restore() works for shadowColor, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowOffsetX.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowOffsetX.html @@ -6,19 +6,39 @@ <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.state.saverestore.shadowOffsetX</h1> -<p class="desc">save()/restore() works for shadowOffsetX</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for shadowOffsetX"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetX; + ctx.save(); + ctx.shadowOffsetX = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetX = 5; + old = ctx.shadowOffsetX; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetX; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); ctx.restore(); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowOffsetY.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.shadowOffsetY.html @@ -6,19 +6,39 @@ <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.state.saverestore.shadowOffsetY</h1> -<p class="desc">save()/restore() works for shadowOffsetY</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for shadowOffsetY"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetY; + ctx.save(); + ctx.shadowOffsetY = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetY = 5; + old = ctx.shadowOffsetY; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetY; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); ctx.restore(); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.strokeStyle.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.strokeStyle.html @@ -6,19 +6,39 @@ <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.state.saverestore.strokeStyle</h1> -<p class="desc">save()/restore() works for strokeStyle</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for strokeStyle"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.strokeStyle; + ctx.save(); + ctx.strokeStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.strokeStyle = "#ff0000"; + old = ctx.strokeStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + ctx.restore(); +}, "save()/restore() works for strokeStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.strokeStyle; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); ctx.restore(); +}, "save()/restore() works for strokeStyle, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.textAlign.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.textAlign.html @@ -6,19 +6,39 @@ <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.state.saverestore.textAlign</h1> -<p class="desc">save()/restore() works for textAlign</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for textAlign"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.textAlign; + ctx.save(); + ctx.textAlign = "center"; + ctx.restore(); + _assertSame(ctx.textAlign, old, "ctx.textAlign", "old"); + + // Also test that save() doesn't modify the values + ctx.textAlign = "center"; + old = ctx.textAlign; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "center" + ctx.save(); + _assertSame(ctx.textAlign, old, "ctx.textAlign", "old"); + ctx.restore(); +}, "save()/restore() works for textAlign, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.textAlign; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.textAlign, old, "ctx.textAlign", "old"); ctx.restore(); +}, "save()/restore() works for textAlign, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.textBaseline.html b/testing/web-platform/tests/html/canvas/element/the-canvas-state/2d.state.saverestore.textBaseline.html @@ -6,19 +6,39 @@ <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.state.saverestore.textBaseline</h1> -<p class="desc">save()/restore() works for textBaseline</p> +<script> -<p class="output">Actual output:</p> -<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 300; + canvas.height = 150; + const ctx = canvas.getContext('2d'); -<ul id="d"></ul> -<script> -var t = async_test("save()/restore() works for textBaseline"); -_addTest(function(canvas, ctx) { + // Test that restore() undoes any modifications + var old = ctx.textBaseline; + ctx.save(); + ctx.textBaseline = "bottom"; + ctx.restore(); + _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); + + // Also test that save() doesn't modify the values + ctx.textBaseline = "bottom"; + old = ctx.textBaseline; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "bottom" + ctx.save(); + _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); + ctx.restore(); +}, "save()/restore() works for textBaseline, with a canvas size of (300, 150)"); + +test(t => { + const canvas = document.createElement('canvas'); + canvas.width = 0; + canvas.height = 0; + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.textBaseline; @@ -35,7 +55,6 @@ _addTest(function(canvas, ctx) { ctx.save(); _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); ctx.restore(); +}, "save()/restore() works for textBaseline, with a canvas size of (0, 0)"); -}); </script> - diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.fillStyle.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.fillStyle.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.fillStyle</h1> -<p class="desc">save()/restore() works for fillStyle</p> - <script> -var t = async_test("save()/restore() works for fillStyle"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.fillStyle; + ctx.save(); + ctx.fillStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.fillStyle = "#ff0000"; + old = ctx.fillStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + ctx.restore(); +}, "save()/restore() works for fillStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.fillStyle; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for fillStyle, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.fillStyle.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.fillStyle.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.fillStyle -// Description:save()/restore() works for fillStyle +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for fillStyle"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.fillStyle; + ctx.save(); + ctx.fillStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.fillStyle = "#ff0000"; + old = ctx.fillStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); + ctx.restore(); +}, "save()/restore() works for fillStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.fillStyle; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.fillStyle, old, "ctx.fillStyle", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for fillStyle, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalAlpha.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalAlpha.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.globalAlpha</h1> -<p class="desc">save()/restore() works for globalAlpha</p> - <script> -var t = async_test("save()/restore() works for globalAlpha"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.globalAlpha; + ctx.save(); + ctx.globalAlpha = 0.5; + ctx.restore(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + + // Also test that save() doesn't modify the values + ctx.globalAlpha = 0.5; + old = ctx.globalAlpha; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + ctx.restore(); +}, "save()/restore() works for globalAlpha, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalAlpha; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for globalAlpha, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalAlpha.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalAlpha.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.globalAlpha -// Description:save()/restore() works for globalAlpha +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for globalAlpha"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.globalAlpha; + ctx.save(); + ctx.globalAlpha = 0.5; + ctx.restore(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + + // Also test that save() doesn't modify the values + ctx.globalAlpha = 0.5; + old = ctx.globalAlpha; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); + ctx.restore(); +}, "save()/restore() works for globalAlpha, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalAlpha; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.globalAlpha, old, "ctx.globalAlpha", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for globalAlpha, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.globalCompositeOperation</h1> -<p class="desc">save()/restore() works for globalCompositeOperation</p> - <script> -var t = async_test("save()/restore() works for globalCompositeOperation"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.globalCompositeOperation; + ctx.save(); + ctx.globalCompositeOperation = "copy"; + ctx.restore(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + + // Also test that save() doesn't modify the values + ctx.globalCompositeOperation = "copy"; + old = ctx.globalCompositeOperation; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "copy" + ctx.save(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + ctx.restore(); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalCompositeOperation; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalCompositeOperation.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.globalCompositeOperation.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.globalCompositeOperation -// Description:save()/restore() works for globalCompositeOperation +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for globalCompositeOperation"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.globalCompositeOperation; + ctx.save(); + ctx.globalCompositeOperation = "copy"; + ctx.restore(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + + // Also test that save() doesn't modify the values + ctx.globalCompositeOperation = "copy"; + old = ctx.globalCompositeOperation; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "copy" + ctx.save(); + _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); + ctx.restore(); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.globalCompositeOperation; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.globalCompositeOperation, old, "ctx.globalCompositeOperation", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for globalCompositeOperation, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineCap.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineCap.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.lineCap</h1> -<p class="desc">save()/restore() works for lineCap</p> - <script> -var t = async_test("save()/restore() works for lineCap"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.lineCap; + ctx.save(); + ctx.lineCap = "round"; + ctx.restore(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + + // Also test that save() doesn't modify the values + ctx.lineCap = "round"; + old = ctx.lineCap; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + ctx.restore(); +}, "save()/restore() works for lineCap, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineCap; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for lineCap, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineCap.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineCap.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.lineCap -// Description:save()/restore() works for lineCap +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for lineCap"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.lineCap; + ctx.save(); + ctx.lineCap = "round"; + ctx.restore(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + + // Also test that save() doesn't modify the values + ctx.lineCap = "round"; + old = ctx.lineCap; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); + ctx.restore(); +}, "save()/restore() works for lineCap, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineCap; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineCap, old, "ctx.lineCap", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for lineCap, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineJoin.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineJoin.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.lineJoin</h1> -<p class="desc">save()/restore() works for lineJoin</p> - <script> -var t = async_test("save()/restore() works for lineJoin"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.lineJoin; + ctx.save(); + ctx.lineJoin = "round"; + ctx.restore(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + + // Also test that save() doesn't modify the values + ctx.lineJoin = "round"; + old = ctx.lineJoin; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + ctx.restore(); +}, "save()/restore() works for lineJoin, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineJoin; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for lineJoin, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineJoin.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineJoin.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.lineJoin -// Description:save()/restore() works for lineJoin +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for lineJoin"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.lineJoin; + ctx.save(); + ctx.lineJoin = "round"; + ctx.restore(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + + // Also test that save() doesn't modify the values + ctx.lineJoin = "round"; + old = ctx.lineJoin; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); + ctx.restore(); +}, "save()/restore() works for lineJoin, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineJoin; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineJoin, old, "ctx.lineJoin", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for lineJoin, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineWidth.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineWidth.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.lineWidth</h1> -<p class="desc">save()/restore() works for lineWidth</p> - <script> -var t = async_test("save()/restore() works for lineWidth"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.lineWidth; + ctx.save(); + ctx.lineWidth = 0.5; + ctx.restore(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + + // Also test that save() doesn't modify the values + ctx.lineWidth = 0.5; + old = ctx.lineWidth; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + ctx.restore(); +}, "save()/restore() works for lineWidth, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineWidth; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for lineWidth, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineWidth.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.lineWidth.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.lineWidth -// Description:save()/restore() works for lineWidth +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for lineWidth"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.lineWidth; + ctx.save(); + ctx.lineWidth = 0.5; + ctx.restore(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + + // Also test that save() doesn't modify the values + ctx.lineWidth = 0.5; + old = ctx.lineWidth; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); + ctx.restore(); +}, "save()/restore() works for lineWidth, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.lineWidth; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.lineWidth, old, "ctx.lineWidth", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for lineWidth, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.miterLimit.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.miterLimit.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.miterLimit</h1> -<p class="desc">save()/restore() works for miterLimit</p> - <script> -var t = async_test("save()/restore() works for miterLimit"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.miterLimit; + ctx.save(); + ctx.miterLimit = 0.5; + ctx.restore(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + + // Also test that save() doesn't modify the values + ctx.miterLimit = 0.5; + old = ctx.miterLimit; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + ctx.restore(); +}, "save()/restore() works for miterLimit, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.miterLimit; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for miterLimit, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.miterLimit.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.miterLimit.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.miterLimit -// Description:save()/restore() works for miterLimit +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for miterLimit"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.miterLimit; + ctx.save(); + ctx.miterLimit = 0.5; + ctx.restore(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + + // Also test that save() doesn't modify the values + ctx.miterLimit = 0.5; + old = ctx.miterLimit; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); + ctx.restore(); +}, "save()/restore() works for miterLimit, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.miterLimit; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.miterLimit, old, "ctx.miterLimit", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for miterLimit, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowBlur.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowBlur.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.shadowBlur</h1> -<p class="desc">save()/restore() works for shadowBlur</p> - <script> -var t = async_test("save()/restore() works for shadowBlur"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.shadowBlur; + ctx.save(); + ctx.shadowBlur = 5; + ctx.restore(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowBlur = 5; + old = ctx.shadowBlur; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + ctx.restore(); +}, "save()/restore() works for shadowBlur, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowBlur; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for shadowBlur, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowBlur.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowBlur.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.shadowBlur -// Description:save()/restore() works for shadowBlur +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for shadowBlur"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.shadowBlur; + ctx.save(); + ctx.shadowBlur = 5; + ctx.restore(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowBlur = 5; + old = ctx.shadowBlur; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); + ctx.restore(); +}, "save()/restore() works for shadowBlur, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowBlur; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowBlur, old, "ctx.shadowBlur", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for shadowBlur, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowColor.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowColor.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.shadowColor</h1> -<p class="desc">save()/restore() works for shadowColor</p> - <script> -var t = async_test("save()/restore() works for shadowColor"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.shadowColor; + ctx.save(); + ctx.shadowColor = "#ff0000"; + ctx.restore(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowColor = "#ff0000"; + old = ctx.shadowColor; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + ctx.restore(); +}, "save()/restore() works for shadowColor, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowColor; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for shadowColor, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowColor.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowColor.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.shadowColor -// Description:save()/restore() works for shadowColor +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for shadowColor"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.shadowColor; + ctx.save(); + ctx.shadowColor = "#ff0000"; + ctx.restore(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowColor = "#ff0000"; + old = ctx.shadowColor; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); + ctx.restore(); +}, "save()/restore() works for shadowColor, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowColor; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowColor, old, "ctx.shadowColor", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for shadowColor, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetX.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetX.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.shadowOffsetX</h1> -<p class="desc">save()/restore() works for shadowOffsetX</p> - <script> -var t = async_test("save()/restore() works for shadowOffsetX"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetX; + ctx.save(); + ctx.shadowOffsetX = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetX = 5; + old = ctx.shadowOffsetX; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetX; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetX.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetX.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.shadowOffsetX -// Description:save()/restore() works for shadowOffsetX +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for shadowOffsetX"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetX; + ctx.save(); + ctx.shadowOffsetX = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetX = 5; + old = ctx.shadowOffsetX; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetX; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowOffsetX, old, "ctx.shadowOffsetX", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for shadowOffsetX, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetY.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetY.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.shadowOffsetY</h1> -<p class="desc">save()/restore() works for shadowOffsetY</p> - <script> -var t = async_test("save()/restore() works for shadowOffsetY"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetY; + ctx.save(); + ctx.shadowOffsetY = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetY = 5; + old = ctx.shadowOffsetY; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetY; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetY.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.shadowOffsetY.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.shadowOffsetY -// Description:save()/restore() works for shadowOffsetY +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for shadowOffsetY"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetY; + ctx.save(); + ctx.shadowOffsetY = 5; + ctx.restore(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetY = 5; + old = ctx.shadowOffsetY; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); + ctx.restore(); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.shadowOffsetY; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.shadowOffsetY, old, "ctx.shadowOffsetY", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for shadowOffsetY, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.strokeStyle.html b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.strokeStyle.html @@ -7,19 +7,33 @@ <script src="/html/canvas/resources/canvas-tests.js"></script> <h1>2d.state.saverestore.strokeStyle</h1> -<p class="desc">save()/restore() works for strokeStyle</p> - <script> -var t = async_test("save()/restore() works for strokeStyle"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); + + // Test that restore() undoes any modifications + var old = ctx.strokeStyle; + ctx.save(); + ctx.strokeStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.strokeStyle = "#ff0000"; + old = ctx.strokeStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + ctx.restore(); +}, "save()/restore() works for strokeStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.strokeStyle; @@ -36,7 +50,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); ctx.restore(); - t.done(); +}, "save()/restore() works for strokeStyle, with a canvas size of (0, 0)"); -}); </script> diff --git a/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.strokeStyle.worker.js b/testing/web-platform/tests/html/canvas/offscreen/the-canvas-state/2d.state.saverestore.strokeStyle.worker.js @@ -1,20 +1,35 @@ // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.state.saverestore.strokeStyle -// Description:save()/restore() works for strokeStyle +// Description: // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); -var t = async_test("save()/restore() works for strokeStyle"); -var t_pass = t.done.bind(t); -var t_fail = t.step_func(function(reason) { - throw reason; -}); -t.step(function() { +test(t => { + const canvas = new OffscreenCanvas(300, 150); + const ctx = canvas.getContext('2d'); - var canvas = new OffscreenCanvas(100, 50); - var ctx = canvas.getContext('2d'); + // Test that restore() undoes any modifications + var old = ctx.strokeStyle; + ctx.save(); + ctx.strokeStyle = "#ff0000"; + ctx.restore(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + + // Also test that save() doesn't modify the values + ctx.strokeStyle = "#ff0000"; + old = ctx.strokeStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); + ctx.restore(); +}, "save()/restore() works for strokeStyle, with a canvas size of (300, 150)"); + +test(t => { + const canvas = new OffscreenCanvas(0, 0); + const ctx = canvas.getContext('2d'); // Test that restore() undoes any modifications var old = ctx.strokeStyle; @@ -31,6 +46,6 @@ t.step(function() { ctx.save(); _assertSame(ctx.strokeStyle, old, "ctx.strokeStyle", "old"); ctx.restore(); - t.done(); -}); +}, "save()/restore() works for strokeStyle, with a canvas size of (0, 0)"); + done(); diff --git a/testing/web-platform/tests/html/canvas/tools/yaml/the-canvas-state.yaml b/testing/web-platform/tests/html/canvas/tools/yaml/the-canvas-state.yaml @@ -104,24 +104,30 @@ @assert ctx.lineWidth === 0.5; - name: 2d.state.saverestore - desc: save()/restore() works for {{ variant_names[0] }} + desc: save()/restore() works for {{ variant_names[1] }}, with a canvas size of + {{ size }} code: | // Test that restore() undoes any modifications - var old = ctx.{{ variant_names[0] }}; + var old = ctx.{{ variant_names[1] }}; ctx.save(); - ctx.{{ variant_names[0] }} = {{ value }}; + ctx.{{ variant_names[1] }} = {{ value }}; ctx.restore(); - _assertSame(ctx.{{ variant_names[0] }}, old, "ctx.{{ variant_names[0] }}", "old"); + _assertSame(ctx.{{ variant_names[1] }}, old, "ctx.{{ variant_names[1] }}", "old"); // Also test that save() doesn't modify the values - ctx.{{ variant_names[0] }} = {{ value }}; - old = ctx.{{ variant_names[0] }}; + ctx.{{ variant_names[1] }} = {{ value }}; + old = ctx.{{ variant_names[1] }}; // we're not interested in failures caused by get(set(x)) != x (e.g. // from rounding), so compare against 'old' instead of against {{ value }} ctx.save(); - _assertSame(ctx.{{ variant_names[0] }}, old, "ctx.{{ variant_names[0] }}", "old"); + _assertSame(ctx.{{ variant_names[1] }}, old, "ctx.{{ variant_names[1] }}", "old"); ctx.restore(); + variants_layout: [single_file, multi_files] variants: + - non-zero-size: + size: [300, 150] + zero-size: + size: [0, 0] - &2d_state_test_cases strokeStyle: value: '"#ff0000"'