commit 0cf780c090012183472cf6d964fb6a26661c6241
parent 1601d523c53a78990cfcf2f1b2f68adcc0423c4b
Author: Divyansh Mangal <dmangal@microsoft.com>
Date: Thu, 9 Oct 2025 20:36:26 +0000
Bug 1992365 [wpt PR 55196] - [SVG] Avoid throwing exception if UA can compute length via computed styles for `SVGGeometryElement`, a=testonly
Automatic update from web-platform-tests
[SVG] Avoid throwing exception if UA can compute length via computed
styles for `SVGGeometryElement`
According to the specification[1]:
If current element is a non-rendered element, and the user agent(UA)
is not able to compute the total length of the path, then throw an
InvalidStateError.
However, this also implies that if the UA is able to compute the
total length for a non-rendered element, such as by using computed
styles then an error should not be thrown in this case.
This CL addresses this scenario and ensures that no exception is
thrown when the UA can successfully determine the total length.
[1] https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getTotalLength
Bug: 41462013
Change-Id: Ifee9c833c86c2f3d609e0726e59b53a69b19ef4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6945694
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Kurt Catti-Schmidt <kschmi@microsoft.com>
Commit-Queue: Divyansh Mangal <dmangal@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1524433}
--
wpt-commits: 387038a30863b41f59cac1a7483c5f394e4bfe30
wpt-pr: 55196
Diffstat:
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/svg/types/scripted/SVGGeometryElement.getTotalLength-02.html b/testing/web-platform/tests/svg/types/scripted/SVGGeometryElement.getTotalLength-02.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<title>SVGGeometryElement.getTotalLength: 'display:none'</title>
+<link rel="author" title="Divyansh Mangal" href="mailto:dmangal@microsoft.com">
+<link rel="help" href="https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getTotalLength"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <rect id="rectTest" style="display:none" x="30" y="30" width="10" height="10"></rect>
+ <circle id="circleTest" style="display:none" cx="50" cy="50" r="5" />
+</svg>
+<script>
+ test(function() {
+ let perimeter = (width, height) => 2 * width + 2 * height;
+ assert_equals(rectTest.getTotalLength(), perimeter(rectTest.width.baseVal.value, rectTest.height.baseVal.value));
+ let circumference = (r) => 2 * Math.PI * r;
+ assert_approx_equals(circleTest.getTotalLength(), circumference(circleTest.r.baseVal.value), 1);
+ });
+</script>
diff --git a/testing/web-platform/tests/svg/types/scripted/SVGPathElement.getTotalLength-01.html b/testing/web-platform/tests/svg/types/scripted/SVGPathElement.getTotalLength-01.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<title>SVGPathElement.getTotalLength: 'display:none'</title>
+<link rel="author" title="Divyansh Mangal" href="mailto:dmangal@microsoft.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<style>
+ #path2, #path3 {
+ d:path("M 0 0 t 0 100");
+ }
+</style>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <path id="path1" d="M 0 0 t 0 100" style="display:none" />
+ <path id="path2" style="display:none;" />
+ <path id="path3" d="M 110,10 l 80,80 v -80 h -40" style="display:none;" />
+</svg>
+<script>
+ test(function() {
+ assert_equals(path1.getTotalLength(), 100);
+ },document.title + ', ' + 'path with d attribute specified on element');
+ test(function() {
+ assert_equals(path2.getTotalLength(), 100);
+ },document.title + ', ' + 'path with d attribute specified as styles');
+ test(function() {
+ assert_equals(path3.getTotalLength(), 100);
+ },document.title + ', ' + 'path with d attribute specified on element and as styles');
+</script>