OLD | NEW |
| (Empty) |
1 <html xmlns="http://www.w3.org/1999/xhtml"> | |
2 <head> | |
3 <script>window.enablePixelTesting = true;</script> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="200" height="200"> | |
8 <text id="text1" x="500 1000 1500" y="50"> ABC </text> | |
9 <text id="reference" x="50 100 150" y="100"> ABC </text> | |
10 </svg> | |
11 | |
12 <p id="description"></p> | |
13 <div id="console"></div> | |
14 <script type="text/javascript"> | |
15 <![CDATA[ | |
16 description("This is a test of the SVGLengthList::insertItemBefore() API."); | |
17 | |
18 var svg = document.getElementById("svg"); | |
19 var text1 = document.getElementById("text1"); | |
20 | |
21 debug(""); | |
22 debug("Create three SVGLength objects, with values=50,100,150"); | |
23 var newLength1 = svg.createSVGLength(); | |
24 newLength1.value = 50; | |
25 shouldBe("newLength1.value", "50"); | |
26 | |
27 var newLength2 = svg.createSVGLength(); | |
28 newLength2.value = 100; | |
29 shouldBe("newLength2.value", "100"); | |
30 | |
31 var newLength3 = svg.createSVGLength(); | |
32 newLength3.value = 150; | |
33 shouldBe("newLength3.value", "150"); | |
34 | |
35 shouldBeTrue("newLength1 != newLength2"); | |
36 shouldBeTrue("newLength2 != newLength3"); | |
37 shouldBeTrue("newLength3 != newLength1"); | |
38 shouldBeTrue("newLength1.value == newLength2.value - 50"); | |
39 shouldBeTrue("newLength2.value + 50 == newLength3.value"); | |
40 | |
41 debug(""); | |
42 debug("Check initial list state"); | |
43 shouldBe("text1.x.baseVal.numberOfItems", "3"); | |
44 shouldBe("text1.x.baseVal.getItem(0).value", "500"); | |
45 shouldBe("text1.x.baseVal.getItem(1).value", "1000"); | |
46 shouldBe("text1.x.baseVal.getItem(2).value", "1500"); | |
47 shouldThrow("text1.x.baseVal.getItem(3)"); | |
48 | |
49 // Spec: If the index is greater than or equal to numberOfItems, then the ne
w item is appended to the end of the list. | |
50 debug(""); | |
51 debug("Insert item 'newLength1' at the end of the list, by using a large ind
ex"); | |
52 shouldBe("text1.x.baseVal.insertItemBefore(newLength1, 1000)", "newLength1")
; | |
53 shouldBe("text1.x.baseVal.numberOfItems", "4"); | |
54 shouldBe("text1.x.baseVal.getItem(0).value", "500"); | |
55 shouldBe("text1.x.baseVal.getItem(1).value", "1000"); | |
56 shouldBe("text1.x.baseVal.getItem(2).value", "1500"); | |
57 shouldBe("text1.x.baseVal.getItem(3).value", "50"); | |
58 shouldThrow("text1.x.baseVal.getItem(4)"); | |
59 | |
60 debug(""); | |
61 debug("Storing getItem(0/1/2) in local variables"); | |
62 var item0 = text1.x.baseVal.getItem(0); | |
63 var item1 = text1.x.baseVal.getItem(1); | |
64 var item2 = text1.x.baseVal.getItem(2); | |
65 var item3 = text1.x.baseVal.getItem(3); | |
66 | |
67 // Spec: If the index is equal to 0, then the new item is inserted at the fr
ont of the list. | |
68 debug(""); | |
69 debug("Insert item 'newLength2' at the front of the list, by using index=0")
; | |
70 shouldBe("text1.x.baseVal.insertItemBefore(newLength2, 0)", "newLength2"); | |
71 shouldBe("text1.x.baseVal.numberOfItems", "5"); | |
72 shouldBe("text1.x.baseVal.getItem(0).value", "100"); | |
73 shouldBe("text1.x.baseVal.getItem(1).value", "500"); | |
74 shouldBe("text1.x.baseVal.getItem(2).value", "1000"); | |
75 shouldBe("text1.x.baseVal.getItem(3).value", "1500"); | |
76 shouldBe("text1.x.baseVal.getItem(4).value", "50"); | |
77 shouldThrow("text1.x.baseVal.getItem(5)"); | |
78 | |
79 debug(""); | |
80 debug("Assure that previously saved wrappers still show the old values"); | |
81 shouldBe("item0.value", "500"); | |
82 shouldBe("item1.value", "1000"); | |
83 shouldBe("item2.value", "1500"); | |
84 shouldBe("item3.value", "50"); | |
85 | |
86 // Spec: The index of the item before which the new item is to be inserted. | |
87 debug(""); | |
88 debug("Insert item 'newLength3' at position=2, between '500' and '1000'"); | |
89 shouldBe("text1.x.baseVal.insertItemBefore(newLength3, 2)", "newLength3"); | |
90 shouldBe("text1.x.baseVal.numberOfItems", "6"); | |
91 shouldBe("text1.x.baseVal.getItem(0).value", "100"); | |
92 shouldBe("text1.x.baseVal.getItem(1).value", "500"); | |
93 shouldBe("text1.x.baseVal.getItem(2).value", "150"); | |
94 shouldBe("text1.x.baseVal.getItem(3).value", "1000"); | |
95 shouldBe("text1.x.baseVal.getItem(4).value", "1500"); | |
96 shouldBe("text1.x.baseVal.getItem(5).value", "50"); | |
97 shouldThrow("text1.x.baseVal.getItem(6)"); | |
98 | |
99 // Spec: If newItem is already in a list, then a new object is created with
the same values as newItem and this item is inserted into the list. | |
100 // Otherwise, newItem itself is inserted into the list.. | |
101 debug(""); | |
102 debug("Insert item 'newLength3' at position=1, between '100' and '500', shou
ld not remove it from the old position=2 afterwards."); | |
103 shouldBe("text1.x.baseVal.insertItemBefore(newLength3, 1)", "newLength3"); | |
104 shouldBe("text1.x.baseVal.numberOfItems", "7"); | |
105 shouldBe("text1.x.baseVal.getItem(0).value", "100"); | |
106 shouldBe("text1.x.baseVal.getItem(1).value", "150"); | |
107 shouldBe("text1.x.baseVal.getItem(2).value", "500"); | |
108 shouldBe("text1.x.baseVal.getItem(3).value", "150"); | |
109 shouldBe("text1.x.baseVal.getItem(4).value", "1000"); | |
110 shouldBe("text1.x.baseVal.getItem(5).value", "1500"); | |
111 shouldBe("text1.x.baseVal.getItem(6).value", "50"); | |
112 shouldThrow("text1.x.baseVal.getItem(7)"); | |
113 | |
114 debug(""); | |
115 debug("Insert item 'newLength1' at position=0, before '100', should not remo
ve it from the old position=6 afterwards."); | |
116 shouldBe("text1.x.baseVal.insertItemBefore(newLength1, 0)", "newLength1"); | |
117 shouldBe("text1.x.baseVal.numberOfItems", "8"); | |
118 shouldBe("text1.x.baseVal.getItem(0).value", "50"); | |
119 shouldBe("text1.x.baseVal.getItem(1).value", "100"); | |
120 shouldBe("text1.x.baseVal.getItem(2).value", "150"); | |
121 shouldBe("text1.x.baseVal.getItem(3).value", "500"); | |
122 shouldBe("text1.x.baseVal.getItem(4).value", "150"); | |
123 shouldBe("text1.x.baseVal.getItem(5).value", "1000"); | |
124 shouldBe("text1.x.baseVal.getItem(6).value", "1500"); | |
125 shouldBe("text1.x.baseVal.getItem(7).value", "50"); | |
126 shouldThrow("text1.x.baseVal.getItem(8)"); | |
127 | |
128 debug(""); | |
129 debug("The test passes if you only see 'PASS' messages, and both text elemen
ts on top look the same"); | |
130 debug(""); | |
131 | |
132 ]]> | |
133 </script> | |
134 </body> | |
135 </html> | |
OLD | NEW |