OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <title>SVGLengthList, insertItemBefore()</title> | 2 <title>SVGLengthList, insertItemBefore()</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 x="500 1000 1500" y="50"> ABC </text> | 7 <text x="500 1000 1500" y="50"> ABC </text> |
7 </svg> | 8 </svg> |
8 <script> | 9 <script> |
9 test(function() { | 10 test(function() { |
10 // This is a test of the SVGLengthList.insertItemBefore() API. | 11 // This is a test of the SVGLengthList.insertItemBefore() API. |
11 | 12 |
12 var svg = document.querySelector("svg"); | 13 var svg = document.querySelector("svg"); |
13 var list = document.querySelector("text").x.baseVal; | 14 var list = document.querySelector("text").x.baseVal; |
14 | 15 |
(...skipping 19 matching lines...) Expand all Loading... |
34 // Check initial list state"); | 35 // Check initial list state"); |
35 assert_equals(list.numberOfItems, 3); | 36 assert_equals(list.numberOfItems, 3); |
36 assert_equals(list.getItem(0).value, 500); | 37 assert_equals(list.getItem(0).value, 500); |
37 assert_equals(list.getItem(1).value, 1000); | 38 assert_equals(list.getItem(1).value, 1000); |
38 assert_equals(list.getItem(2).value, 1500); | 39 assert_equals(list.getItem(2).value, 1500); |
39 assert_throws("IndexSizeError", function() { list.getItem(3); }); | 40 assert_throws("IndexSizeError", function() { list.getItem(3); }); |
40 | 41 |
41 // Spec: If the index is greater than or equal to numberOfItems, then the new
item is appended to the end of the list. | 42 // Spec: If the index is greater than or equal to numberOfItems, then the new
item is appended to the end of the list. |
42 // Insert item 'newLength1' at the end of the list, by using a large index. | 43 // Insert item 'newLength1' at the end of the list, by using a large index. |
43 assert_equals(list.insertItemBefore(newLength1, 1000).value, newLength1.value)
; | 44 assert_equals(list.insertItemBefore(newLength1, 1000).value, newLength1.value)
; |
44 assert_equals(list.numberOfItems, 4); | 45 assert_list(list, [500, 1000, 1500, 50]); |
45 assert_equals(list.getItem(0).value, 500); | |
46 assert_equals(list.getItem(1).value, 1000); | |
47 assert_equals(list.getItem(2).value, 1500); | |
48 assert_equals(list.getItem(3).value, 50); | |
49 assert_throws("IndexSizeError", function() { list.getItem(4); }); | |
50 | 46 |
51 // Storing getItem(0/1/2/3) in local variables. | 47 // Storing getItem(0/1/2/3) in local variables. |
52 var item0 = list.getItem(0); | 48 var item0 = list.getItem(0); |
53 var item1 = list.getItem(1); | 49 var item1 = list.getItem(1); |
54 var item2 = list.getItem(2); | 50 var item2 = list.getItem(2); |
55 var item3 = list.getItem(3); | 51 var item3 = list.getItem(3); |
56 | 52 |
57 // Spec: If the index is equal to 0, then the new item is inserted at the fron
t of the list. | 53 // Spec: If the index is equal to 0, then the new item is inserted at the fron
t of the list. |
58 // Insert item 'newLength2' at the front of the list, by using index=0". | 54 // Insert item 'newLength2' at the front of the list, by using index=0". |
59 assert_equals(list.insertItemBefore(newLength2, 0).value, newLength2.value); | 55 assert_equals(list.insertItemBefore(newLength2, 0).value, newLength2.value); |
60 assert_equals(list.numberOfItems, 5); | 56 assert_list(list, [100, 500, 1000, 1500, 50]); |
61 assert_equals(list.getItem(0).value, 100); | |
62 assert_equals(list.getItem(1).value, 500); | |
63 assert_equals(list.getItem(2).value, 1000); | |
64 assert_equals(list.getItem(3).value, 1500); | |
65 assert_equals(list.getItem(4).value, 50); | |
66 assert_throws("IndexSizeError", function() { list.getItem(5); }); | |
67 | 57 |
68 // Assure that previously saved wrappers still show the old values. | 58 // Assure that previously saved wrappers still show the old values. |
69 assert_equals(item0.value, 500); | 59 assert_equals(item0.value, 500); |
70 assert_equals(item1.value, 1000); | 60 assert_equals(item1.value, 1000); |
71 assert_equals(item2.value, 1500); | 61 assert_equals(item2.value, 1500); |
72 assert_equals(item3.value, 50); | 62 assert_equals(item3.value, 50); |
73 | 63 |
74 // Spec: The index of the item before which the new item is to be inserted. | 64 // Spec: The index of the item before which the new item is to be inserted. |
75 | 65 |
76 // Insert item 'newLength3' at position=2, between '500' and '1000'. | 66 // Insert item 'newLength3' at position=2, between '500' and '1000'. |
77 assert_equals(list.insertItemBefore(newLength3, 2).value, newLength3.value); | 67 assert_equals(list.insertItemBefore(newLength3, 2).value, newLength3.value); |
78 assert_equals(list.numberOfItems, 6); | 68 assert_list(list, [100, 500, 150, 1000, 1500, 50]); |
79 assert_equals(list.getItem(0).value, 100); | |
80 assert_equals(list.getItem(1).value, 500); | |
81 assert_equals(list.getItem(2).value, 150); | |
82 assert_equals(list.getItem(3).value, 1000); | |
83 assert_equals(list.getItem(4).value, 1500); | |
84 assert_equals(list.getItem(5).value, 50); | |
85 assert_throws("IndexSizeError", function() { list.getItem(6); }); | |
86 | 69 |
87 // Spec: If newItem is already in a list, then a new object is created with th
e same values as newItem and this item is inserted into the list. | 70 // Spec: If newItem is already in a list, then a new object is created with th
e same values as newItem and this item is inserted into the list. |
88 // Otherwise, newItem itself is inserted into the list. | 71 // Otherwise, newItem itself is inserted into the list. |
89 | 72 |
90 // Insert item 'newLength3' at position=1, between '100' and '500', should not
remove it from the old position=2 afterwards."); | 73 // Insert item 'newLength3' at position=1, between '100' and '500', should not
remove it from the old position=2 afterwards."); |
91 assert_equals(list.insertItemBefore(newLength3, 1).value, newLength3.value); | 74 assert_equals(list.insertItemBefore(newLength3, 1).value, newLength3.value); |
92 assert_equals(list.numberOfItems, 7); | 75 assert_equals(list.numberOfItems, 7); |
93 assert_equals(list.getItem(0).value, 100); | 76 assert_list(list, [100, 150, 500, 150, 1000, 1500, 50]); |
94 assert_equals(list.getItem(1).value, 150); | |
95 assert_equals(list.getItem(2).value, 500); | |
96 assert_equals(list.getItem(3).value, 150); | |
97 assert_equals(list.getItem(4).value, 1000); | |
98 assert_equals(list.getItem(5).value, 1500); | |
99 assert_equals(list.getItem(6).value, 50); | |
100 assert_throws("IndexSizeError", function() { list.getItem(7); }); | |
101 | 77 |
102 // Insert item 'newLength1' at position=0, before '100', should not remove it
from the old position=6 afterwards. | 78 // Insert item 'newLength1' at position=0, before '100', should not remove it
from the old position=6 afterwards. |
103 assert_equals(list.insertItemBefore(newLength1, 0).value, newLength1.value); | 79 assert_equals(list.insertItemBefore(newLength1, 0).value, newLength1.value); |
104 assert_equals(list.numberOfItems, 8); | 80 assert_list(list, [50, 100, 150, 500, 150, 1000, 1500, 50]); |
105 assert_equals(list.getItem(0).value, 50); | |
106 assert_equals(list.getItem(1).value, 100); | |
107 assert_equals(list.getItem(2).value, 150); | |
108 assert_equals(list.getItem(3).value, 500); | |
109 assert_equals(list.getItem(4).value, 150); | |
110 assert_equals(list.getItem(5).value, 1000); | |
111 assert_equals(list.getItem(6).value, 1500); | |
112 assert_equals(list.getItem(7).value, 50); | |
113 assert_throws("IndexSizeError", function() { list.getItem(8); }); | |
114 }); | 81 }); |
115 </script> | 82 </script> |
OLD | NEW |