OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <title>SVGLengthList, initialize()</title> | 2 <title>SVGLengthList, initialize()</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 1000 1500" y="25"> ABC </text> | 7 <text id="text1" x="500 1000 1500" y="25"> ABC </text> |
7 <text id="text2" x="50 500" y="50"> ABC </text> | 8 <text id="text2" x="50 500" y="50"> ABC </text> |
8 <text id="text3" x="50 500 50" y="75">ABC</text> | 9 <text id="text3" x="50 500 50" y="75">ABC</text> |
9 <text id="text4" x="500" y="100">ABC</text> | 10 <text id="text4" x="500" y="100">ABC</text> |
10 </svg> | 11 </svg> |
11 <script> | 12 <script> |
12 test(function() { | 13 test(function() { |
13 // This is a test of the SVGLengthList.initialize() API. | 14 // This is a test of the SVGLengthList.initialize() API. |
14 | 15 |
15 var svg = document.querySelector("svg"); | 16 var svg = document.querySelector("svg"); |
16 var list1 = document.getElementById("text1").x.baseVal; | 17 var list1 = document.getElementById("text1").x.baseVal; |
17 var list2 = document.getElementById("text2").x.baseVal; | 18 var list2 = document.getElementById("text2").x.baseVal; |
18 var list3 = document.getElementById("text3").x.baseVal; | 19 var list3 = document.getElementById("text3").x.baseVal; |
19 var list4 = document.getElementById("text4").x.baseVal; | 20 var list4 = document.getElementById("text4").x.baseVal; |
20 | 21 |
21 // Check initial list state of text1. | 22 // Check initial list state of text1. |
22 assert_equals(list1.numberOfItems, 3); | 23 assert_list(list1, [500, 1000, 1500]); |
23 assert_equals(list1.getItem(0).value, 500); | |
24 assert_equals(list1.getItem(1).value, 1000); | |
25 assert_equals(list1.getItem(2).value, 1500); | |
26 assert_throws("IndexSizeError", function() { list1.getItem(3); }); | |
27 | 24 |
28 // Check initial list state of text2. | 25 // Check initial list state of text2. |
29 assert_equals(list2.numberOfItems, 2); | 26 assert_list(list2, [50, 500]); |
30 assert_equals(list2.getItem(0).value, 50); | |
31 assert_equals(list2.getItem(1).value, 500); | |
32 assert_throws("IndexSizeError", function() { list2.getItem(2); }); | |
33 | 27 |
34 // Check initial list state of text3. | 28 // Check initial list state of text3. |
35 assert_equals(list3.numberOfItems, 3); | 29 assert_list(list3, [50, 500, 50]); |
36 assert_equals(list3.getItem(0).value, 50); | |
37 assert_equals(list3.getItem(1).value, 500); | |
38 assert_equals(list3.getItem(2).value, 50); | |
39 assert_throws("IndexSizeError", function() { list3.getItem(3); }); | |
40 | 30 |
41 // Check initial list state of text4. | 31 // Check initial list state of text4. |
42 assert_equals(list4.numberOfItems, 1); | 32 assert_list(list4, [500]); |
43 assert_equals(list4.getItem(0).value, 500); | |
44 assert_throws("IndexSizeError", function() { list4.getItem(1); }); | |
45 | 33 |
46 // Create a new SVGLength object, that will be the only x coordinate in the fi
rst text element. | 34 // Create a new SVGLength object, that will be the only x coordinate in the fi
rst text element. |
47 var newLength = svg.createSVGLength(); | 35 var newLength = svg.createSVGLength(); |
48 newLength.value = 50; | 36 newLength.value = 50; |
49 assert_equals(newLength.value, 50); | 37 assert_equals(newLength.value, 50); |
50 | 38 |
51 // Spec: Clears all existing current items from the list and re-initializes th
e list to hold the single item specified by the parameter. | 39 // Spec: Clears all existing current items from the list and re-initializes th
e list to hold the single item specified by the parameter. |
52 | 40 |
53 // Initialize SVGLengthList with 'newLength'. | 41 // Initialize SVGLengthList with 'newLength'. |
54 assert_equals(list1.initialize(newLength).value, newLength.value); | 42 assert_equals(list1.initialize(newLength).value, newLength.value); |
(...skipping 25 matching lines...) Expand all Loading... |
80 // Copy item from text3 to text4. | 68 // Copy item from text3 to text4. |
81 assert_equals(list4.initialize(list3.getItem(0)).value, itemInAnotherList.valu
e); | 69 assert_equals(list4.initialize(list3.getItem(0)).value, itemInAnotherList.valu
e); |
82 assert_equals(list4.getItem(0).value, 50); | 70 assert_equals(list4.getItem(0).value, 50); |
83 list3.getItem(0); // Should not throw. | 71 list3.getItem(0); // Should not throw. |
84 | 72 |
85 // Initialize text2 using setAttribute('x', '50'). | 73 // Initialize text2 using setAttribute('x', '50'). |
86 text2.setAttribute("x", "50"); | 74 text2.setAttribute("x", "50"); |
87 assert_equals(list2.getItem(0).value, 50); | 75 assert_equals(list2.getItem(0).value, 50); |
88 | 76 |
89 // Final check whether the lists all look like expected. | 77 // Final check whether the lists all look like expected. |
90 assert_equals(list1.getItem(0).value, 50); | 78 assert_list(list1, [50]); |
91 assert_equals(list2.getItem(0).value, 50); | 79 assert_list(list2, [50]); |
92 assert_equals(list3.getItem(0).value, 50); | 80 assert_list(list3, [50]); |
93 assert_equals(list4.getItem(0).value, 50); | 81 assert_list(list4, [50]); |
94 assert_equals(list1.numberOfItems, 1); | |
95 assert_equals(list2.numberOfItems, 1); | |
96 assert_equals(list3.numberOfItems, 1); | |
97 assert_equals(list4.numberOfItems, 1); | |
98 assert_throws("IndexSizeError", function() { list1.getItem(1); }); | |
99 assert_throws("IndexSizeError", function() { list2.getItem(1); }); | |
100 assert_throws("IndexSizeError", function() { list3.getItem(1); }); | |
101 assert_throws("IndexSizeError", function() { list4.getItem(1); }); | |
102 }); | 82 }); |
103 </script> | 83 </script> |
OLD | NEW |