Skip to content

Commit 3032c66

Browse files
Fredrik Söderquistchromium-wpt-export-bot
authored andcommitted
Move/migrate SVGRect and SVGPoint tests to WPT
Bug: 40779000 Change-Id: If95877c56ddfd4bc1ec34c13e53a99281452ec30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6983405 Reviewed-by: Philip Rogers <[email protected]> Auto-Submit: Fredrik Söderquist <[email protected]> Commit-Queue: Philip Rogers <[email protected]> Cr-Commit-Position: refs/heads/main@{#1520548}
1 parent fe7656c commit 3032c66

File tree

2 files changed

+90
-9
lines changed

2 files changed

+90
-9
lines changed

svg/types/scripted/SVGPoint.html

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,63 @@
44
<script src="/resources/testharnessreport.js"></script>
55
<script>
66
test(function() {
7-
let svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
8-
let point = svgElement.createSVGPoint();
7+
const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
8+
const point = svgElement.createSVGPoint();
99

1010
// Check initial point values.
1111
assert_equals(point.x, 0);
1212
assert_equals(point.y, 0);
1313

14-
point.y = 2;
15-
16-
// Check setting valid arguments.
17-
assert_equals(point.x, 0);
18-
assert_equals(point.y, 2);
14+
// Check assigning points.
15+
point.x = 100;
16+
assert_equals(point.x, 100);
17+
point.y = 200;
18+
assert_equals(point.y, 200);
19+
point.y = null;
20+
assert_equals(point.y, 0);
21+
point.y = 200;
1922

2023
// Check setting invalid arguments.
24+
assert_throws_js(TypeError, function() { point.x = point; });
25+
assert_equals(point.x, 100);
2126
assert_throws_js(TypeError, function() { point.x = NaN; });
27+
assert_equals(point.x, 100);
2228
assert_throws_js(TypeError, function() { point.x = Infinity; });
23-
assert_equals(point.x, 0);
24-
});
29+
assert_equals(point.x, 100);
30+
31+
assert_throws_js(TypeError, function() { point.y = point; });
32+
assert_equals(point.y, 200);
33+
assert_throws_js(TypeError, function() { point.y = NaN; });
34+
assert_equals(point.y, 200);
35+
assert_throws_js(TypeError, function() { point.y = Infinity; });
36+
assert_equals(point.y, 200);
37+
}, `${document.title}, 'x' and 'y' attributes`);
38+
39+
test(function() {
40+
const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
41+
const point = svgElement.createSVGPoint();
42+
43+
point.x = -50;
44+
point.y = 100;
45+
46+
// Multiply with -1,0,0,2,10,10 matrix, should flip x coordinate, multiply y
47+
// by two and translate each coordinate by 10.
48+
const ctm = svgElement.createSVGMatrix();
49+
ctm.a = -1;
50+
ctm.d = 2;
51+
ctm.e = 10;
52+
ctm.f = 10;
53+
newPoint = point.matrixTransform(ctm);
54+
assert_true(newPoint instanceof SVGPoint);
55+
assert_equals(newPoint.x, 60);
56+
assert_equals(newPoint.y, 210);
57+
58+
// Check invalid arguments for 'matrixTransform'.
59+
assert_throws_js(TypeError, function() { point.matrixTransform(); });
60+
assert_throws_js(TypeError, function() { point.matrixTransform(-1); });
61+
assert_throws_js(TypeError, function() { point.matrixTransform(5); });
62+
assert_throws_js(TypeError, function() { point.matrixTransform('aString'); });
63+
assert_throws_js(TypeError, function() { point.matrixTransform(point); });
64+
assert_throws_js(TypeError, function() { point.matrixTransform(svgElement); });
65+
}, `${document.title}, matrixTransform()`);
2566
</script>

svg/types/scripted/SVGRect.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<title>SVGRect interface</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
setup(() => {
7+
window.svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
8+
});
9+
10+
test(t => {
11+
const rect = svgElement.createSVGRect();
12+
assert_equals(rect.x, 0, 'initial x');
13+
assert_equals(rect.y, 0, 'initial y');
14+
assert_equals(rect.width, 0, 'initial width');
15+
assert_equals(rect.height, 0, 'initial height');
16+
}, `${document.title}, initial values`);
17+
18+
test(t => {
19+
const rect = svgElement.createSVGRect();
20+
rect.x = 100;
21+
rect.y = 200;
22+
rect.width = 300;
23+
rect.height = 400;
24+
assert_equals(rect.x, 100);
25+
assert_equals(rect.y, 200);
26+
assert_equals(rect.width, 300);
27+
assert_equals(rect.height, 400);
28+
29+
rect.y = null;
30+
assert_equals(rect.y, 0);
31+
}, `${document.title}, assignment, numeric values`);
32+
33+
test(t => {
34+
const rect = svgElement.createSVGRect();
35+
assert_throws_js(TypeError, () => { rect.x = rect; });
36+
assert_throws_js(TypeError, () => { rect.y = 'aString'; });
37+
assert_throws_js(TypeError, () => { rect.width = svgElement; });
38+
assert_throws_js(TypeError, () => { rect.height = NaN; });
39+
}, `${document.title}, assignment, invalid values`);
40+
</script>

0 commit comments

Comments
 (0)