Automatic update from web-platform-tests
[SVG] Implement `setPathData()` on `SVGPathElement`
Implements `setPathData(sequence<SVGPathSegment> pathData)` from the
SVG Paths spec [1] on `SVGPathElement`.
Valid segments are built into an SVGPathByteStream (via
SVGPathByteStreamBuilder), then applied through `setAttribute("d", …)`
so the existing mutation pipeline (invalidation, <use> instances,
MutationObservers) fires. A leading non-moveto yields an empty path;
on the first invalid segment (unknown type, wrong arity, non-finite
value, non-binary arc flag) that segment and all after it are dropped.
Gated behind the existing experimental runtime flag `SVGPathDataAPI`.
Instrumented via the `SVGPathElementSetPathData` use counter.
[1] https://svgwg.org/specs/paths/#__svg__SVGPathData__setPathData
Design: https://docs.google.com/document/d/1uCVUqYGKgsCCu7LEtEdO3Yuea-MT-I2XsU6Eoe3mlQI/edit?usp=sharing
Bug: 40441025
Change-Id: I70419142ad23736d2e0e0f1a4ed4833e6c76fef8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7863903
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Divyansh Mangal <dmangal@microsoft.com>
Commit-Queue: Virali Purbey <viralipurbey@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1651484}
--
wpt-commits: 3c7d417eaf128fa7bfad500611b4e071a1e0627e
wpt-pr: 60835
58 lines
2.0 KiB
HTML
58 lines
2.0 KiB
HTML
<!doctype html>
|
|
<title>SVGPathElement.setPathData() fires MutationObserver on the d attribute</title>
|
|
<link rel="help" href="https://svgwg.org/specs/paths/#__svg__SVGPathData__setPathData">
|
|
<link rel="author" title="Virali Purbey" href="mailto:viralipurbey@microsoft.com">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="support/getPathData-helpers.js"></script>
|
|
|
|
<svg></svg>
|
|
<script>
|
|
// setPathData() must fire MutationObserver (equivalent to setAttribute('d')).
|
|
|
|
promise_test(async () => {
|
|
const path = createPath("M 0 0");
|
|
const records = [];
|
|
const observer = new MutationObserver(mutations => {
|
|
for (const m of mutations) {
|
|
records.push({
|
|
type: m.type,
|
|
attributeName: m.attributeName,
|
|
oldValue: m.oldValue,
|
|
newValue: m.target.getAttribute(m.attributeName)
|
|
});
|
|
}
|
|
});
|
|
observer.observe(path, { attributes: true, attributeOldValue: true,
|
|
attributeFilter: ["d"] });
|
|
|
|
path.setPathData([
|
|
{ type: "M", values: [0, 0] },
|
|
{ type: "L", values: [10, 10] }
|
|
]);
|
|
|
|
await Promise.resolve(); // Flush microtasks so MutationObserver fires.
|
|
|
|
observer.disconnect();
|
|
assert_equals(records.length, 1, "exactly one mutation record");
|
|
assert_equals(records[0].type, "attributes");
|
|
assert_equals(records[0].attributeName, "d");
|
|
assert_equals(records[0].oldValue, "M 0 0");
|
|
assert_equals(records[0].newValue, "M 0 0 L 10 10");
|
|
}, "setPathData() fires a MutationObserver record for the d attribute");
|
|
|
|
promise_test(async () => {
|
|
const path = createPath("M 0 0 L 5 5");
|
|
let count = 0;
|
|
const observer = new MutationObserver(mutations => { count += mutations.length; });
|
|
observer.observe(path, { attributes: true, attributeFilter: ["d"] });
|
|
|
|
path.setPathData([]); // Removes the d attribute.
|
|
|
|
await Promise.resolve();
|
|
observer.disconnect();
|
|
assert_equals(count, 1, "empty input still fires one record");
|
|
assert_equals(path.getAttribute("d"), null);
|
|
}, "setPathData([]) fires a MutationObserver record");
|
|
</script>
|