Skip to content

Truly independent web browser

LibWeb: Import SVGAnimatedRect interface tests

Andreas Klingb3a03068c190
diff --git a/Tests/LibWeb/Text/expected/svg-viewbox-rectangle-reset.txt b/Tests/LibWeb/Text/expected/svg-viewbox-rectangle-reset.txt
new file mode 100644
index 00000000000..8bcf4641a0e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/svg-viewbox-rectangle-reset.txt
@@ -0,0 +1,40 @@
+svg initial: null / null
+svg null: 1 2 3 4 / 1 2 3 4
+svg null identity: false
+svg "invalid": 1 2 3 4 / 1 2 3 4
+svg "invalid" identity: false
+svg "": 1 2 3 4 / 1 2 3 4
+svg "" identity: false
+svg restored: 5 6 7 8 / 5 6 7 8
+symbol initial: null / null
+symbol null: 1 2 3 4 / 1 2 3 4
+symbol null identity: false
+symbol "invalid": 1 2 3 4 / 1 2 3 4
+symbol "invalid" identity: false
+symbol "": 1 2 3 4 / 1 2 3 4
+symbol "" identity: false
+symbol restored: 5 6 7 8 / 5 6 7 8
+marker initial: null / null
+marker null: 1 2 3 4 / 1 2 3 4
+marker null identity: false
+marker "invalid": 1 2 3 4 / 1 2 3 4
+marker "invalid" identity: false
+marker "": 1 2 3 4 / 1 2 3 4
+marker "" identity: false
+marker restored: 5 6 7 8 / 5 6 7 8
+pattern initial: null / null
+pattern null: 1 2 3 4 / 1 2 3 4
+pattern null identity: false
+pattern "invalid": 1 2 3 4 / 1 2 3 4
+pattern "invalid" identity: false
+pattern "": 1 2 3 4 / 1 2 3 4
+pattern "" identity: false
+pattern restored: 5 6 7 8 / 5 6 7 8
+view initial: null / null
+view null: 1 2 3 4 / 1 2 3 4
+view null identity: false
+view "invalid": 1 2 3 4 / 1 2 3 4
+view "invalid" identity: false
+view "": 1 2 3 4 / 1 2 3 4
+view "" identity: false
+view restored: 5 6 7 8 / 5 6 7 8
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedRect.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedRect.txt
new file mode 100644
index 00000000000..997c7b5e2dd
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedRect.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 5 tests
+
+2 Pass
+3 Fail
+Fail SVGAnimatedRect interface - utilizing the viewBox property of SVGSVGElement
+Fail baseVal/animVal are zero rects when the viewBox attribute is unset
+Pass baseVal/animVal return the same SVGRect across reads
+Pass setAttribute('viewBox', ...) is reflected in baseVal/animVal
+Fail removeAttribute('viewBox') resets baseVal/animVal to a zero rect
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/svg-viewbox-rectangle-reset.html b/Tests/LibWeb/Text/input/svg-viewbox-rectangle-reset.html
new file mode 100644
index 00000000000..8fd9430e560
--- /dev/null
+++ b/Tests/LibWeb/Text/input/svg-viewbox-rectangle-reset.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script>
+ test(() => {
+ const coordinates = rect => rect ? [rect.x, rect.y, rect.width, rect.height].join(" ") : "null";
+ for (const name of ["svg", "symbol", "marker", "pattern", "view"]) {
+ const element = document.createElementNS("http://www.w3.org/2000/svg", name);
+ println(`${name} initial: ${coordinates(element.viewBox.baseVal)} / ${coordinates(element.viewBox.animVal)}`);
+ element.setAttribute("viewBox", "1 2 3 4");
+ const base = element.viewBox.baseVal;
+ const animated = element.viewBox.animVal;
+ for (const value of [null, "invalid", ""]) {
+ element.setAttribute("viewBox", "1 2 3 4");
+ if (value === null)
+ element.removeAttribute("viewBox");
+ else
+ element.setAttribute("viewBox", value);
+ println(`${name} ${JSON.stringify(value)}: ${coordinates(base)} / ${coordinates(animated)}`);
+ println(`${name} ${JSON.stringify(value)} identity: ${base === element.viewBox.baseVal && animated === element.viewBox.animVal}`);
+ }
+ element.setAttribute("viewBox", "5 6 7 8");
+ println(`${name} restored: ${coordinates(base)} / ${coordinates(animated)}`);
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGAnimatedRect.html b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGAnimatedRect.html
new file mode 100644
index 00000000000..c017f5c444e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGAnimatedRect.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<title>SVGAnimatedRect interface - utilizing the viewBox property of SVGSVGElement</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script>
+const FIELDS = ["x", "y", "width", "height"];
+
+function newSVG() {
+ return document.createElementNS("http://www.w3.org/2000/svg", "svg");
+}
+
+test(function() {
+ // This test checks the SVGAnimatedRect API - utilizing the viewBox property of SVGSVGElement.
+
+ var svgElement = newSVG();
+
+ // Check initial viewBox value.
+ assert_true(svgElement.viewBox instanceof SVGAnimatedRect);
+ assert_true(svgElement.viewBox.baseVal instanceof SVGRect);
+ assert_equals(svgElement.viewBox.baseVal.x, 0);
+ assert_true(svgElement.viewBox.animVal instanceof SVGRect);
+
+ // Check that rects are dynamic, caching value in a local variable and modifying it, should take effect.
+ var numRef = svgElement.viewBox.baseVal;
+ numRef.x = 100;
+ assert_equals(numRef.x, 100);
+ assert_equals(svgElement.viewBox.baseVal.x, 100);
+ assert_true(svgElement.hasAttribute("viewBox"));
+
+ // Check that assigning to baseVal has no effect, as no setter is defined.
+ svgElement.viewBox.baseVal = -1;
+ assert_equals(svgElement.viewBox.baseVal.x, 100);
+ svgElement.viewBox.baseVal = 'aString';
+ assert_equals(svgElement.viewBox.baseVal.x, 100);
+ svgElement.viewBox.baseVal = svgElement;
+ assert_equals(svgElement.viewBox.baseVal.x, 100);
+
+ // Check that the viewBox baseVal type has not been changed.
+ assert_true(svgElement.viewBox.baseVal instanceof SVGRect);
+});
+
+test(function() {
+ var svg = newSVG();
+ for (var p of FIELDS) {
+ assert_equals(svg.viewBox.baseVal[p], 0, "baseVal." + p);
+ assert_equals(svg.viewBox.animVal[p], 0, "animVal." + p);
+ }
+}, "baseVal/animVal are zero rects when the viewBox attribute is unset");
+
+test(function() {
+ var svg = newSVG();
+ assert_equals(svg.viewBox.baseVal, svg.viewBox.baseVal, "baseVal identity");
+ assert_equals(svg.viewBox.animVal, svg.viewBox.animVal, "animVal identity");
+}, "baseVal/animVal return the same SVGRect across reads");
+
+test(function() {
+ var svg = newSVG();
+ svg.setAttribute("viewBox", "1 2 3 4");
+ var expected = [1, 2, 3, 4];
+ FIELDS.forEach(function(p, i) {
+ assert_equals(svg.viewBox.baseVal[p], expected[i], "baseVal." + p);
+ assert_equals(svg.viewBox.animVal[p], expected[i], "animVal." + p);
+ });
+}, "setAttribute('viewBox', ...) is reflected in baseVal/animVal");
+
+test(function() {
+ var svg = newSVG();
+ svg.setAttribute("viewBox", "1 2 3 4");
+ svg.removeAttribute("viewBox");
+ for (var p of FIELDS) {
+ assert_equals(svg.viewBox.baseVal[p], 0, "baseVal." + p);
+ assert_equals(svg.viewBox.animVal[p], 0, "animVal." + p);
+ }
+}, "removeAttribute('viewBox') resets baseVal/animVal to a zero rect");
+</script>