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