Skip to content

Truly independent web browser

LibWeb: Move <animateMotion> targets along the shape <mpath> refers to

Jelle Raaijmakers04e7a4399308
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 2ee1fcd2127..6aa8e528d13 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -237,6 +237,7 @@
#include <LibWeb/ResizeObserver/ResizeObserver.h>
#include <LibWeb/ResizeObserver/ResizeObserverEntry.h>
#include <LibWeb/SVG/SMILTimeContainer.h>
+#include <LibWeb/SVG/SVGAnimateMotionElement.h>
#include <LibWeb/SVG/SVGDecodedImageData.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGPatternElement.h>
@@ -996,6 +997,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_associated_animation_timelines);
visitor.visit(m_smil_time_containers_to_begin);
+ visitor.visit(m_animate_motion_elements_to_update);
visitor.visit(m_list_of_available_images);
for (auto& it : m_map_of_preloaded_resources)
visitor.visit(it.value);
@@ -5162,6 +5164,15 @@ void Document::begin_smil_time_container_once_loaded(SVG::SMILTimeContainer& tim
m_smil_time_containers_to_begin.append(time_container);
}
+void Document::schedule_svg_referenced_motion_path_update(SVG::SVGAnimateMotionElement& element)
+{
+ // The motion path that an animateMotion element takes from the element its mpath child references is the geometry
+ // of that element, which depends on its style. Instead of updating style and layout when the reference changes,
+ // take the motion path the next time the animations are updated.
+ if (!m_animate_motion_elements_to_update.contains_slow(GC::Ref { element }))
+ m_animate_motion_elements_to_update.append(element);
+}
+
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#completely-finish-loading
void Document::completely_finish_loading()
{
@@ -9055,7 +9066,14 @@ void Document::prepare_to_observe_css_animation_events()
void Document::update_animations_and_send_events(double timestamp)
{
m_last_animation_frame_timestamp = timestamp;
- auto timelines_to_update = GC::RootVector { m_associated_animation_timelines.values() };
+
+ // AD-HOC: Take the motion paths of animateMotion elements from the elements their mpath children refer to. See
+ // schedule_svg_referenced_motion_path_update().
+ GC::RootVector animate_motion_elements_to_update = { exchange(m_animate_motion_elements_to_update, {}) };
+ for (auto& element : animate_motion_elements_to_update)
+ element->update_referenced_motion_path();
+
+ GC::RootVector timelines_to_update = { m_associated_animation_timelines.values() };
{
HTML::TemporaryExecutionContext temporary_execution_context { relevant_settings_object() };
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index f59c0b09fc9..e5c54d69ccb 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1208,6 +1208,7 @@ public:
WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> get_animations();
HashTable<GC::Ref<Animations::AnimationTimeline>> const& associated_animation_timelines() const { return m_associated_animation_timelines; }
void begin_smil_time_container_once_loaded(SVG::SMILTimeContainer&);
+ void schedule_svg_referenced_motion_path_update(SVG::SVGAnimateMotionElement&);
bool ready_to_run_scripts() const { return m_ready_to_run_scripts; }
void set_ready_to_run_scripts();
@@ -2167,6 +2168,7 @@ private:
// https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document
HashTable<GC::Ref<Animations::AnimationTimeline>> m_associated_animation_timelines;
Vector<GC::Ref<SVG::SMILTimeContainer>> m_smil_time_containers_to_begin;
+ Vector<GC::Ref<SVG::SVGAnimateMotionElement>> m_animate_motion_elements_to_update;
// NB: Weak so the document does not unnecessarily keep animations alive. Note that this also includes animations
// associated with elements in shadow trees so differs from getAnimations()
diff --git a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp
index 72697975c5f..628a0090217 100644
--- a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp
@@ -9,9 +9,12 @@
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
+#include <LibWeb/DOM/Document.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/Path.h>
#include <LibWeb/SVG/SVGAnimateMotionElement.h>
+#include <LibWeb/SVG/SVGGeometryElement.h>
+#include <LibWeb/SVG/SVGMPathElement.h>
namespace Web::SVG {
@@ -29,6 +32,27 @@ void SVGAnimateMotionElement::attribute_changed(Utf16FlyString const& name, Opti
update_animation();
}
+void SVGAnimateMotionElement::schedule_referenced_motion_path_update()
+{
+ document().schedule_svg_referenced_motion_path_update(*this);
+}
+
+// https://svgwg.org/specs/animations/#AnimateMotionElement
+void SVGAnimateMotionElement::update_referenced_motion_path()
+{
+ // If the ‘mpath’ sub-element refers to a shape element, the motion path is defined by the equivalent path of the
+ // shape element.
+ // NB: Only the first mpath child counts, as the content model allows one. Without a shape element that it refers to,
+ // the attributes of this element define the motion path.
+ // FIXME: Follow changes to the geometry of the referenced element.
+ m_referenced_motion_path.clear();
+ if (auto* mpath_element = is_connected() ? first_child_of_type<SVGMPathElement>() : nullptr) {
+ if (auto* geometry_element = as_if<SVGGeometryElement>(mpath_element->referenced_element().ptr()))
+ m_referenced_motion_path = geometry_element->computed_path();
+ }
+ update_animation();
+}
+
// https://svgwg.org/specs/animations/#AnimateMotionElementPathAttribute
Optional<CSS::PropertyID> SVGAnimateMotionElement::target_property() const
{
@@ -113,8 +137,10 @@ Vector<Animations::BaseKeyframe> SVGAnimateMotionElement::keyframes(SVGElement c
{
// Regarding the definition of the motion path, the ‘mpath’ element overrides the ‘path’ attribute, which overrides
// ‘values’, which overrides ‘from’, ‘by’ and ‘to’.
- // FIXME: Take the motion path from an mpath child element, and from the values and by attributes.
+ // FIXME: Take the motion path from the values and by attributes.
// FIXME: Apply the keyPoints and rotate attributes.
+ if (m_referenced_motion_path.has_value())
+ return keyframes_along_motion_path(*m_referenced_motion_path, property_id);
if (auto path = get_attribute(AttributeNames::path); path.has_value())
return keyframes_along_motion_path(parse_path_data(*path).to_gfx_path(), property_id);
diff --git a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h
index ccea0abf288..83007ab0481 100644
--- a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h
+++ b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h
@@ -6,7 +6,7 @@
#pragma once
-#include <LibGfx/Forward.h>
+#include <LibGfx/Path.h>
#include <LibWeb/SVG/SVGAnimationElement.h>
namespace Web::SVG {
@@ -15,6 +15,10 @@ class SVGAnimateMotionElement final : public SVGAnimationElement {
WEB_WRAPPABLE(SVGAnimateMotionElement, SVGAnimationElement);
GC_DECLARE_ALLOCATOR(SVGAnimateMotionElement);
+public:
+ void schedule_referenced_motion_path_update();
+ void update_referenced_motion_path();
+
private:
SVGAnimateMotionElement(DOM::Document&, DOM::QualifiedName);
@@ -23,6 +27,8 @@ private:
virtual Optional<CSS::PropertyID> target_property() const override;
virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const override;
static Vector<Animations::BaseKeyframe> keyframes_along_motion_path(Gfx::Path const&, CSS::PropertyID);
+
+ Optional<Gfx::Path> m_referenced_motion_path;
};
}
diff --git a/Libraries/LibWeb/SVG/SVGMPathElement.cpp b/Libraries/LibWeb/SVG/SVGMPathElement.cpp
index 1ba556b8015..d3fcc75502c 100644
--- a/Libraries/LibWeb/SVG/SVGMPathElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGMPathElement.cpp
@@ -4,6 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibURL/URL.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/DOM/ParentNode.h>
+#include <LibWeb/Namespace.h>
+#include <LibWeb/SVG/AttributeNames.h>
+#include <LibWeb/SVG/FragmentIdentifier.h>
+#include <LibWeb/SVG/SVGAnimateMotionElement.h>
#include <LibWeb/SVG/SVGMPathElement.h>
namespace Web::SVG {
@@ -21,4 +28,58 @@ void SVGMPathElement::visit_edges(Cell::Visitor& visitor)
SVGURIReferenceMixin::visit_edges(visitor);
}
+void SVGMPathElement::inserted()
+{
+ Base::inserted();
+ motion_path_changed(parent());
+}
+
+void SVGMPathElement::removed_from(IsSubtreeRoot is_subtree_root, Node* old_ancestor, Node& old_root)
+{
+ Base::removed_from(is_subtree_root, old_ancestor, old_root);
+ if (is_subtree_root == IsSubtreeRoot::Yes)
+ motion_path_changed(old_ancestor);
+}
+
+void SVGMPathElement::moved_from(IsSubtreeRoot is_subtree_root, GC::Ptr<Node> old_ancestor)
+{
+ Base::moved_from(is_subtree_root, old_ancestor);
+ if (is_subtree_root == IsSubtreeRoot::Yes)
+ motion_path_changed(old_ancestor);
+ motion_path_changed(parent());
+}
+
+void SVGMPathElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)
+{
+ Base::attribute_changed(name, old_value, value, namespace_);
+ if (name == AttributeNames::href && (!namespace_.has_value() || namespace_ == Namespace::XLink))
+ motion_path_changed(parent());
+}
+
+void SVGMPathElement::motion_path_changed(GC::Ptr<Node> parent)
+{
+ if (auto* animate_motion_element = as_if<SVGAnimateMotionElement>(parent.ptr()))
+ animate_motion_element->schedule_referenced_motion_path_update();
+}
+
+// https://svgwg.org/specs/animations/#MPathElementHrefAttribute
+GC::Ptr<DOM::Element> SVGMPathElement::referenced_element()
+{
+ // A URL reference to the ‘path’ element or shape element which defines the motion path.
+ // Refer to the common handling defined for URL reference attributes and deprecated XLink attributes.
+ // FIXME: Resolve references to elements in other documents.
+ auto href = get_attribute_ns(OptionalNone {}, AttributeNames::href);
+ if (!href.has_value())
+ href = get_attribute_ns(Namespace::XLink, AttributeNames::href);
+ if (!href.has_value())
+ return {};
+ auto url = document().encoding_parse_url(*href);
+ if (!url.has_value() || !url->fragment().has_value())
+ return {};
+ auto* root = as_if<DOM::ParentNode>(this->root());
+ if (!root)
+ return {};
+ return root->get_element_by_id(decode_fragment_identifier(*url->fragment()));
+}
+
}
diff --git a/Libraries/LibWeb/SVG/SVGMPathElement.h b/Libraries/LibWeb/SVG/SVGMPathElement.h
index cea796fd182..20af6f133c8 100644
--- a/Libraries/LibWeb/SVG/SVGMPathElement.h
+++ b/Libraries/LibWeb/SVG/SVGMPathElement.h
@@ -17,10 +17,19 @@ class SVGMPathElement final
WEB_WRAPPABLE(SVGMPathElement, SVGElement);
GC_DECLARE_ALLOCATOR(SVGMPathElement);
+public:
+ GC::Ptr<DOM::Element> referenced_element();
+
private:
SVGMPathElement(DOM::Document&, DOM::QualifiedName);
virtual void visit_edges(Cell::Visitor&) override;
+ virtual void inserted() override;
+ virtual void removed_from(IsSubtreeRoot, Node* old_ancestor, Node& old_root) override;
+ virtual void moved_from(IsSubtreeRoot, GC::Ptr<Node> old_ancestor) override;
+ virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;
+
+ static void motion_path_changed(GC::Ptr<Node> parent);
};
}
diff --git a/Tests/LibWeb/Crash/wpt-import/svg/animations/mpath-zero-radius-crash.html b/Tests/LibWeb/Crash/wpt-import/svg/animations/mpath-zero-radius-crash.html
new file mode 100644
index 00000000000..a0528a27f5d
--- /dev/null
+++ b/Tests/LibWeb/Crash/wpt-import/svg/animations/mpath-zero-radius-crash.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+ <script>
+ document.addEventListener("DOMContentLoaded", async () => {
+ const frame = document.createElementNS("http://www.w3.org/1999/xhtml", "frame")
+ document.documentElement.appendChild(frame)
+ frame.src = `data:text/html,` + encodeURIComponent(`<!doctype html>
+<svg>
+ <ellipse id="id_8" ry="100pt"></ellipse>
+ <animateMotion>
+ <desc></desc>
+ <mpath xlink:href="#id_8"></mpath>
+ </animateMotion>
+</svg>`);
+ })
+ </script>
+</head>
+</html>
diff --git a/Tests/LibWeb/Text/expected/SVG/animate-motion-element-mpath.txt b/Tests/LibWeb/Text/expected/SVG/animate-motion-element-mpath.txt
new file mode 100644
index 00000000000..f4509888dcd
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SVG/animate-motion-element-mpath.txt
@@ -0,0 +1,11 @@
+path: 50.0, 0.0
+shape: 50.0, 100.0
+href-over-xlink-href: 50.0, 0.0
+xlink-href: 0.0, 50.0
+over-path-attribute: 50.0, 0.0
+missing-element-falls-back-to-path-attribute: 0.0, 100.0
+not-a-shape-falls-back-to-path-attribute: 0.0, 100.0
+href-changed: 0.0, 50.0
+mpath-removed: 0.0, 100.0
+mpath-inserted: 0.0, 50.0
+in-shadow-root: 0.0, 150.0
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-circle.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-circle.txt
new file mode 100644
index 00000000000..f760723f5d8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-circle.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for checking position of the svg element when animateMotion's mpath is a circle
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-display-none.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-display-none.txt
new file mode 100644
index 00000000000..d048f97c9fc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-display-none.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for checking position of the svg element when animateMotion's mpath is display:none
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-ellipse.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-ellipse.txt
new file mode 100644
index 00000000000..12a95a02e51
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-ellipse.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for checking position of the svg element when animateMotion's mpath is an ellipse
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-line.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-line.txt
new file mode 100644
index 00000000000..eaa5d3f2e0a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-line.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for checking position of the svg element when animateMotion's mpath is a line
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rect.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rect.txt
new file mode 100644
index 00000000000..122c4bb9c2d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rect.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for checking position of the svg element when animateMotion's mpath is a rect
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/SVG/animate-motion-element-mpath.html b/Tests/LibWeb/Text/input/SVG/animate-motion-element-mpath.html
new file mode 100644
index 00000000000..3e93a18fb42
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SVG/animate-motion-element-mpath.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<svg id="svg" width="400" height="400">
+ <path id="horizontal" d="M0,0 L100,0"/>
+ <path id="vertical" d="M0,0 L0,100"/>
+ <circle id="circle" cx="100" cy="100" r="50"/>
+ <g id="not-a-shape"></g>
+ <rect id="path" width="10" height="10"><animateMotion dur="2s"><mpath href="#horizontal"/></animateMotion></rect>
+ <rect id="shape" width="10" height="10"><animateMotion dur="2s"><mpath href="#circle"/></animateMotion></rect>
+ <rect id="href-over-xlink-href" width="10" height="10"><animateMotion dur="2s"><mpath href="#horizontal" xlink:href="#vertical"/></animateMotion></rect>
+ <rect id="xlink-href" width="10" height="10"><animateMotion dur="2s"><mpath xlink:href="#vertical"/></animateMotion></rect>
+ <rect id="over-path-attribute" width="10" height="10"><animateMotion dur="2s" path="M0,0 L0,200"><mpath href="#horizontal"/></animateMotion></rect>
+ <rect id="missing-element-falls-back-to-path-attribute" width="10" height="10"><animateMotion dur="2s" path="M0,0 L0,200"><mpath href="#missing"/></animateMotion></rect>
+ <rect id="not-a-shape-falls-back-to-path-attribute" width="10" height="10"><animateMotion dur="2s" path="M0,0 L0,200"><mpath href="#not-a-shape"/></animateMotion></rect>
+ <rect id="href-changed" width="10" height="10"><animateMotion dur="2s"><mpath id="mpath-to-change" href="#horizontal"/></animateMotion></rect>
+ <rect id="mpath-removed" width="10" height="10"><animateMotion dur="2s" path="M0,0 L0,200"><mpath id="mpath-to-remove" href="#horizontal"/></animateMotion></rect>
+ <rect id="mpath-inserted" width="10" height="10"><animateMotion id="animate-motion-to-insert-into" dur="2s"/></rect>
+</svg>
+<div id="host"></div>
+<script>
+ function printPositions(svg, rects) {
+ const origin = svg.getBoundingClientRect();
+ for (const rect of rects) {
+ const box = rect.getBoundingClientRect();
+ println(`${rect.id}: ${(box.left - origin.left).toFixed(1)}, ${(box.top - origin.top).toFixed(1)}`);
+ }
+ }
+
+ asyncTest(async done => {
+ await new Promise(resolve => window.addEventListener("load", resolve));
+ await new Promise(requestAnimationFrame);
+
+ document.getElementById("mpath-to-change").setAttribute("href", "#vertical");
+ document.getElementById("mpath-to-remove").remove();
+ const mpath = document.createElementNS("http://www.w3.org/2000/svg", "mpath");
+ mpath.setAttribute("href", "#vertical");
+ document.getElementById("animate-motion-to-insert-into").appendChild(mpath);
+
+ const shadowRoot = host.attachShadow({ mode: "open" });
+ shadowRoot.innerHTML = `
+ <svg width="400" height="400">
+ <path id="horizontal" d="M0,0 L0,300"/>
+ <rect id="in-shadow-root" width="10" height="10"><animateMotion dur="2s"><mpath href="#horizontal"/></animateMotion></rect>
+ </svg>`;
+ await new Promise(requestAnimationFrame);
+
+ const shadowSVG = shadowRoot.querySelector("svg");
+ for (const element of [svg, shadowSVG]) {
+ element.pauseAnimations();
+ element.setCurrentTime(1);
+ }
+ printPositions(svg, svg.querySelectorAll("rect"));
+ printPositions(shadowSVG, shadowSVG.querySelectorAll("rect"));
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-circle.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-circle.html
new file mode 100644
index 00000000000..170b8ee1044
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-circle.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test for checking position of the svg element when animateMotion's mpath is a circle</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <circle id="circle" cx="-100" r="100" display="none"/>
+ <rect width="50" height="50" x="0" y="0" fill="green">
+ <animateMotion id="anim" begin="0s" dur="4s" fill="freeze">
+ <mpath href="#circle"/>
+ </animateMotion>
+ </rect>
+</svg>
+
+<script>
+var rootSVGElement = document.querySelector("svg");
+var epsilon = 1.0;
+
+// Setup animation test
+function sample1() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+function sample2() {
+ assert_approx_equals(rootSVGElement.getBBox().x, -200, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+function sample3() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+smil_async_test((t) => {
+ var rects = rootSVGElement.ownerDocument.getElementsByTagName("rect");
+ rect1 = rects[0];
+
+ const expectedValues = [
+ // [animationId, time, sampleCallback]
+ ["anim", 0.0, sample1],
+ ["anim", 2.0, sample2],
+ ["anim", 4.0, sample3]
+ ];
+
+ runAnimationTest(t, expectedValues);
+});
+
+window.animationStartsImmediately = true;
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-display-none.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-display-none.html
new file mode 100644
index 00000000000..f0f31f94664
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-display-none.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test for checking position of the svg element when animateMotion's mpath is display:none</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <path id="path" d="M0,0 100,0" display="none"/>
+ <rect width="50" height="50" x="0" y="0" fill="green">
+ <animateMotion id="anim" begin="0s" dur="4s" fill="freeze">
+ <mpath href="#path"/>
+ </animateMotion>
+ </rect>
+</svg>
+
+<script>
+var rootSVGElement = document.querySelector("svg");
+var epsilon = 1.0;
+
+// Setup animation test
+function sample1() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+}
+
+function sample2() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 50, epsilon);
+}
+
+function sample3() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 100, epsilon);
+}
+
+smil_async_test((t) => {
+ var rects = rootSVGElement.ownerDocument.getElementsByTagName("rect");
+ rect1 = rects[0];
+
+ const expectedValues = [
+ // [animationId, time, sampleCallback]
+ ["anim", 0.0, sample1],
+ ["anim", 2.0, sample2],
+ ["anim", 4.0, sample3]
+ ];
+
+ runAnimationTest(t, expectedValues);
+});
+
+window.animationStartsImmediately = true;
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-ellipse.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-ellipse.html
new file mode 100644
index 00000000000..943fa076f7d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-ellipse.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test for checking position of the svg element when animateMotion's mpath is an ellipse</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <ellipse id="ellipse" cx="-100" rx="100" display="none"/>
+ <rect width="50" height="50" x="0" y="0" fill="green">
+ <animateMotion id="anim" begin="0s" dur="4s" fill="freeze">
+ <mpath href="#ellipse"/>
+ </animateMotion>
+ </rect>
+</svg>
+
+<script>
+var rootSVGElement = document.querySelector("svg");
+var epsilon = 1.0;
+
+// Setup animation test
+function sample1() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+function sample2() {
+ assert_approx_equals(rootSVGElement.getBBox().x, -200, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+function sample3() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+ assert_approx_equals(rootSVGElement.getBBox().y, 0, epsilon);
+}
+
+smil_async_test((t) => {
+ var rects = rootSVGElement.ownerDocument.getElementsByTagName("rect");
+ rect1 = rects[0];
+
+ const expectedValues = [
+ // [animationId, time, sampleCallback]
+ ["anim", 0.0, sample1],
+ ["anim", 2.0, sample2],
+ ["anim", 4.0, sample3]
+ ];
+
+ runAnimationTest(t, expectedValues);
+});
+
+window.animationStartsImmediately = true;
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-line.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-line.html
new file mode 100644
index 00000000000..ac7f274c42e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-line.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test for checking position of the svg element when animateMotion's mpath is a line</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <line id="line" x2="100" display="none"/>
+ <rect width="50" height="50" x="0" y="0" fill="green">
+ <animateMotion id="anim" begin="0s" dur="4s" fill="freeze">
+ <mpath href="#line"/>
+ </animateMotion>
+ </rect>
+</svg>
+
+<script>
+var rootSVGElement = document.querySelector("svg");
+var epsilon = 1.0;
+
+// Setup animation test
+function sample1() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+}
+
+function sample2() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 50, epsilon);
+}
+
+function sample3() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 100, epsilon);
+}
+
+smil_async_test((t) => {
+ var rects = rootSVGElement.ownerDocument.getElementsByTagName("rect");
+ rect1 = rects[0];
+
+ const expectedValues = [
+ // [animationId, time, sampleCallback]
+ ["anim", 0.0, sample1],
+ ["anim", 2.0, sample2],
+ ["anim", 4.0, sample3]
+ ];
+
+ runAnimationTest(t, expectedValues);
+});
+
+window.animationStartsImmediately = true;
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rect.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rect.html
new file mode 100644
index 00000000000..b1ab29621ac
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rect.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test for checking position of the svg element when animateMotion's mpath is a rect</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <rect id="rect" width="100" height="100" display="none"/>
+ <rect width="50" height="50" x="0" y="0" fill="green">
+ <animateMotion id="anim" begin="0s" dur="4s" fill="freeze">
+ <mpath href="#rect"/>
+ </animateMotion>
+ </rect>
+</svg>
+
+<script>
+var rootSVGElement = document.querySelector("svg");
+var epsilon = 1.0;
+
+// Setup animation test
+function sample1() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+}
+
+function sample2() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 100, epsilon);
+}
+
+function sample3() {
+ assert_approx_equals(rootSVGElement.getBBox().x, 0, epsilon);
+}
+
+smil_async_test((t) => {
+ var rects = rootSVGElement.ownerDocument.getElementsByTagName("rect");
+ rect1 = rects[1];
+
+ const expectedValues = [
+ // [animationId, time, sampleCallback]
+ ["anim", 0.0, sample1],
+ ["anim", 2.0, sample2],
+ ["anim", 4.0, sample3]
+ ];
+
+ runAnimationTest(t, expectedValues);
+});
+
+window.animationStartsImmediately = true;
+
+</script>