OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE HTML> | |
2 <title>SVGLengthList, insertItemBefore()</title> | |
3 <script src="../../resources/testharness.js"></script> | |
4 <script src="../../resources/testharnessreport.js"></script> | |
5 <svg width="200" height="200"> | |
6 <text x="500 1000 1500" y="50"> ABC </text> | |
7 </svg> | |
8 <script> | |
9 test(function() { | |
10 // This is a test of the SVGLengthList::insertItemBefore() API. | |
fs
2016/09/17 17:42:36
Like in previous test.
Shanmuga Pandi
2016/09/19 07:40:04
Done.
| |
11 | |
12 var svg = document.querySelector("svg"); | |
13 var list = document.querySelector("text").x.baseVal; | |
14 | |
15 // Create three SVGLength objects, with values=50,100,150"); | |
16 var newLength1 = svg.createSVGLength(); | |
17 newLength1.value = 50; | |
18 assert_equals(newLength1.value, 50); | |
19 | |
20 var newLength2 = svg.createSVGLength(); | |
21 newLength2.value = 100; | |
22 assert_equals(newLength2.value, 100); | |
23 | |
24 var newLength3 = svg.createSVGLength(); | |
25 newLength3.value = 150; | |
26 assert_equals(newLength3.value, 150); | |
27 | |
28 assert_not_equals(newLength1.value, newLength2.value); | |
29 assert_not_equals(newLength2.value, newLength3.value); | |
30 assert_not_equals(newLength3.value, newLength1.value); | |
31 assert_equals(newLength1.value, newLength2.value - 50); | |
32 assert_equals(newLength2.value + 50, newLength3.value); | |
33 | |
34 // Check initial list state"); | |
35 assert_equals(list.numberOfItems, 3); | |
36 assert_equals(list.getItem(0).value, 500); | |
37 assert_equals(list.getItem(1).value, 1000); | |
38 assert_equals(list.getItem(2).value, 1500); | |
39 assert_throws("IndexSizeError", function() { list.getItem(3); }); | |
40 | |
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 // 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.numberOfItems, 4); | |
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 | |
51 // Storing getItem(0/1/2) in local variables. | |
fs
2016/09/17 17:42:37
0/1/2 -> 0/1/2/3
?
Shanmuga Pandi
2016/09/19 07:40:04
Done.
| |
52 var item0 = list.getItem(0); | |
53 var item1 = list.getItem(1); | |
54 var item2 = list.getItem(2); | |
55 var item3 = list.getItem(3); | |
56 | |
57 // 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". | |
59 assert_equals(list.insertItemBefore(newLength2, 0).value, newLength2.value); | |
60 assert_equals(list.numberOfItems, 5); | |
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 | |
68 // Assure that previously saved wrappers still show the old values. | |
69 assert_equals(item0.value, 500); | |
70 assert_equals(item1.value, 1000); | |
71 assert_equals(item2.value, 1500); | |
72 assert_equals(item3.value, 50); | |
73 | |
74 // Spec: The index of the item before which the new item is to be inserted. | |
75 | |
76 // Insert item 'newLength3' at position=2, between '500' and '1000'. | |
77 assert_equals(list.insertItemBefore(newLength3, 2).value, newLength3.value); | |
78 assert_equals(list.numberOfItems, 6); | |
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 | |
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. | |
88 // Otherwise, newItem itself is inserted into the list. | |
89 | |
90 // 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); | |
92 assert_equals(list.numberOfItems, 7); | |
93 assert_equals(list.getItem(0).value, 100); | |
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 | |
102 // 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); | |
104 assert_equals(list.numberOfItems, 8); | |
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 }); | |
115 </script> | |
OLD | NEW |