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"; | |
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; | 23 actualTestPoint = actualPoint; |
29 expectedTestPoint = expectedPoint; | 24 expectedTestPoint = expectedPoint; |
fs
2016/08/23 08:30:11
These should go too. Use the ones without *Test*.
Shanmuga Pandi
2016/08/23 09:22:08
Done.
| |
30 shouldBe("actualTestPoint.x", "expectedTestPoint.x"); | 25 assert_equals(actualTestPoint.x, expectedTestPoint.x); |
31 shouldBe("actualTestPoint.y", "expectedTestPoint.y"); | 26 assert_equals(actualTestPoint.y, expectedTestPoint.y); |
32 } | 27 } |
33 | 28 |
34 var actualTestRect, expectedTestRect; | 29 function assert_equals_to_SVGRect(actualRect, expectedRect) |
35 function shouldBeEqualToSVGRect(actualRect, expectedRect) | 30 { |
36 { | |
37 actualTestRect = actualRect; | 31 actualTestRect = actualRect; |
38 expectedTestRect = expectedRect; | 32 expectedTestRect = expectedRect; |
fs
2016/08/23 08:30:11
Ditto.
Shanmuga Pandi
2016/08/23 09:22:08
Done.
| |
39 shouldBe("actualTestRect.x", "expectedTestRect.x"); | 33 assert_equals(actualTestRect.x, expectedTestRect.x); |
40 shouldBe("actualTestRect.y", "expectedTestRect.y"); | 34 assert_equals(actualTestRect.y, expectedTestRect.y); |
41 shouldBe("actualTestRect.width", "expectedTestRect.width"); | 35 assert_equals(actualTestRect.width, expectedTestRect.width); |
42 shouldBe("actualTestRect.height", "expectedTestRect.height"); | 36 assert_equals(actualTestRect.height, expectedTestRect.height); |
43 } | 37 } |
44 | 38 |
45 // Arguments should be mandatory. | 39 // Arguments should be mandatory. |
46 shouldThrow("svgText.getSubStringLength()", '"TypeError: Failed to execute \'get SubStringLength\' on \'SVGTextContentElement\': 2 arguments required, but only 0 present."'); | 40 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."'); | 41 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."'); | 42 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."'); | 43 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."'); | 44 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."'); | 45 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."'); | 46 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\'."'); | 47 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\'."'); | 48 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."'); | 49 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."'); | 50 assert_throws(new TypeError(), function() { svgText.selectSubString(2); }); |
57 | 51 |
58 // Should throw an IndexSizeError if charnum is greater than or equal to the num ber of characters at this node. | 52 // 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)."'); | 53 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)."'); | 54 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)."'); | 55 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)."'); | 56 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)."'); | 57 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)."'); | 58 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 | 59 |
80 // Should not throw if charnum is negative and wraps to a valid positive index ( -4294967294 wraps to 2). | 60 // Test the equality part of the restriction. |
81 shouldBe("svgText.getSubStringLength(-4294967294, 2)", "svgText.getSubStringLeng th(2, 2)"); | 61 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(7, 2); }); |
82 shouldBeEqualToSVGPoint("svgText.getStartPositionOfChar(-4294967294)", "svgText. getStartPositionOfChar(2)"); | 62 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(7) ; }); |
83 shouldBeEqualToSVGPoint("svgText.getEndPositionOfChar(-4294967294)", "svgText.ge tEndPositionOfChar(2)"); | 63 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(7); }); |
84 shouldBeEqualToSVGRect("svgText.getExtentOfChar(-4294967294)", "svgText.getExten tOfChar(2)"); | 64 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(7); }); |
85 shouldBe("svgText.getRotationOfChar(-4294967294)", "svgText.getRotationOfChar(2) "); | 65 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(7); }); |
86 shouldNotThrow("svgText.selectSubString(-4294967294, 2)"); | 66 assert_throws("IndexSizeError", function() { svgText.selectSubString(7, 2); }) ; |
87 | 67 |
88 // Should throw an IndexSizeError if charnum is negative and wraps to an invalid positive index. | 68 // 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)."'); | 69 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)."'); | 70 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)."'); | 71 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)."'); | 72 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)."'); | 73 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)."'); | 74 assert_throws("IndexSizeError", function() { emptySvgText.selectSubString(0, 2 ); }); |
95 | 75 |
96 // We should not throw if nchars is negative or too large. | 76 // 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 | 77 assert_equals(svgText.getSubStringLength(-4294967294, 2), svgText.getSubString Length(2, 2)); |
98 // starting with charnum until the end of the list of characters. | 78 assert_equals_to_SVGPoint(svgText.getStartPositionOfChar(-4294967294), svgText .getStartPositionOfChar(2)); |
99 shouldBe("svgText.getSubStringLength(2, 999)", "svgText.getSubStringLength(2, 5) "); | 79 assert_equals_to_SVGPoint(svgText.getEndPositionOfChar(-4294967294), svgText.g etEndPositionOfChar(2)); |
100 shouldBe("svgText.getSubStringLength(2, -1)", "svgText.getSubStringLength(2, 5)" ); | 80 assert_equals_to_SVGRect(svgText.getExtentOfChar(-4294967294), svgText.getExte ntOfChar(2)); |
101 shouldBe("svgText.getSubStringLength(2, 2)", "svgText.getSubStringLength(2, -429 4967294)"); | 81 assert_equals(svgText.getRotationOfChar(-4294967294), svgText.getRotationOfCha r(2)); |
102 shouldNotThrow("svgText.selectSubString(2, 999)"); | 82 svgText.selectSubString(-4294967294, 2); |
103 shouldNotThrow("svgText.selectSubString(2, -1)"); | |
104 shouldNotThrow("svgText.selectSubString(2, -4294967294)"); | |
105 | 83 |
84 // Should throw an IndexSizeError if charnum is negative and wraps to an inval id positive index. | |
85 assert_throws("IndexSizeError", function() { svgText.getSubStringLength(-1, 2) ; }); | |
86 assert_throws("IndexSizeError", function() { svgText.getStartPositionOfChar(-1 ); }); | |
87 assert_throws("IndexSizeError", function() { svgText.getEndPositionOfChar(-1); }); | |
88 assert_throws("IndexSizeError", function() { svgText.getExtentOfChar(-1); }); | |
89 assert_throws("IndexSizeError", function() { svgText.getRotationOfChar(-1); }) ; | |
90 assert_throws("IndexSizeError", function() { svgText.selectSubString(-1, 2); } ); | |
91 | |
92 // We should not throw if nchars is negative or too large. | |
93 // If nchars specifies more characters than are available, then the substring will consist of all characters | |
94 // starting with charnum until the end of the list of characters. | |
95 assert_equals(svgText.getSubStringLength(2, 999), svgText.getSubStringLength(2 , 5)); | |
96 assert_equals(svgText.getSubStringLength(2, -1), svgText.getSubStringLength(2, 5)); | |
97 assert_equals(svgText.getSubStringLength(2, 2), svgText.getSubStringLength(2, -4294967294)); | |
98 svgText.selectSubString(2, 999); | |
99 svgText.selectSubString(2, -1); | |
100 svgText.selectSubString(2, -4294967294); | |
101 | |
102 // cleanup | |
103 document.documentElement.removeChild(svgRoot); | |
fs
2016/08/23 08:30:11
Just leave the elements in the tree.
Shanmuga Pandi
2016/08/23 08:57:33
When I leave the element within tree, even with "h
| |
104 }); | |
106 </script> | 105 </script> |
107 </body> | |
108 </html> | |
OLD | NEW |