4 <link rel=
"help" href=
"http://www.w3.org/TR/SVG2/text.html#InterfaceSVGTextContentElement">
5 <script src=
"../../resources/js-test.js"></script>
9 description("Check that SVGTextContentElement methods' parameters are correctly validated");
11 var svgNS
= "http://www.w3.org/2000/svg";
13 var svgRoot
= document
.createElementNS(svgNS
, "svg");
14 document
.documentElement
.appendChild(svgRoot
);
16 var svgText
= document
.createElementNS(svgNS
, "text");
17 svgText
.style
.fontFamily
= "Ahem";
18 svgText
.style
.fontSize
= "20px";
19 svgText
.appendChild(document
.createTextNode("abcdefg"));
20 svgRoot
.appendChild(svgText
);
22 var emptySvgText
= document
.createElementNS(svgNS
, "text");
23 svgRoot
.appendChild(emptySvgText
);
25 var actualTestPoint
, expectedTestPoint
;
26 function shouldBeEqualToSVGPoint(actualPoint
, expectedPoint
)
28 actualTestPoint
= actualPoint
;
29 expectedTestPoint
= expectedPoint
;
30 shouldBe("actualTestPoint.x", "expectedTestPoint.x");
31 shouldBe("actualTestPoint.y", "expectedTestPoint.y");
34 var actualTestRect
, expectedTestRect
;
35 function shouldBeEqualToSVGRect(actualRect
, expectedRect
)
37 actualTestRect
= actualRect
;
38 expectedTestRect
= expectedRect
;
39 shouldBe("actualTestRect.x", "expectedTestRect.x");
40 shouldBe("actualTestRect.y", "expectedTestRect.y");
41 shouldBe("actualTestRect.width", "expectedTestRect.width");
42 shouldBe("actualTestRect.height", "expectedTestRect.height");
45 // Arguments should be mandatory.
46 shouldThrow("svgText.getSubStringLength()", '"TypeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': 2 arguments required, but only 0 present."');
47 shouldThrow("svgText.getSubStringLength(2)", '"TypeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': 2 arguments required, but only 1 present."');
48 shouldThrow("svgText.getStartPositionOfChar()", '"TypeError: Failed to execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 present."');
49 shouldThrow("svgText.getEndPositionOfChar()", '"TypeError: Failed to execute \'getEndPositionOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 present."');
50 shouldThrow("svgText.getExtentOfChar()", '"TypeError: Failed to execute \'getExtentOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 present."');
51 shouldThrow("svgText.getRotationOfChar()", '"TypeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 present."');
52 shouldThrow("svgText.getCharNumAtPosition()", '"TypeError: Failed to execute \'getCharNumAtPosition\' on \'SVGTextContentElement\': 1 argument required, but only 0 present."');
53 shouldThrow("svgText.getCharNumAtPosition('aString')", '"TypeError: Failed to execute \'getCharNumAtPosition\' on \'SVGTextContentElement\': parameter 1 is not of type \'SVGPoint\'."');
54 shouldThrow("svgText.getCharNumAtPosition(svgText)", '"TypeError: Failed to execute \'getCharNumAtPosition\' on \'SVGTextContentElement\': parameter 1 is not of type \'SVGPoint\'."');
55 shouldThrow("svgText.selectSubString()", '"TypeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': 2 arguments required, but only 0 present."');
56 shouldThrow("svgText.selectSubString(2)", '"TypeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': 2 arguments required, but only 1 present."');
58 // Should throw an IndexSizeError if charnum is greater than or equal to the number of characters at this node.
59 shouldThrow("svgText.getSubStringLength(999, 2)", '"IndexSizeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
60 shouldThrow("svgText.getStartPositionOfChar(999)", '"IndexSizeError: Failed to execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
61 shouldThrow("svgText.getEndPositionOfChar(999)", '"IndexSizeError: Failed to execute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
62 shouldThrow("svgText.getExtentOfChar(999)", '"IndexSizeError: Failed to execute \'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
63 shouldThrow("svgText.getRotationOfChar(999)", '"IndexSizeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
64 shouldThrow("svgText.selectSubString(999, 2)", '"IndexSizeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (999) is greater than the maximum bound (7)."');
65 // Test the equality part of the restriction.
66 shouldThrow("svgText.getSubStringLength(7, 2)", '"IndexSizeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
67 shouldThrow("svgText.getStartPositionOfChar(7)", '"IndexSizeError: Failed to execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
68 shouldThrow("svgText.getEndPositionOfChar(7)", '"IndexSizeError: Failed to execute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
69 shouldThrow("svgText.getExtentOfChar(7)", '"IndexSizeError: Failed to execute \'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
70 shouldThrow("svgText.getRotationOfChar(7)", '"IndexSizeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
71 shouldThrow("svgText.selectSubString(7, 2)", '"IndexSizeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (7) is greater than or equal to the maximum bound (7)."');
72 // Test the equality part of the restriction for the <number of chars> == 0 case.
73 shouldThrow("emptySvgText.getSubStringLength(0, 2)", '"IndexSizeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
74 shouldThrow("emptySvgText.getStartPositionOfChar(0)", '"IndexSizeError: Failed to execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
75 shouldThrow("emptySvgText.getEndPositionOfChar(0)", '"IndexSizeError: Failed to execute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
76 shouldThrow("emptySvgText.getExtentOfChar(0)", '"IndexSizeError: Failed to execute \'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
77 shouldThrow("emptySvgText.getRotationOfChar(0)", '"IndexSizeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
78 shouldThrow("emptySvgText.selectSubString(0, 2)", '"IndexSizeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (0) is greater than or equal to the maximum bound (0)."');
80 // Should not throw if charnum is negative and wraps to a valid positive index (-4294967294 wraps to 2).
81 shouldBe("svgText.getSubStringLength(-4294967294, 2)", "svgText.getSubStringLength(2, 2)");
82 shouldBeEqualToSVGPoint("svgText.getStartPositionOfChar(-4294967294)", "svgText.getStartPositionOfChar(2)");
83 shouldBeEqualToSVGPoint("svgText.getEndPositionOfChar(-4294967294)", "svgText.getEndPositionOfChar(2)");
84 shouldBeEqualToSVGRect("svgText.getExtentOfChar(-4294967294)", "svgText.getExtentOfChar(2)");
85 shouldBe("svgText.getRotationOfChar(-4294967294)", "svgText.getRotationOfChar(2)");
86 shouldNotThrow("svgText.selectSubString(-4294967294, 2)");
88 // Should throw an IndexSizeError if charnum is negative and wraps to an invalid positive index.
89 shouldThrow("svgText.getSubStringLength(-1, 2)", '"IndexSizeError: Failed to execute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
90 shouldThrow("svgText.getStartPositionOfChar(-1)", '"IndexSizeError: Failed to execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
91 shouldThrow("svgText.getEndPositionOfChar(-1)", '"IndexSizeError: Failed to execute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
92 shouldThrow("svgText.getExtentOfChar(-1)", '"IndexSizeError: Failed to execute \'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
93 shouldThrow("svgText.getRotationOfChar(-1)", '"IndexSizeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
94 shouldThrow("svgText.selectSubString(-1, 2)", '"IndexSizeError: Failed to execute \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."');
96 // We should not throw if nchars is negative or too large.
97 // If nchars specifies more characters than are available, then the substring will consist of all characters
98 // starting with charnum until the end of the list of characters.
99 shouldBe("svgText.getSubStringLength(2, 999)", "svgText.getSubStringLength(2, 5)");
100 shouldBe("svgText.getSubStringLength(2, -1)", "svgText.getSubStringLength(2, 5)");
101 shouldBe("svgText.getSubStringLength(2, 2)", "svgText.getSubStringLength(2, -4294967294)");
102 shouldNotThrow("svgText.selectSubString(2, 999)");
103 shouldNotThrow("svgText.selectSubString(2, -1)");
104 shouldNotThrow("svgText.selectSubString(2, -4294967294)");