OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <title>SVG*List array method tests</title> | 2 <title>SVG*List array method tests</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 <div id="testcontainer"></div> | 5 <div id="testcontainer"></div> |
6 <div id=log></div> | 6 <div id=log></div> |
7 <script> | 7 <script> |
8 function createSvg() { | 8 function createSvg() { |
9 document.getElementById("testcontainer").innerHTML = '<svg id="svg" width="1"
height="1" visibility="hidden"><polygon id="polygon" points="10 10 450 212 24 10
3 45 32 62 42 123 52 62 52 57 72 12 548 85 12" visibility="hidden" systemLanguag
e="sv, en, fr, de, zn, jp"/><path id="path" d="M 10 10 L 450 212 24 103 45 32 62
42 123 52 62 52 57 72 12 548 85 12" transform="scale(0.5) rotate(34) translate(
10 10)" visibility="hidden"/><text id="text" dx="10 10 450 212 24 103 45 32 62 4
2 123 52 62 52 57 72 12 548 85 12" rotate="10 66 2 23 546 54657 567 546 3 2 2 2
23" visibility="hidden"/></svg>'; | 9 document.getElementById("testcontainer").innerHTML = '<svg id="svg" width="1"
height="1" visibility="hidden"><polygon id="polygon" points="10 10 450 212 24 10
3 45 32 62 42 123 52 62 52 57 72 12 548 85 12" visibility="hidden" systemLanguag
e="sv, en, fr, de, zn, jp"/><path id="path" d="M 10 10 L 450 212 24 103 45 32 62
42 123 52 62 52 57 72 12 548 85 12" transform="scale(0.5) rotate(34) translate(
10 10)" visibility="hidden"/><text id="text" dx="10 10 450 212 24 103 45 32 62 4
2 123 52 62 52 57 72 12 548 85 12" rotate="10 66 2 23 546 54657 567 546 3 2 2 2
23" visibility="hidden"/></svg>'; |
10 } | 10 } |
11 setup(createSvg); | 11 setup(createSvg); |
12 var svg = document.getElementById("svg"); | 12 var svg = document.getElementById("svg"); |
13 var polygon = document.getElementById("polygon"); | 13 var polygon = document.getElementById("polygon"); |
14 var path = document.getElementById("path"); | 14 var path = document.getElementById("path"); |
15 var text = document.getElementById("text"); | 15 var text = document.getElementById("text"); |
16 function createSVGPoint(x,y) { | 16 function createSVGPoint(x,y) { |
17 » var o; | 17 var o; |
18 » try { | 18 try { |
19 » » o = new SVGPoint(x,y); | 19 o = new SVGPoint(x,y); |
20 » } | 20 } |
21 » catch(e) { | 21 catch(e) { |
22 » » o = svg.createSVGPoint(); | 22 o = svg.createSVGPoint(); |
23 » » o.x = x; | 23 o.x = x; |
24 » » o.y = y; | 24 o.y = y; |
25 » } | 25 } |
26 » return o; | 26 return o; |
27 } | 27 } |
28 function createSVGLength(value) { | 28 function createSVGLength(value) { |
29 » var o; | 29 var o; |
30 » try { | 30 try { |
31 » » o = new SVGLength(value); | 31 o = new SVGLength(value); |
32 » } | 32 } |
33 » catch(e) { | 33 catch(e) { |
34 » » o = svg.createSVGLength(); | 34 o = svg.createSVGLength(); |
35 » » o.value = value; | 35 o.value = value; |
36 » } | 36 } |
37 » return o; | 37 return o; |
38 } | 38 } |
39 function createSVGNumber(value) { | 39 function createSVGNumber(value) { |
40 » var o; | 40 var o; |
41 » try { | 41 try { |
42 » » o = new SVGNumber(value); | 42 o = new SVGNumber(value); |
43 » } | 43 } |
44 » catch(e) { | 44 catch(e) { |
45 » » o = svg.createSVGNumber(); | 45 o = svg.createSVGNumber(); |
46 » » o.value = value; | 46 o.value = value; |
47 » } | 47 } |
48 » return o; | 48 return o; |
49 } | 49 } |
50 function createSVGTransformTranslate(tx,ty) { | 50 function createSVGTransformTranslate(tx,ty) { |
51 » var o; | 51 var o; |
52 » try { | 52 try { |
53 » » o = new SVGTransform(); | 53 o = new SVGTransform(); |
54 » } | 54 } |
55 » catch(e) { | 55 catch(e) { |
56 » » o = svg.createSVGTransform(); | 56 o = svg.createSVGTransform(); |
57 » } | 57 } |
58 » o.setTranslate(tx, ty); | 58 o.setTranslate(tx, ty); |
59 » return o; | 59 return o; |
60 } | 60 } |
61 var lists = { | 61 var lists = { |
62 » "SVGPointList" : | 62 "SVGPointList": |
63 » » { "impl": polygon.points, | 63 { "impl": polygon.points, |
64 » "type": "SVGPoint", | 64 "type": "SVGPoint", |
65 » "length": 10, | 65 "length": 10, |
66 » "insert_value": createSVGPoint(5, 5), | 66 "insert_value": createSVGPoint(5, 5), |
67 » "equals": function(a,b) { return a.x == b.x && a.y == b.y; } | 67 "equals": function(a,b) { return a.x == b.x && a.y == b.y; } |
68 » }, | 68 }, |
69 » "SVGStringList" : | 69 "SVGStringList": |
70 » » { "impl": polygon.systemLanguage, | 70 { "impl": polygon.systemLanguage, |
71 » » "type": "DOMString", | 71 "type": "DOMString", |
72 » "length": 6, | 72 "length": 6, |
73 » "insert_value": "uk", | 73 "insert_value": "uk", |
74 » "equals": function(a,b) { return a == b; } | 74 "equals": function(a,b) { return a == b; } |
75 » }, | 75 }, |
76 » "SVGTransformList" : | 76 "SVGTransformList": |
77 » » { "impl": path.transform.baseVal, | 77 { "impl": path.transform.baseVal, |
78 » » "type": "SVGTransform", | 78 "type": "SVGTransform", |
79 » "length": 3, | 79 "length": 3, |
80 » "insert_value": createSVGTransformTranslate(5,5), | 80 "insert_value": createSVGTransformTranslate(5,5), |
81 » "equals": function(a,b) { return a.matrix.a == b.matrix.a && | 81 "equals": function(a,b) { return a.matrix.a == b.matrix.a && |
82 » » » » » » » » » »
a.matrix.b == b.matrix.b && | 82 a.matrix.b == b.matrix.b && |
83 » » » » » » » » » »
a.matrix.c == b.matrix.c && | 83 a.matrix.c == b.matrix.c && |
84 » » » » » » » » » »
a.matrix.d == b.matrix.d && | 84 a.matrix.d == b.matrix.d && |
85 » » » » » » » » » »
a.matrix.e == b.matrix.e && | 85 a.matrix.e == b.matrix.e && |
86 » » » » » » » » » »
a.matrix.f == b.matrix.f; } | 86 a.matrix.f == b.matrix.f; } |
87 » }, | 87 }, |
88 » "SVGPathSegList" : | 88 "SVGPathSegList": |
89 » » { "impl": path.pathSegList, | 89 { "impl": path.pathSegList, |
90 » » "type": "SVGPathSegMovetoAbs", | 90 "type": "SVGPathSegMovetoAbs", |
91 » "length": 10, | 91 "length": 10, |
92 » "insert_value": path.createSVGPathSegMovetoAbs(5,5), | 92 "insert_value": path.createSVGPathSegMovetoAbs(5,5), |
93 » "equals": function(a,b) { return a.x == b.x && a.y == b.y; } | 93 "equals": function(a,b) { return a.x == b.x && a.y == b.y; } |
94 » }, | 94 }, |
95 » "SVGLengthList" : | 95 "SVGLengthList": |
96 » » { "impl": text.dx.baseVal, | 96 { "impl": text.dx.baseVal, |
97 » » "type": "SVGLength", | 97 "type": "SVGLength", |
98 » "length": 20, | 98 "length": 20, |
99 » "insert_value": createSVGLength(5), | 99 "insert_value": createSVGLength(5), |
100 » "equals": function(a,b) { return a.valueInSpecifiedUnits == b.valu
eInSpecifiedUnits && | 100 "equals": function(a,b) { return a.valueInSpecifiedUnits == b.valueInS
pecifiedUnits && |
101 » » » » » » » » » »
a.unitType == b.unitType; } | 101 a.unitType == b.unitType; } |
102 » }, | 102 }, |
103 » "SVGNumberList" : | 103 "SVGNumberList": |
104 » » { "impl": text.rotate.baseVal, | 104 { "impl": text.rotate.baseVal, |
105 » » "type": "SVGNumber", | 105 "type": "SVGNumber", |
106 » "length": 13, | 106 "length": 13, |
107 » "insert_value": createSVGNumber(5), | 107 "insert_value": createSVGNumber(5), |
108 » "equals": function(a,b) { return a.value == b.value; } | 108 "equals": function(a,b) { return a.value == b.value; } |
109 » } | 109 } |
110 }; | 110 }; |
111 | 111 |
112 for (list_type in lists) { | 112 for (list_type in lists) { |
113 » test(function() { | 113 test(function() { |
114 » » assert_idl_attribute(lists[list_type].impl, "length"); | 114 assert_idl_attribute(lists[list_type].impl, "length"); |
115 » }, list_type + " has length attribute"); | 115 }, list_type + " has length attribute"); |
116 » test(function() { | 116 test(function() { |
117 » » assert_idl_attribute(lists[list_type].impl, "numberOfItems"); | 117 assert_idl_attribute(lists[list_type].impl, "numberOfItems"); |
118 » }, list_type + " has numberOfItems attribute"); | 118 }, list_type + " has numberOfItems attribute"); |
119 » test(function() { | 119 test(function() { |
120 » assert_equals(lists[list_type].impl.length, lists[list_type].impl.numb
erOfItems); | 120 assert_equals(lists[list_type].impl.length, lists[list_type].impl.numberOf
Items); |
121 » assert_equals(lists[list_type].impl.length, lists[list_type].length); | 121 assert_equals(lists[list_type].impl.length, lists[list_type].length); |
122 » }, list_type + ".length equals " + list_type + ".numberOfItems."); | 122 }, list_type + ".length equals " + list_type + ".numberOfItems."); |
123 » test(function() { | 123 test(function() { |
124 » » assert_true(lists[list_type].equals(lists[list_type].impl.getIte
m(0), lists[list_type].impl[0])); | 124 assert_true(lists[list_type].equals(lists[list_type].impl.getItem(0), li
sts[list_type].impl[0])); |
125 » }, list_type + " has array getter"); | 125 }, list_type + " has array getter"); |
126 » test(function() { | 126 test(function() { |
127 » » var old_value = lists[list_type].impl[0]; | 127 var old_value = lists[list_type].impl[0]; |
128 » » var new_value = lists[list_type].insert_value; | 128 var new_value = lists[list_type].insert_value; |
129 » » lists[list_type].impl[0] = lists[list_type].insert_value; | 129 lists[list_type].impl[0] = lists[list_type].insert_value; |
130 » » assert_false(lists[list_type].equals(old_value, new_value)); | 130 assert_false(lists[list_type].equals(old_value, new_value)); |
131 » » assert_true(lists[list_type].equals(lists[list_type].impl[0], ne
w_value)); | 131 assert_true(lists[list_type].equals(lists[list_type].impl[0], new_value)
); |
132 assert_equals(lists[list_type].impl.length, lists[list_type].length); | 132 assert_equals(lists[list_type].impl.length, lists[list_type].length); |
133 » }, list_type + " has array setter"); | 133 }, list_type + " has array setter"); |
134 } | 134 } |
135 | 135 |
136 </script> | 136 </script> |
OLD | NEW |