OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>SVGTextContentElement methods' parameters are correctly validated</title> |
3 <head> | |
4 <link rel="help" href="http://www.w3.org/TR/SVG2/text.html#InterfaceSVGTextConte
ntElement"> | 3 <link rel="help" href="http://www.w3.org/TR/SVG2/text.html#InterfaceSVGTextConte
ntElement"> |
5 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
6 </head> | 5 <script src="../../resources/testharnessreport.js"></script> |
7 <body> | |
8 <script> | 6 <script> |
9 description("Check that SVGTextContentElement methods' parameters are correctly
validated"); | 7 test(function() { |
| 8 var svgNS = "http://www.w3.org/2000/svg"; |
| 9 var svgRoot = document.createElementNS(svgNS, "svg"); |
| 10 document.documentElement.appendChild(svgRoot); |
10 | 11 |
11 var svgNS = "http://www.w3.org/2000/svg"; | 12 var svgText = document.createElementNS(svgNS, "text"); |
| 13 svgText.style.fontFamily = "Ahem"; |
| 14 svgText.style.fontSize = "20px"; |
| 15 svgText.appendChild(document.createTextNode("abcdefg")); |
| 16 svgRoot.appendChild(svgText); |
12 | 17 |
13 var svgRoot = document.createElementNS(svgNS, "svg"); | 18 var emptySvgText = document.createElementNS(svgNS, "text"); |
14 document.documentElement.appendChild(svgRoot); | 19 svgRoot.appendChild(emptySvgText); |
15 | 20 |
16 var svgText = document.createElementNS(svgNS, "text"); | 21 function assert_equals_to_SVGPoint(actualPoint, expectedPoint) |
17 svgText.style.fontFamily = "Ahem"; | 22 { |
18 svgText.style.fontSize = "20px"; | 23 assert_equals(actualPoint.x, expectedPoint.x); |
19 svgText.appendChild(document.createTextNode("abcdefg")); | 24 assert_equals(actualPoint.y, expectedPoint.y); |
20 svgRoot.appendChild(svgText); | 25 } |
21 | 26 |
22 var emptySvgText = document.createElementNS(svgNS, "text"); | 27 function assert_equals_to_SVGRect(actualRect, expectedRect) |
23 svgRoot.appendChild(emptySvgText); | 28 { |
| 29 assert_equals(actualRect.x, expectedRect.x); |
| 30 assert_equals(actualRect.y, expectedRect.y); |
| 31 assert_equals(actualRect.width, expectedRect.width); |
| 32 assert_equals(actualRect.height, expectedRect.height); |
| 33 } |
24 | 34 |
25 var actualTestPoint, expectedTestPoint; | 35 // Arguments should be mandatory. |
26 function shouldBeEqualToSVGPoint(actualPoint, expectedPoint) | 36 assert_throws(new TypeError(), function() { svgText.getSubStringLength(); }); |
27 { | 37 assert_throws(new TypeError(), function() { svgText.getSubStringLength(2); }); |
28 actualTestPoint = actualPoint; | 38 assert_throws(new TypeError(), function() { svgText.getStartPositionOfChar();
}); |
29 expectedTestPoint = expectedPoint; | 39 assert_throws(new TypeError(), function() { svgText.getEndPositionOfChar(); })
; |
30 shouldBe("actualTestPoint.x", "expectedTestPoint.x"); | 40 assert_throws(new TypeError(), function() { svgText.getExtentOfChar(); }); |
31 shouldBe("actualTestPoint.y", "expectedTestPoint.y"); | 41 assert_throws(new TypeError(), function() { svgText.getRotationOfChar(); }); |
32 } | 42 assert_throws(new TypeError(), function() { svgText.getCharNumAtPosition(); })
; |
| 43 assert_throws(new TypeError(), function() { svgText.getCharNumAtPosition('aStr
ing'); }); |
| 44 assert_throws(new TypeError(), function() { svgText.getCharNumAtPosition(svgTe
xt); }); |
| 45 assert_throws(new TypeError(), function() { svgText.selectSubString(); }); |
| 46 assert_throws(new TypeError(), function() { svgText.selectSubString(2); }); |
33 | 47 |
34 var actualTestRect, expectedTestRect; | 48 // Should throw an IndexSizeError if charnum is greater than or equal to the n
umber of characters at this node. |
35 function shouldBeEqualToSVGRect(actualRect, expectedRect) | 49 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(999, 2
); }); |
36 { | 50 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(99
9); }); |
37 actualTestRect = actualRect; | 51 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(999)
; }); |
38 expectedTestRect = expectedRect; | 52 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(999); }); |
39 shouldBe("actualTestRect.x", "expectedTestRect.x"); | 53 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(999); }
); |
40 shouldBe("actualTestRect.y", "expectedTestRect.y"); | 54 assert_throws("IndexSizeError", function() { svgText.selectSubString(999, 2);
}); |
41 shouldBe("actualTestRect.width", "expectedTestRect.width"); | |
42 shouldBe("actualTestRect.height", "expectedTestRect.height"); | |
43 } | |
44 | 55 |
45 // Arguments should be mandatory. | 56 // Test the equality part of the restriction. |
46 shouldThrow("svgText.getSubStringLength()", '"TypeError: Failed to execute \'get
SubStringLength\' on \'SVGTextContentElement\': 2 arguments required, but only 0
present."'); | 57 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(7, 2);
}); |
47 shouldThrow("svgText.getSubStringLength(2)", '"TypeError: Failed to execute \'ge
tSubStringLength\' on \'SVGTextContentElement\': 2 arguments required, but only
1 present."'); | 58 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(7)
; }); |
48 shouldThrow("svgText.getStartPositionOfChar()", '"TypeError: Failed to execute \
'getStartPositionOfChar\' on \'SVGTextContentElement\': 1 argument required, but
only 0 present."'); | 59 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(7);
}); |
49 shouldThrow("svgText.getEndPositionOfChar()", '"TypeError: Failed to execute \'g
etEndPositionOfChar\' on \'SVGTextContentElement\': 1 argument required, but onl
y 0 present."'); | 60 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(7); }); |
50 shouldThrow("svgText.getExtentOfChar()", '"TypeError: Failed to execute \'getExt
entOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 presen
t."'); | 61 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(7); }); |
51 shouldThrow("svgText.getRotationOfChar()", '"TypeError: Failed to execute \'getR
otationOfChar\' on \'SVGTextContentElement\': 1 argument required, but only 0 pr
esent."'); | 62 assert_throws("IndexSizeError", function() { svgText.selectSubString(7, 2); })
; |
52 shouldThrow("svgText.getCharNumAtPosition()", '"TypeError: Failed to execute \'g
etCharNumAtPosition\' on \'SVGTextContentElement\': 1 argument required, but onl
y 0 present."'); | |
53 shouldThrow("svgText.getCharNumAtPosition('aString')", '"TypeError: Failed to ex
ecute \'getCharNumAtPosition\' on \'SVGTextContentElement\': parameter 1 is not
of type \'SVGPoint\'."'); | |
54 shouldThrow("svgText.getCharNumAtPosition(svgText)", '"TypeError: Failed to exec
ute \'getCharNumAtPosition\' on \'SVGTextContentElement\': parameter 1 is not of
type \'SVGPoint\'."'); | |
55 shouldThrow("svgText.selectSubString()", '"TypeError: Failed to execute \'select
SubString\' on \'SVGTextContentElement\': 2 arguments required, but only 0 prese
nt."'); | |
56 shouldThrow("svgText.selectSubString(2)", '"TypeError: Failed to execute \'selec
tSubString\' on \'SVGTextContentElement\': 2 arguments required, but only 1 pres
ent."'); | |
57 | 63 |
58 // Should throw an IndexSizeError if charnum is greater than or equal to the num
ber of characters at this node. | 64 // Test the equality part of the restriction for the <number of chars> == 0 ca
se. |
59 shouldThrow("svgText.getSubStringLength(999, 2)", '"IndexSizeError: Failed to ex
ecute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided
(999) is greater than the maximum bound (7)."'); | 65 assert_throws("IndexSizeError", function() { emptySvgText.getSubStringLength(0
, 2); }); |
60 shouldThrow("svgText.getStartPositionOfChar(999)", '"IndexSizeError: Failed to e
xecute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum prov
ided (999) is greater than the maximum bound (7)."'); | 66 assert_throws("IndexSizeError", function() { emptySvgText.getStartPositionOfCh
ar(0); }); |
61 shouldThrow("svgText.getEndPositionOfChar(999)", '"IndexSizeError: Failed to exe
cute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided
(999) is greater than the maximum bound (7)."'); | 67 assert_throws("IndexSizeError", function() { emptySvgText.getEndPositionOfChar
(0); }); |
62 shouldThrow("svgText.getExtentOfChar(999)", '"IndexSizeError: Failed to execute
\'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (999) is
greater than the maximum bound (7)."'); | 68 assert_throws("IndexSizeError", function() { emptySvgText.getExtentOfChar(0);
}); |
63 shouldThrow("svgText.getRotationOfChar(999)", '"IndexSizeError: Failed to execut
e \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (999)
is greater than the maximum bound (7)."'); | 69 assert_throws("IndexSizeError", function() { emptySvgText.getRotationOfChar(0)
; }); |
64 shouldThrow("svgText.selectSubString(999, 2)", '"IndexSizeError: Failed to execu
te \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (999)
is greater than the maximum bound (7)."'); | 70 assert_throws("IndexSizeError", function() { emptySvgText.selectSubString(0, 2
); }); |
65 // Test the equality part of the restriction. | |
66 shouldThrow("svgText.getSubStringLength(7, 2)", '"IndexSizeError: Failed to exec
ute \'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 exe
cute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provid
ed (7) is greater than or equal to the maximum bound (7)."'); | |
68 shouldThrow("svgText.getEndPositionOfChar(7)", '"IndexSizeError: Failed to execu
te \'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 grea
ter 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 g
reater 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 provid
ed (0) is greater than or equal to the maximum bound (0)."'); | |
74 shouldThrow("emptySvgText.getStartPositionOfChar(0)", '"IndexSizeError: Failed t
o execute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum p
rovided (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 provi
ded (0) is greater than or equal to the maximum bound (0)."'); | |
76 shouldThrow("emptySvgText.getExtentOfChar(0)", '"IndexSizeError: Failed to execu
te \'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 exe
cute \'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 ex
ecute \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (0)
is greater than or equal to the maximum bound (0)."'); | |
79 | 71 |
80 // Should not throw if charnum is negative and wraps to a valid positive index (
-4294967294 wraps to 2). | 72 // 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.getSubStringLeng
th(2, 2)"); | 73 assert_equals(svgText.getSubStringLength(-4294967294, 2), svgText.getSubString
Length(2, 2)); |
82 shouldBeEqualToSVGPoint("svgText.getStartPositionOfChar(-4294967294)", "svgText.
getStartPositionOfChar(2)"); | 74 assert_equals_to_SVGPoint(svgText.getStartPositionOfChar(-4294967294), svgText
.getStartPositionOfChar(2)); |
83 shouldBeEqualToSVGPoint("svgText.getEndPositionOfChar(-4294967294)", "svgText.ge
tEndPositionOfChar(2)"); | 75 assert_equals_to_SVGPoint(svgText.getEndPositionOfChar(-4294967294), svgText.g
etEndPositionOfChar(2)); |
84 shouldBeEqualToSVGRect("svgText.getExtentOfChar(-4294967294)", "svgText.getExten
tOfChar(2)"); | 76 assert_equals_to_SVGRect(svgText.getExtentOfChar(-4294967294), svgText.getExte
ntOfChar(2)); |
85 shouldBe("svgText.getRotationOfChar(-4294967294)", "svgText.getRotationOfChar(2)
"); | 77 assert_equals(svgText.getRotationOfChar(-4294967294), svgText.getRotationOfCha
r(2)); |
86 shouldNotThrow("svgText.selectSubString(-4294967294, 2)"); | 78 svgText.selectSubString(-4294967294, 2); |
87 | 79 |
88 // Should throw an IndexSizeError if charnum is negative and wraps to an invalid
positive index. | 80 // Should throw an IndexSizeError if charnum is negative and wraps to an inval
id positive index. |
89 shouldThrow("svgText.getSubStringLength(-1, 2)", '"IndexSizeError: Failed to exe
cute \'getSubStringLength\' on \'SVGTextContentElement\': The charnum provided (
4294967295) is greater than the maximum bound (7)."'); | 81 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(-1, 2)
; }); |
90 shouldThrow("svgText.getStartPositionOfChar(-1)", '"IndexSizeError: Failed to ex
ecute \'getStartPositionOfChar\' on \'SVGTextContentElement\': The charnum provi
ded (4294967295) is greater than the maximum bound (7)."'); | 82 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(-1
); }); |
91 shouldThrow("svgText.getEndPositionOfChar(-1)", '"IndexSizeError: Failed to exec
ute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided
(4294967295) is greater than the maximum bound (7)."'); | 83 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(-1);
}); |
92 shouldThrow("svgText.getExtentOfChar(-1)", '"IndexSizeError: Failed to execute \
'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (429496729
5) is greater than the maximum bound (7)."'); | 84 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(-1); }); |
93 shouldThrow("svgText.getRotationOfChar(-1)", '"IndexSizeError: Failed to execute
\'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (42949
67295) is greater than the maximum bound (7)."'); | 85 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(-1); })
; |
94 shouldThrow("svgText.selectSubString(-1, 2)", '"IndexSizeError: Failed to execut
e \'selectSubString\' on \'SVGTextContentElement\': The charnum provided (429496
7295) is greater than the maximum bound (7)."'); | 86 assert_throws("IndexSizeError", function() { svgText.selectSubString(-1, 2); }
); |
95 | 87 |
96 // We should not throw if nchars is negative or too large. | 88 // We should not throw if nchars is negative or too large. |
97 // If nchars specifies more characters than are available, then the substring wi
ll consist of all characters | 89 // 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. | 90 // starting with charnum until the end of the list of characters. |
99 shouldBe("svgText.getSubStringLength(2, 999)", "svgText.getSubStringLength(2, 5)
"); | 91 assert_equals(svgText.getSubStringLength(2, 999), svgText.getSubStringLength(2
, 5)); |
100 shouldBe("svgText.getSubStringLength(2, -1)", "svgText.getSubStringLength(2, 5)"
); | 92 assert_equals(svgText.getSubStringLength(2, -1), svgText.getSubStringLength(2,
5)); |
101 shouldBe("svgText.getSubStringLength(2, 2)", "svgText.getSubStringLength(2, -429
4967294)"); | 93 assert_equals(svgText.getSubStringLength(2, 2), svgText.getSubStringLength(2,
-4294967294)); |
102 shouldNotThrow("svgText.selectSubString(2, 999)"); | 94 svgText.selectSubString(2, 999); |
103 shouldNotThrow("svgText.selectSubString(2, -1)"); | 95 svgText.selectSubString(2, -1); |
104 shouldNotThrow("svgText.selectSubString(2, -4294967294)"); | 96 svgText.selectSubString(2, -4294967294); |
105 | 97 |
| 98 // cleanup |
| 99 document.documentElement.removeChild(svgRoot); |
| 100 }); |
106 </script> | 101 </script> |
107 </body> | |
108 </html> | |
OLD | NEW |