diff options
Diffstat (limited to 'testing/web-platform/tests/2dcontext/the-canvas-state')
26 files changed, 955 insertions, 0 deletions
diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/.gitkeep b/testing/web-platform/tests/2dcontext/the-canvas-state/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/.gitkeep diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.bitmap.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.bitmap.html new file mode 100644 index 000000000..d22720c09 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.bitmap.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.bitmap</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.bitmap</h1> +<p class="desc">save()/restore() does not affect the current bitmap</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("save()/restore() does not affect the current bitmap"); +_addTest(function(canvas, ctx) { + +ctx.fillStyle = '#f00'; +ctx.fillRect(0, 0, 100, 50); +ctx.save(); +ctx.fillStyle = '#0f0'; +ctx.fillRect(0, 0, 100, 50); +ctx.restore(); +_assertPixel(canvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.clip.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.clip.html new file mode 100644 index 000000000..5f4d1ad35 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.clip.html @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.clip</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.clip</h1> +<p class="desc">save()/restore() affects the clipping path</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("save()/restore() affects the clipping path"); +_addTest(function(canvas, ctx) { + +ctx.fillStyle = '#f00'; +ctx.fillRect(0, 0, 100, 50); +ctx.save(); +ctx.rect(0, 0, 1, 1); +ctx.clip(); +ctx.restore(); +ctx.fillStyle = '#0f0'; +ctx.fillRect(0, 0, 100, 50); +_assertPixel(canvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.fillStyle.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.fillStyle.html new file mode 100644 index 000000000..a44f4f96a --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.fillStyle.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.fillStyle</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.fillStyle</h1> +<p class="desc">save()/restore() works for fillStyle</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.font.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.font.html new file mode 100644 index 000000000..287400646 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.font.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.font</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.font</h1> +<p class="desc">save()/restore() works for font</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalAlpha.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalAlpha.html new file mode 100644 index 000000000..27fc1aed8 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalAlpha.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.globalAlpha</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.globalAlpha</h1> +<p class="desc">save()/restore() works for globalAlpha</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html new file mode 100644 index 000000000..419a96052 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.globalCompositeOperation.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.globalCompositeOperation</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.globalCompositeOperation</h1> +<p class="desc">save()/restore() works for globalCompositeOperation</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.imageSmoothingEnabled.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.imageSmoothingEnabled.html new file mode 100644 index 000000000..e99be83d5 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.imageSmoothingEnabled.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>CanvasRenderingContext2D imageSmoothingEnabled save/restore test</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing"> +<script> +function createTestImage() { + var image = document.createElement('canvas'); + var imgctx = image.getContext('2d'); + imgctx.fillStyle = "#F00"; + imgctx.fillRect(0, 0, 2, 2); + imgctx.fillStyle = "#0F0"; + imgctx.fillRect(0, 0, 1, 1); + return image; +} + +test(function() { + var ctx = document.createElement('canvas').getContext('2d'); + ctx.save(); + ctx.imageSmoothingEnabled = false; + ctx.restore(); + assert_equals(ctx.imageSmoothingEnabled, true); +}, "Test that restore() undoes any modifications to imageSmoothingEnabled."); + +test(function() { + var ctx = document.createElement('canvas').getContext('2d'); + ctx.imageSmoothingEnabled = false; + var old = ctx.imageSmoothingEnabled; + ctx.save(); + assert_equals(ctx.imageSmoothingEnabled, old); + ctx.restore(); +}, "Test that save() doesn't modify the values of imageSmoothingEnabled."); + +test(function() { + var ctx = document.createElement('canvas').getContext('2d'); + ctx.imageSmoothingEnabled = false; + ctx.save(); + ctx.imageSmoothingEnabled = true; + ctx.restore(); + var image = createTestImage(); + ctx.scale(10, 10); + ctx.drawImage(image, 0, 0); + var pixels = ctx.getImageData(0, 0, 1, 1).data; + assert_array_equals(pixels, [0, 255, 0, 255]); +}, "Test that restoring actually changes smoothing and not just the attribute value."); +</script> diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineCap.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineCap.html new file mode 100644 index 000000000..cb750219f --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineCap.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.lineCap</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.lineCap</h1> +<p class="desc">save()/restore() works for lineCap</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineJoin.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineJoin.html new file mode 100644 index 000000000..ff1411265 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineJoin.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.lineJoin</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.lineJoin</h1> +<p class="desc">save()/restore() works for lineJoin</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineWidth.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineWidth.html new file mode 100644 index 000000000..21bb26673 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.lineWidth.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.lineWidth</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.lineWidth</h1> +<p class="desc">save()/restore() works for lineWidth</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.miterLimit.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.miterLimit.html new file mode 100644 index 000000000..f49edced1 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.miterLimit.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.miterLimit</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.miterLimit</h1> +<p class="desc">save()/restore() works for miterLimit</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.path.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.path.html new file mode 100644 index 000000000..b6f269c32 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.path.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.path</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.path</h1> +<p class="desc">save()/restore() does not affect the current path</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("save()/restore() does not affect the current path"); +_addTest(function(canvas, ctx) { + +ctx.fillStyle = '#f00'; +ctx.fillRect(0, 0, 100, 50); +ctx.save(); +ctx.rect(0, 0, 100, 50); +ctx.restore(); +ctx.fillStyle = '#0f0'; +ctx.fill(); +_assertPixel(canvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowBlur.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowBlur.html new file mode 100644 index 000000000..7f1ce6f9b --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowBlur.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.shadowBlur</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.shadowBlur</h1> +<p class="desc">save()/restore() works for shadowBlur</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowColor.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowColor.html new file mode 100644 index 000000000..95c36dfad --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowColor.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.shadowColor</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.shadowColor</h1> +<p class="desc">save()/restore() works for shadowColor</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetX.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetX.html new file mode 100644 index 000000000..363d5cc24 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetX.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.shadowOffsetX</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.shadowOffsetX</h1> +<p class="desc">save()/restore() works for shadowOffsetX</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetY.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetY.html new file mode 100644 index 000000000..5edb62a7a --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.shadowOffsetY.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.shadowOffsetY</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.shadowOffsetY</h1> +<p class="desc">save()/restore() works for shadowOffsetY</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stack.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stack.html new file mode 100644 index 000000000..3a5dbea10 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stack.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.stack</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.stack</h1> +<p class="desc">save()/restore() can be nested as a stack</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +var t = async_test("save()/restore() can be nested as a stack"); +_addTest(function(canvas, ctx) { + +ctx.lineWidth = 1; +ctx.save(); +ctx.lineWidth = 2; +ctx.save(); +ctx.lineWidth = 3; +_assertSame(ctx.lineWidth, 3, "ctx.lineWidth", "3"); +ctx.restore(); +_assertSame(ctx.lineWidth, 2, "ctx.lineWidth", "2"); +ctx.restore(); +_assertSame(ctx.lineWidth, 1, "ctx.lineWidth", "1"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stackdepth.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stackdepth.html new file mode 100644 index 000000000..5e6c459f3 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.stackdepth.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.stackdepth</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.stackdepth</h1> +<p class="desc">save()/restore() stack depth is not unreasonably limited</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +var t = async_test("save()/restore() stack depth is not unreasonably limited"); +_addTest(function(canvas, ctx) { + +var limit = 512; +for (var i = 1; i < limit; ++i) +{ + ctx.save(); + ctx.lineWidth = i; +} +for (var i = limit-1; i > 0; --i) +{ + _assertSame(ctx.lineWidth, i, "ctx.lineWidth", "i"); + ctx.restore(); +} + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.strokeStyle.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.strokeStyle.html new file mode 100644 index 000000000..53a28f555 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.strokeStyle.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.strokeStyle</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.strokeStyle</h1> +<p class="desc">save()/restore() works for strokeStyle</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textAlign.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textAlign.html new file mode 100644 index 000000000..ea1b3f2e2 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textAlign.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.textAlign</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.textAlign</h1> +<p class="desc">save()/restore() works for textAlign</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textBaseline.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textBaseline.html new file mode 100644 index 000000000..22664ef1d --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.textBaseline.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.textBaseline</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.textBaseline</h1> +<p class="desc">save()/restore() works for textBaseline</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +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(); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.transformation.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.transformation.html new file mode 100644 index 000000000..744f7ab7f --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.transformation.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.transformation</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.transformation</h1> +<p class="desc">save()/restore() affects the current transformation matrix</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("save()/restore() affects the current transformation matrix"); +_addTest(function(canvas, ctx) { + +ctx.fillStyle = '#0f0'; +ctx.fillRect(0, 0, 100, 50); +ctx.save(); +ctx.translate(200, 0); +ctx.restore(); +ctx.fillStyle = '#f00'; +ctx.fillRect(-200, 0, 100, 50); +_assertPixel(canvas, 50,25, 0,255,0,255, "50,25", "0,255,0,255"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.underflow.html b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.underflow.html new file mode 100644 index 000000000..c965b0256 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/2d.state.saverestore.underflow.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. --> +<title>Canvas test: 2d.state.saverestore.underflow</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/canvas-tests.js"></script> +<link rel="stylesheet" href="/common/canvas-tests.css"> +<body class="show_output"> + +<h1>2d.state.saverestore.underflow</h1> +<p class="desc">restore() with an empty stack has no effect</p> + + +<p class="output">Actual output:</p> +<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> + +<ul id="d"></ul> +<script> +var t = async_test("restore() with an empty stack has no effect"); +_addTest(function(canvas, ctx) { + +for (var i = 0; i < 16; ++i) + ctx.restore(); +ctx.lineWidth = 0.5; +ctx.restore(); +_assertSame(ctx.lineWidth, 0.5, "ctx.lineWidth", "0.5"); + + +}); +</script> + diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001-ref.htm b/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001-ref.htm new file mode 100644 index 000000000..aee610d2e --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001-ref.htm @@ -0,0 +1,11 @@ +<!doctype HTML> +<html> + <head> + <title>HTML5 Canvas Test: restore() pops top entry in drawing state stack</title> + <link rel="author" title="Microsoft" href="http://www.microsoft.com" /> + </head> + <body> + <p>Description: restore() pops the top entry in the drawing state stack.</p> + <div><img src='/images/threecolors.png' alt='3 colors'></div> + </body> +</html> diff --git a/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001.htm b/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001.htm new file mode 100644 index 000000000..6d5a3cb20 --- /dev/null +++ b/testing/web-platform/tests/2dcontext/the-canvas-state/canvas_state_restore_001.htm @@ -0,0 +1,42 @@ +<!doctype HTML> +<html> + <head> + <title>HTML5 Canvas Test: restore() pops top entry in drawing state stack</title> + <link rel="match" href="canvas_state_restore_001-ref.htm"> + <link rel="author" title="Microsoft" href="http://www.microsoft.com" /> + <link rel="help" href="http://www.w3.org/TR/2dcontext/#the-canvas-state" /> + <meta name="assert" content="restore() pops the top entry in the drawing state stack." /> + <script type="text/javascript"> + function runTest() + { + var canvas = document.getElementById("canvas1"); + var ctx = canvas.getContext("2d"); + ctx.fillStyle = "rgba(255, 0, 0, 1.0)"; + ctx.fillRect(0, 0, 99, 50); + + // Save colors to the stack as separate drawing states. + ctx.fillStyle = "rgba(255, 255, 0, 1.0)"; + ctx.save(); + ctx.fillStyle = "rgba(0, 0, 255, 1.0)"; + ctx.save(); + ctx.fillStyle = "rgba(0, 255, 0, 1.0)"; + ctx.save(); + + // Modify the current fillStyle. + ctx.fillStyle = "rgba(255, 0, 0, 1.0)"; + + // Restore the drawing states previously saved and draw with them. + ctx.restore(); + ctx.fillRect(66, 0, 33, 50); + ctx.restore(); + ctx.fillRect(33, 0, 33, 50); + ctx.restore(); + ctx.fillRect(0, 0, 33, 50); + } + </script> + </head> + <body onload="runTest()"> + <p>Description: restore() pops the top entry in the drawing state stack.</p> + <canvas id="canvas1" width="300" height="150">Browser does not support HTML5 Canvas.</canvas> + </body> +</html> |