OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <title>SVGLengthList, appendItem()</title> | 2 <title>SVGLengthList, appendItem()</title> |
3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/SVGLengthList-helper.js"></script> |
5 <svg width="200" height="200"> | 6 <svg width="200" height="200"> |
6 <text id="text1" x="500 50 100 900 1000" y="50">ABC</text> | 7 <text id="text1" x="500 50 100 900 1000" y="50">ABC</text> |
7 <text id="text2" x="50 100 1000" y="100">ABC</text> | 8 <text id="text2" x="50 100 1000" y="100">ABC</text> |
8 </svg> | 9 </svg> |
9 <script> | 10 <script> |
10 test(function() { | 11 test(function() { |
11 // This is a test of the SVGLengthList::appendItem() API. | 12 // This is a test of the SVGLengthList::appendItem() API. |
12 var svg = document.querySelector("svg"); | 13 var svg = document.querySelector("svg"); |
13 var list1 = document.getElementById("text1").x.baseVal; | 14 var list1 = document.getElementById("text1").x.baseVal; |
14 var list2 = document.getElementById("text2").x.baseVal; | 15 var list2 = document.getElementById("text2").x.baseVal; |
15 | 16 |
16 // Create a new SVGLength object, with value=150. | 17 // Create a new SVGLength object, with value=150. |
17 var newLength1 = svg.createSVGLength(); | 18 var newLength1 = svg.createSVGLength(); |
18 newLength1.value = 150; | 19 newLength1.value = 150; |
19 assert_equals(newLength1.value, 150); | 20 assert_equals(newLength1.value, 150); |
20 | 21 |
21 // Check initial list state of text1. | 22 // Check initial list state of text1. |
22 assert_equals(list1.numberOfItems, 5); | 23 assert_list(list1, [500, 50, 100, 900, 1000]); |
23 assert_equals(list1.getItem(0).value, 500); | |
24 assert_equals(list1.getItem(1).value, 50); | |
25 assert_equals(list1.getItem(2).value, 100); | |
26 assert_equals(list1.getItem(3).value, 900); | |
27 assert_equals(list1.getItem(4).value, 1000); | |
28 assert_throws("IndexSizeError", function() { list1.getItem(5); }); | |
29 | 24 |
30 // Check initial list state of text2. | 25 // Check initial list state of text2. |
31 assert_equals(list2.numberOfItems, 3); | 26 assert_list(list2, [50, 100, 1000]); |
32 assert_equals(list2.getItem(0).value, 50); | |
33 assert_equals(list2.getItem(1).value, 100); | |
34 assert_equals(list2.getItem(2).value, 1000); | |
35 assert_throws("IndexSizeError", function() { list2.getItem(3); }); | |
36 | 27 |
37 // Append fourth item x=900 to the text1 x list. | 28 // Append fourth item x=900 to the text1 x list. |
38 assert_equals(list1.appendItem(list1.getItem(3)).value, list1.getItem(5).value
); | 29 assert_equals(list1.appendItem(list1.getItem(3)).value, list1.getItem(5).value
); |
39 assert_equals(list1.numberOfItems, 6); | 30 assert_list(list1, [500, 50, 100, 900, 1000, 900]); |
40 assert_equals(list1.getItem(0).value, 500); | |
41 assert_equals(list1.getItem(1).value, 50); | |
42 assert_equals(list1.getItem(2).value, 100); | |
43 assert_equals(list1.getItem(3).value, 900); | |
44 assert_equals(list1.getItem(4).value, 1000); | |
45 assert_equals(list1.getItem(5).value, 900); | |
46 assert_throws("IndexSizeError", function() { list1.getItem(6); }); | |
47 | 31 |
48 // Append first item x=500 to the text1 x list. | 32 // Append first item x=500 to the text1 x list. |
49 assert_equals(list1.appendItem(list1.getItem(0)).value, list1.getItem(6).value
); | 33 assert_equals(list1.appendItem(list1.getItem(0)).value, list1.getItem(6).value
); |
50 assert_equals(list1.numberOfItems, 7); | 34 assert_list(list1, [500, 50, 100, 900, 1000, 900, 500]); |
51 assert_equals(list1.getItem(0).value, 500); | |
52 assert_equals(list1.getItem(1).value, 50); | |
53 assert_equals(list1.getItem(2).value, 100); | |
54 assert_equals(list1.getItem(3).value, 900); | |
55 assert_equals(list1.getItem(4).value, 1000); | |
56 assert_equals(list1.getItem(5).value, 900); | |
57 assert_equals(list1.getItem(6).value, 500); | |
58 assert_throws("IndexSizeError", function() { list1.getItem(7); }); | |
59 | 35 |
60 // Append 'newLength1' to the text1 x list. | 36 // Append 'newLength1' to the text1 x list. |
61 assert_equals(list1.appendItem(newLength1).value, list1.getItem(7).value); | 37 assert_equals(list1.appendItem(newLength1).value, list1.getItem(7).value); |
62 assert_equals(list1.numberOfItems, 8); | 38 assert_list(list1, [500, 50, 100, 900, 1000, 900, 500, 150]); |
63 assert_equals(list1.getItem(0).value, 500); | |
64 assert_equals(list1.getItem(1).value, 50); | |
65 assert_equals(list1.getItem(2).value, 100); | |
66 assert_equals(list1.getItem(3).value, 900); | |
67 assert_equals(list1.getItem(4).value, 1000); | |
68 assert_equals(list1.getItem(5).value, 900); | |
69 assert_equals(list1.getItem(6).value, 500); | |
70 assert_equals(list1.getItem(7).value, 150); | |
71 assert_throws("IndexSizeError", function() { list1.getItem(8); }); | |
72 | 39 |
73 // Append third and fourth item of the text1 x list to the text2 x list. | 40 // Append third and fourth item of the text1 x list to the text2 x list. |
74 assert_equals(list2.appendItem(list1.getItem(2)).value, 100); | 41 assert_equals(list2.appendItem(list1.getItem(2)).value, 100); |
75 assert_equals(list2.appendItem(list1.getItem(3)).value, 900); | 42 assert_equals(list2.appendItem(list1.getItem(3)).value, 900); |
76 assert_equals(list1.numberOfItems, 8); | 43 assert_list(list1, [500, 50, 100, 900, 1000, 900, 500, 150]); |
77 assert_equals(list1.getItem(0).value, 500); | 44 assert_list(list2, [50, 100, 1000, 100, 900]); |
78 assert_equals(list1.getItem(1).value, 50); | |
79 assert_equals(list1.getItem(2).value, 100); | |
80 assert_equals(list1.getItem(3).value, 900); | |
81 assert_equals(list1.getItem(4).value, 1000); | |
82 assert_equals(list1.getItem(5).value, 900); | |
83 assert_equals(list1.getItem(6).value, 500); | |
84 assert_equals(list1.getItem(7).value, 150); | |
85 assert_throws("IndexSizeError", function() { list1.getItem(8); }); | |
86 assert_equals(list2.numberOfItems, 5); | |
87 assert_equals(list2.getItem(0).value, 50); | |
88 assert_equals(list2.getItem(1).value, 100); | |
89 assert_equals(list2.getItem(2).value, 1000); | |
90 assert_equals(list2.getItem(3).value, 100); | |
91 assert_equals(list2.getItem(4).value, 900); | |
92 assert_throws("IndexSizeError", function() { list2.getItem(5); }); | |
93 | 45 |
94 var newLength2 = svg.createSVGLength(); | 46 var newLength2 = svg.createSVGLength(); |
95 newLength2.value = 150; | 47 newLength2.value = 150; |
96 assert_equals(newLength2.value, 150); | 48 assert_equals(newLength2.value, 150); |
97 list1.clear(); | 49 list1.clear(); |
98 | 50 |
99 // Shuffle around items in text1 and text2 list using appendItem, to get x=50,
100,150,... in both lists. | 51 // Shuffle around items in text1 and text2 list using appendItem, to get x=50,
100,150,... in both lists. |
100 assert_equals(list1.appendItem(list2.getItem(0)).value, 50); | 52 assert_equals(list1.appendItem(list2.getItem(0)).value, 50); |
101 assert_equals(list1.appendItem(list2.getItem(1)).value, 100); | 53 assert_equals(list1.appendItem(list2.getItem(1)).value, 100); |
102 assert_equals(list1.appendItem(newLength2).value, 150); | 54 assert_equals(list1.appendItem(newLength2).value, 150); |
103 list2.clear(); | 55 list2.clear(); |
104 assert_equals(list2.appendItem(list1.getItem(0)).value, 50); | 56 assert_equals(list2.appendItem(list1.getItem(0)).value, 50); |
105 assert_equals(list2.appendItem(list1.getItem(1)).value, 100); | 57 assert_equals(list2.appendItem(list1.getItem(1)).value, 100); |
106 assert_equals(list2.appendItem(list1.getItem(2)).value, 150); | 58 assert_equals(list2.appendItem(list1.getItem(2)).value, 150); |
107 assert_equals(list1.numberOfItems, 3); | 59 assert_list(list1, [50, 100, 150]); |
108 assert_equals(list1.getItem(0).value, 50); | 60 assert_list(list2, [50, 100, 150]); |
109 assert_equals(list1.getItem(1).value, 100); | |
110 assert_equals(list1.getItem(2).value, 150); | |
111 assert_throws("IndexSizeError", function() { list1.getItem(4); }); | |
112 assert_equals(list2.numberOfItems, 3); | |
113 assert_equals(list2.getItem(0).value, 50); | |
114 assert_equals(list2.getItem(1).value, 100); | |
115 assert_equals(list2.getItem(2).value, 150); | |
116 assert_throws("IndexSizeError", function() { list2.getItem(6); }); | |
117 }); | 61 }); |
118 </script> | 62 </script> |
OLD | NEW |