Disabled (empty) SVG shapes cannot be hit

Disabled SVG shapes [1][2][3] should not be possible to hit since they
are considered "not rendered".

[1] https://svgwg.org/svg2-draft/shapes.html#RectElement
[2] https://svgwg.org/svg2-draft/shapes.html#CircleElement
[3] https://svgwg.org/svg2-draft/shapes.html#EllipseElement

Bug: 896641
Change-Id: I5fe530722a4d60ecd416cd68f06a7555bb6a520f
Reviewed-on: https://chromium-review.googlesource.com/c/1353983
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#611840}
diff --git a/third_party/blink/renderer/core/layout/svg/layout_svg_shape.cc b/third_party/blink/renderer/core/layout/svg/layout_svg_shape.cc
index 891762d..5d50614 100644
--- a/third_party/blink/renderer/core/layout/svg/layout_svg_shape.cc
+++ b/third_party/blink/renderer/core/layout/svg/layout_svg_shape.cc
@@ -352,6 +352,8 @@
   // We only draw in the foreground phase, so we only hit-test then.
   if (hit_test_action != kHitTestForeground)
     return false;
+  if (IsShapeEmpty())
+    return false;
   const ComputedStyle& style = StyleRef();
   const PointerEventsHitRules hit_rules(
       PointerEventsHitRules::SVG_GEOMETRY_HITTESTING,
diff --git a/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/disabled-shapes-01.svg b/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/disabled-shapes-01.svg
new file mode 100644
index 0000000..d92eea1
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/disabled-shapes-01.svg
@@ -0,0 +1,50 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml">
+  <title>Disabled shapes are not rendered</title>
+  <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"/>
+    <h:link rel="match" href="support/empty.svg"/>
+  </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"/>
+    </g>
+
+    <g transform="translate(150, 50)">
+      <circle/>
+      <circle r="0"/>
+      <circle r="-10"/>
+      <circle style="r: 0"/>
+      <circle style="r: -10px"/>
+    </g>
+
+    <g transform="translate(250, 50)">
+      <ellipse/>
+      <ellipse rx="0"/>
+      <ellipse rx="0" ry="10"/>
+      <ellipse rx="-10" ry="10"/>
+      <ellipse ry="0"/>
+      <ellipse ry="0" rx="10"/>
+      <ellipse ry="-10" 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"/>
+    </g>
+  </g>
+</svg>
diff --git a/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/support/empty.svg b/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/support/empty.svg
new file mode 100644
index 0000000..0c7be4e2
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/svg/shapes/reftests/support/empty.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg"/>
diff --git a/third_party/blink/web_tests/external/wpt/svg/shapes/scripted/disabled-shapes-not-hit.svg b/third_party/blink/web_tests/external/wpt/svg/shapes/scripted/disabled-shapes-not-hit.svg
new file mode 100644
index 0000000..5a621d9
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/svg/shapes/scripted/disabled-shapes-not-hit.svg
@@ -0,0 +1,68 @@
+<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"/>
+    </g>
+
+    <g transform="translate(150, 50)">
+      <circle/>
+      <circle r="0"/>
+      <circle r="-10"/>
+      <circle style="r: 0"/>
+      <circle style="r: -10px"/>
+    </g>
+
+    <g transform="translate(250, 50)">
+      <ellipse/>
+      <ellipse rx="0"/>
+      <ellipse rx="0" ry="10"/>
+      <ellipse rx="-10" ry="10"/>
+      <ellipse ry="0"/>
+      <ellipse ry="0" rx="10"/>
+      <ellipse ry="-10" 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"/>
+    </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>