diff options
Diffstat (limited to 'testing/web-platform/tests/svg/shapes/scripted')
3 files changed, 174 insertions, 0 deletions
diff --git a/testing/web-platform/tests/svg/shapes/scripted/disabled-shapes-not-hit.svg b/testing/web-platform/tests/svg/shapes/scripted/disabled-shapes-not-hit.svg new file mode 100644 index 0000000000..21ea907878 --- /dev/null +++ b/testing/web-platform/tests/svg/shapes/scripted/disabled-shapes-not-hit.svg @@ -0,0 +1,69 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml"> + <title>Disabled shapes are not rendered and cannot be hit</title> + <h:script src="/resources/testharness.js"/> + <h:script src="/resources/testharnessreport.js"/> + <metadata> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#RectElement"/> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#CircleElement"/> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#EllipseElement"/> + </metadata> + <g stroke="red" stroke-width="100"> + <g transform="translate(50, 50)"> + <rect/> + <rect width="0" height="10"/> + <rect width="-10" height="10"/> + <rect height="0" width="10"/> + <rect height="-10" width="10"/> + <rect style="width: 0"/> + <rect style="width: 0" height="10"/> + <rect style="width: -10px"/> + <rect style="width: -10px" height="10"/> + <rect style="height: 0"/> + <rect style="height: 0" width="10"/> + <rect style="height: -10px"/> + <rect style="height: -10px" width="10"/> + <rect style="width: calc(-10px); height: calc(-10px)"/> + </g> + + <g transform="translate(150, 50)"> + <circle/> + <circle r="0"/> + <circle r="-10"/> + <circle style="r: 0"/> + <circle style="r: -10px"/> + <circle style="r: calc(-10px)"/> + </g> + + <g transform="translate(250, 50)"> + <ellipse/> + <ellipse rx="0"/> + <ellipse rx="0" ry="10"/> + <ellipse ry="0"/> + <ellipse ry="0" rx="10"/> + <ellipse style="rx: 0"/> + <ellipse style="rx: -10px"/> + <ellipse style="rx: 0" ry="10"/> + <ellipse style="ry: 0"/> + <ellipse style="ry: -10px"/> + <ellipse style="ry: 0" rx="10"/> + <ellipse style="rx: calc(-10px); ry: calc(-10px)"/> + </g> + </g> + <script><![CDATA[ + test(function() { + let element = document.elementFromPoint(50, 50); + assert_equals(element, document.documentElement, "does not hit one of the shapes"); + }, document.title + ": <rect>"); + + test(function() { + let element = document.elementFromPoint(150, 50); + assert_equals(element, document.documentElement, "does not hit one of the shapes"); + }, document.title + ": <circle>"); + + test(function() { + let element = document.elementFromPoint(250, 50); + assert_equals(element, document.documentElement, "does not hit one of the shapes"); + }, document.title + ": <ellipse>"); + ]]> + </script> +</svg> diff --git a/testing/web-platform/tests/svg/shapes/scripted/shapes-clip-path.svg b/testing/web-platform/tests/svg/shapes/scripted/shapes-clip-path.svg new file mode 100644 index 0000000000..a8277226a5 --- /dev/null +++ b/testing/web-platform/tests/svg/shapes/scripted/shapes-clip-path.svg @@ -0,0 +1,78 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml"> + <title>Clipped shapes can be hit when rendered</title> + <h:script src="/resources/testharness.js"/> + <h:script src="/resources/testharnessreport.js"/> + <metadata> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#RectElement"/> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#CircleElement"/> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#EllipseElement"/> + </metadata> + <defs> + <clipPath id="clip1"> + <circle cx="100" cy="100" r="25"/> + </clipPath> + <clipPath id="clip2"> + <circle cx="150" cy="150" r="25"/> + </clipPath> + <clipPath id="clip3"> + <circle cx="250" cy="150" r="25"/> + </clipPath> + <clipPath id="clip4"> + <circle cx="350" cy="150" r="25"/> + </clipPath> + </defs> + <g> + <circle id="circle1" cx="100" cy="100" r="25"/> + <circle id="circle2" cx="150" cy="100" r="25" clip-path="url(#unknown)"/> + <circle id="circle3" cx="100" cy="150" r="25" clip-path="url(#clip1)"/> + <circle id="circle4" cx="150" cy="150" r="25" clip-path="url(#clip2)"/> + </g> + <g> + <ellipse id="ellipse1" cx="200" cy="100" rx="25" ry="15"/> + <ellipse id="ellipse2" cx="250" cy="100" rx="25" ry="15" clip-path="url(#unknown)"/> + <ellipse id="ellipse3" cx="200" cy="150" rx="25" ry="15" clip-path="url(#clip1)"/> + <ellipse id="ellipse4" cx="250" cy="150" rx="25" ry="15" clip-path="url(#clip3)"/> + </g> + <g> + <rect id="rect1" x="285" y="85" width="30" height="30"/> + <rect id="rect2" x="335" y="85" width="30" height="30" clip-path="url(#unknown)"/> + <rect id="rect3" x="285" y="135" width="30" height="30" clip-path="url(#clip1)"/> + <rect id="rect4" x="335" y="135" width="30" height="30" clip-path="url(#clip4)"/> + </g> + <script><![CDATA[ + class Expectation { + constructor(x, y, id = null) { + this.x = x; + this.y = y; + this.element = id ? document.getElementById(id) : document.documentElement; + } + } + class Shape { + constructor(name, offset) { + this.name = name; + this.offset = offset; + } + } + let shapes = []; + shapes.push(new Shape("circle", 0)); + shapes.push(new Shape("ellipse", 100)); + shapes.push(new Shape("rect", 200)); + + shapes.forEach(shape => { + test(function() { + let expectations = []; + + expectations.push(new Expectation(100 + shape.offset, 100, shape.name + "1")); + expectations.push(new Expectation(150 + shape.offset, 100, shape.name + "2")); + expectations.push(new Expectation(100 + shape.offset, 150)); + expectations.push(new Expectation(150 + shape.offset, 150, shape.name + "4")); + + expectations.forEach(expectation => { + let element = document.elementFromPoint(expectation.x, expectation.y); + assert_equals(element, expectation.element, "finds " + shape.name); + }); + }, document.title + ": " + shape.name); + }); + ]]> + </script> +</svg> diff --git a/testing/web-platform/tests/svg/shapes/scripted/stroke-dashes-hit-at-high-scale.svg b/testing/web-platform/tests/svg/shapes/scripted/stroke-dashes-hit-at-high-scale.svg new file mode 100644 index 0000000000..b57a9e0aa7 --- /dev/null +++ b/testing/web-platform/tests/svg/shapes/scripted/stroke-dashes-hit-at-high-scale.svg @@ -0,0 +1,27 @@ +<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml" viewBox="0 0 36 36" width="600" height="600"> + <title>Strokes w/dashes are properly hit-tested, even at large scale factors</title> + <h:script src="/resources/testharness.js"/> + <h:script src="/resources/testharnessreport.js"/> + <metadata> + <h:link rel="help" href="https://svgwg.org/svg2-draft/shapes.html#CircleElement"/> + <h:link rel="help" href="https://svgwg.org/svg2-draft/painting.html#StrokeProperties"/> + </metadata> + <circle id="circle" cx="6" cy="10" r="5" stroke="blue" stroke-width="1" stroke-dasharray="10 21.4159" fill="none"/> + <script> + <![CDATA[ + test(function() { + let svg = document.getElementById("svg"); + let circle = document.getElementById("circle"); + let hitTest = function(x, y) { + return document.elementFromPoint( + x * svg.width.baseVal.value / svg.viewBox.baseVal.width, + y * svg.height.baseVal.value / svg.viewBox.baseVal.height); + } + assert_equals(hitTest(11, 10), circle, "hit-test the beginning of the dash (t=0)"); + assert_equals(hitTest(8.70, 14.21), circle, "hit-test the middle of the dash (t=5)"); + assert_equals(hitTest(4.10, 14.63), circle, "hit-test the end of the dash (t=9.8)"); + assert_equals(hitTest(3.74, 14.46), svg, "hit-test past the end of the dash (t=10.2)"); + }); + ]]> + </script> +</svg> |