OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Check that SVGTextContentElement methods' parameters are correctly valida ted</title> |
fs
2016/08/22 14:10:05
Drop the "Check that" for a slightly better testna
Shanmuga Pandi
2016/08/23 07:11:38
Done.
| |
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.style.visibility = "hidden"; | |
fs
2016/08/22 14:10:05
No need to add this. Also, the SVG content could b
Shanmuga Pandi
2016/08/23 07:11:38
Done.
| |
16 svgText.appendChild(document.createTextNode("abcdefg")); | |
17 svgRoot.appendChild(svgText); | |
12 | 18 |
13 var svgRoot = document.createElementNS(svgNS, "svg"); | 19 var emptySvgText = document.createElementNS(svgNS, "text"); |
14 document.documentElement.appendChild(svgRoot); | 20 svgRoot.appendChild(emptySvgText); |
15 | 21 |
16 var svgText = document.createElementNS(svgNS, "text"); | 22 var actualTestPoint, expectedTestPoint; |
fs
2016/08/22 14:10:05
You don't need these - just reference actualPoint
Shanmuga Pandi
2016/08/23 07:11:38
Done.
| |
17 svgText.style.fontFamily = "Ahem"; | 23 function assert_equals_to_SVGPoint(actualPoint, expectedPoint) |
18 svgText.style.fontSize = "20px"; | 24 { |
19 svgText.appendChild(document.createTextNode("abcdefg")); | |
20 svgRoot.appendChild(svgText); | |
21 | |
22 var emptySvgText = document.createElementNS(svgNS, "text"); | |
23 svgRoot.appendChild(emptySvgText); | |
24 | |
25 var actualTestPoint, expectedTestPoint; | |
26 function shouldBeEqualToSVGPoint(actualPoint, expectedPoint) | |
27 { | |
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; |
fs
2016/08/22 14:10:05
Ditto.
Shanmuga Pandi
2016/08/23 07:11:38
Done.
| |
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('aStr ing'); }); |
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(svgTe xt); }); |
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 n umber 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(99 9); }); |
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); }); |
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 | 62 |
80 // Should not throw if charnum is negative and wraps to a valid positive index ( -4294967294 wraps to 2). | 63 // Test the equality part of the restriction. |
81 shouldBe("svgText.getSubStringLength(-4294967294, 2)", "svgText.getSubStringLeng th(2, 2)"); | 64 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(7, 2); }); |
82 shouldBeEqualToSVGPoint("svgText.getStartPositionOfChar(-4294967294)", "svgText. getStartPositionOfChar(2)"); | 65 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(7) ; }); |
83 shouldBeEqualToSVGPoint("svgText.getEndPositionOfChar(-4294967294)", "svgText.ge tEndPositionOfChar(2)"); | 66 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(7); }); |
84 shouldBeEqualToSVGRect("svgText.getExtentOfChar(-4294967294)", "svgText.getExten tOfChar(2)"); | 67 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(7); }); |
85 shouldBe("svgText.getRotationOfChar(-4294967294)", "svgText.getRotationOfChar(2) "); | 68 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(7); }); |
86 shouldNotThrow("svgText.selectSubString(-4294967294, 2)"); | 69 assert_throws("IndexSizeError", function() { svgText.selectSubString(7, 2); }) ; |
87 | 70 |
88 // Should throw an IndexSizeError if charnum is negative and wraps to an invalid positive index. | 71 // Test the equality part of the restriction for the <number of chars> == 0 ca se. |
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)."'); | 72 assert_throws("IndexSizeError", function() { emptySvgText.getSubStringLength(0 , 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)."'); | 73 assert_throws("IndexSizeError", function() { emptySvgText.getStartPositionOfCh ar(0); }); |
91 shouldThrow("svgText.getEndPositionOfChar(-1)", '"IndexSizeError: Failed to exec ute \'getEndPositionOfChar\' on \'SVGTextContentElement\': The charnum provided (4294967295) is greater than the maximum bound (7)."'); | 74 assert_throws("IndexSizeError", function() { emptySvgText.getEndPositionOfChar (0); }); |
92 shouldThrow("svgText.getExtentOfChar(-1)", '"IndexSizeError: Failed to execute \ 'getExtentOfChar\' on \'SVGTextContentElement\': The charnum provided (429496729 5) is greater than the maximum bound (7)."'); | 75 assert_throws("IndexSizeError", function() { emptySvgText.getExtentOfChar(0); }); |
93 shouldThrow("svgText.getRotationOfChar(-1)", '"IndexSizeError: Failed to execute \'getRotationOfChar\' on \'SVGTextContentElement\': The charnum provided (42949 67295) is greater than the maximum bound (7)."'); | 76 assert_throws("IndexSizeError", function() { emptySvgText.getRotationOfChar(0) ; }); |
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)."'); | 77 assert_throws("IndexSizeError", function() { emptySvgText.selectSubString(0, 2 ); }); |
95 | 78 |
96 // We should not throw if nchars is negative or too large. | 79 // Should not throw if charnum is negative and wraps to a valid positive index (-4294967294 wraps to 2). |
97 // If nchars specifies more characters than are available, then the substring wi ll consist of all characters | 80 assert_equals(svgText.getSubStringLength(-4294967294, 2), svgText.getSubString Length(2, 2)); |
98 // starting with charnum until the end of the list of characters. | 81 assert_equals_to_SVGPoint(svgText.getStartPositionOfChar(-4294967294), svgText .getStartPositionOfChar(2)); |
99 shouldBe("svgText.getSubStringLength(2, 999)", "svgText.getSubStringLength(2, 5) "); | 82 assert_equals_to_SVGPoint(svgText.getEndPositionOfChar(-4294967294), svgText.g etEndPositionOfChar(2)); |
100 shouldBe("svgText.getSubStringLength(2, -1)", "svgText.getSubStringLength(2, 5)" ); | 83 assert_equals_to_SVGRect(svgText.getExtentOfChar(-4294967294), svgText.getExte ntOfChar(2)); |
101 shouldBe("svgText.getSubStringLength(2, 2)", "svgText.getSubStringLength(2, -429 4967294)"); | 84 assert_equals(svgText.getRotationOfChar(-4294967294), svgText.getRotationOfCha r(2)); |
102 shouldNotThrow("svgText.selectSubString(2, 999)"); | 85 svgText.selectSubString(-4294967294, 2); |
103 shouldNotThrow("svgText.selectSubString(2, -1)"); | |
104 shouldNotThrow("svgText.selectSubString(2, -4294967294)"); | |
105 | 86 |
87 // Should throw an IndexSizeError if charnum is negative and wraps to an inval id positive index. | |
88 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(-1, 2) ; }); | |
89 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(-1 ); }); | |
90 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(-1); }); | |
91 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(-1); }); | |
92 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(-1); }) ; | |
93 assert_throws("IndexSizeError", function() { svgText.selectSubString(-1, 2); } ); | |
94 | |
95 // We should not throw if nchars is negative or too large. | |
96 // If nchars specifies more characters than are available, then the substring will consist of all characters | |
97 // starting with charnum until the end of the list of characters. | |
98 assert_equals(svgText.getSubStringLength(2, 999), svgText.getSubStringLength(2 , 5)); | |
99 assert_equals(svgText.getSubStringLength(2, -1), svgText.getSubStringLength(2, 5)); | |
100 assert_equals(svgText.getSubStringLength(2, 2), svgText.getSubStringLength(2, -4294967294)); | |
101 svgText.selectSubString(2, 999); | |
102 svgText.selectSubString(2, -1); | |
103 svgText.selectSubString(2, -4294967294); | |
104 }); | |
106 </script> | 105 </script> |
107 </body> | |
108 </html> | |
OLD | NEW |