OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <title>SVGTransformList, basics</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/SVGTransformList-helper.js"></script> |
| 6 <svg width="200" height="200"> |
| 7 <circle cx="40" cy="40" r="40" fill="green" transform="scale(2, 2) translate
(10 10)"/> |
| 8 </svg> |
| 9 <script> |
| 10 test(function() { |
| 11 // This is a test of the simple SVGTransformList API parts. |
| 12 |
| 13 var svg = document.querySelector("svg"); |
| 14 var circle1 = document.querySelector("circle"); |
| 15 var transformList = circle1.transform.baseVal; |
| 16 |
| 17 // TODO(shanmuga.m) : // Split into several subtests. |
| 18 |
| 19 // Spec: The object referenced by animVal will always be distinct from the one
referenced by baseVal, even when the attribute is not animated. |
| 20 assert_not_equals(circle1.transform.baseVal, circle1.transform.animVal); |
| 21 |
| 22 assert_equals(circle1.transform.baseVal.numberOfItems, 2); |
| 23 assert_equals(circle1.transform.animVal.numberOfItems, 2); |
| 24 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 25 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 26 |
| 27 // Test uncommon arguments for initialize(). |
| 28 assert_throws(new TypeError(), function() { transformList.initialize(30); }); |
| 29 assert_throws(new TypeError(), function() { transformList.initialize('aString'
); }); |
| 30 assert_throws(new TypeError(), function() { transformList.initialize(circle1);
}); |
| 31 assert_throws(new TypeError(), function() { transformList.initialize(null); })
; |
| 32 |
| 33 // Test uncommon arguments for getItem(). |
| 34 assert_throws("IndexSizeError", function() { transformList.getItem(30); }); |
| 35 assert_equals(transformList.getItem('aString').toString(), "type=SVG_TRANSFORM
_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 36 assert_equals(transformList.getItem(circle1).toString(), "type=SVG_TRANSFORM_S
CALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 37 assert_equals(transformList.getItem(null).toString(), "type=SVG_TRANSFORM_SCAL
E matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 38 |
| 39 // Test uncommon arguments for insertItemBefore(). |
| 40 assert_throws(new TypeError(), function() { transformList.insertItemBefore(30)
; }); |
| 41 assert_throws(new TypeError(), function() { transformList.insertItemBefore('aS
tring'); }); |
| 42 assert_throws(new TypeError(), function() { transformList.insertItemBefore(cir
cle1); }); |
| 43 assert_throws(new TypeError(), function() { transformList.insertItemBefore(nul
l); }); |
| 44 |
| 45 assert_equals(transformList.insertItemBefore(transformList.getItem(1), 'aStrin
g').toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]
"); |
| 46 assert_equals(transformList.numberOfItems, 3); |
| 47 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 48 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 49 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 50 assert_equals(circle1.getAttribute('transform'), "translate(10 10) scale(2 2)
translate(10 10)"); |
| 51 |
| 52 assert_equals(transformList.insertItemBefore(transformList.getItem(1), circle1
).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 53 assert_equals(transformList.numberOfItems, 4); |
| 54 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 55 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 56 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 57 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 58 assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10)
scale(2 2) translate(10 10)"); |
| 59 |
| 60 assert_equals(transformList.insertItemBefore(transformList.getItem(1), null).t
oString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 61 assert_equals(transformList.numberOfItems, 5); |
| 62 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 63 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 64 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 65 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 66 assert_equals(transformList.getItem(4).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 67 assert_equals(circle1.getAttribute('transform'), "translate(10 10) scale(2 2)
translate(10 10) scale(2 2) translate(10 10)"); |
| 68 |
| 69 assert_equals(transformList.insertItemBefore(transformList.getItem(1), 0).toSt
ring(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 70 assert_equals(transformList.numberOfItems, 6); |
| 71 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 72 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 73 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 74 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 75 assert_equals(transformList.getItem(4).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 76 assert_equals(transformList.getItem(5).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 77 assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10)
scale(2 2) translate(10 10) scale(2 2) translate(10 10)"); |
| 78 |
| 79 assert_throws(new TypeError(), function() { transformList.insertItemBefore(30,
0); }); |
| 80 assert_throws(new TypeError(), function() { transformList.insertItemBefore('aS
tring', 0); }); |
| 81 assert_throws(new TypeError(), function() { transformList.insertItemBefore(cir
cle1, 0); }); |
| 82 assert_throws(new TypeError(), function() { transformList.insertItemBefore(nul
l, 0); }); |
| 83 |
| 84 // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle
1. |
| 85 circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skew
X(45)'); |
| 86 assert_equals(transformList.numberOfItems, 4); |
| 87 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE
matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 88 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 89 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 90 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 91 assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) transl
ate(10 10) skewX(45)"); |
| 92 |
| 93 // Test uncommon arguments for replaceItem(). |
| 94 assert_throws(new TypeError(), function() { transformList.replaceItem(30); }); |
| 95 assert_throws(new TypeError(), function() { transformList.replaceItem('aString
'); }); |
| 96 assert_throws(new TypeError(), function() { transformList.replaceItem(circle1)
; }); |
| 97 assert_throws(new TypeError(), function() { transformList.replaceItem(null); }
); |
| 98 assert_throws(new TypeError(), function() { transformList.replaceItem(30, 0);
}); |
| 99 assert_throws(new TypeError(), function() { transformList.replaceItem('aString
', 0); }); |
| 100 assert_throws(new TypeError(), function() { transformList.replaceItem(circle1,
0); }); |
| 101 assert_throws(new TypeError(), function() { transformList.replaceItem(null, 0)
; }); |
| 102 |
| 103 // Test uncommon values for indexed setter. |
| 104 assert_throws(new TypeError(), function() { transformList[0] = 30; }); |
| 105 assert_throws(new TypeError(), function() { transformList[0] = 'aString'; }); |
| 106 assert_throws(new TypeError(), function() { transformList[0] = circle1; }); |
| 107 assert_throws(new TypeError(), function() { transformList[0] = null; }); |
| 108 |
| 109 assert_equals(transformList.replaceItem(transformList.getItem(3), 0).toString(
), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 110 assert_equals(transformList.numberOfItems, 4); |
| 111 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 112 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 113 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 114 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 115 assert_equals(circle1.getAttribute('transform'), "skewX(45) scale(2 2) transla
te(10 10) skewX(45)"); |
| 116 |
| 117 // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle
1. |
| 118 circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skew
X(45)'); |
| 119 assert_equals(transformList.replaceItem(transformList.getItem(0), 'aString').t
oString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 120 assert_equals(transformList.numberOfItems, 4); |
| 121 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE
matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 122 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 123 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 124 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 125 assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) transl
ate(10 10) skewX(45)"); |
| 126 |
| 127 assert_equals(transformList.replaceItem(transformList.getItem(0), circle1).toS
tring(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 128 assert_equals(transformList.numberOfItems, 4); |
| 129 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE
matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 130 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 131 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 132 assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 133 assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) transl
ate(10 10) skewX(45)"); |
| 134 |
| 135 assert_equals(transformList.replaceItem(transformList.getItem(0), null).toStri
ng(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 136 assert_equals(transformList.numberOfItems, 4); |
| 137 assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) transl
ate(10 10) skewX(45)"); |
| 138 |
| 139 // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle
1. |
| 140 circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skew
X(45)'); |
| 141 |
| 142 // Test uncommon arguments for removeItem(). |
| 143 assert_throws("IndexSizeError", function() { transformList.removeItem(30); }); |
| 144 |
| 145 assert_equals(transformList.removeItem(0).toString(), "type=SVG_TRANSFORM_ROTA
TE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]"); |
| 146 assert_equals(transformList.numberOfItems, 3); |
| 147 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE m
atrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 148 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 149 assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 150 assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10)
skewX(45)"); |
| 151 |
| 152 assert_equals(transformList.removeItem('aString').toString(), "type=SVG_TRANSF
ORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]"); |
| 153 assert_equals(transformList.numberOfItems, 2); |
| 154 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLA
TE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 155 assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 156 assert_equals(circle1.getAttribute('transform'), "translate(10 10) skewX(45)")
; |
| 157 |
| 158 assert_equals(transformList.removeItem(circle1).toString(), "type=SVG_TRANSFOR
M_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]"); |
| 159 assert_equals(transformList.numberOfItems, 1); |
| 160 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SKEWX m
atrix=[1.0 0.0 1.0 1.0 0.0 0.0]"); |
| 161 assert_equals(circle1.getAttribute('transform'), "skewX(45)"); |
| 162 |
| 163 // Test uncommon arguments for appendItem(). |
| 164 assert_throws(new TypeError(), function() { transformList.appendItem(30); }); |
| 165 assert_throws(new TypeError(), function() { transformList.appendItem('aString'
); }); |
| 166 assert_throws(new TypeError(), function() { transformList.appendItem(circle1);
}); |
| 167 assert_throws(new TypeError(), function() { transformList.appendItem(null); })
; |
| 168 |
| 169 // Testing animVal clear throws. |
| 170 assert_throws("NoModificationAllowedError", function() { circle1.transform.ani
mVal.clear(); }); |
| 171 transformList.clear(); |
| 172 |
| 173 // Creating new SVGTransform, with 45 deg rotation about x=50, y=100 and appen
d it to the transform list. |
| 174 var transform = svg.createSVGTransform(); |
| 175 assert_equals(transform.toString(), "type=SVG_TRANSFORM_MATRIX matrix=[1.0 0.0
0.0 1.0 0.0 0.0]"); |
| 176 transform.setRotate(45, 50, 100); |
| 177 |
| 178 assert_equals(transformList.appendItem(transform).toString(), "type=SVG_TRANSF
ORM_ROTATE matrix=[0.7 0.7 -0.7 0.7 85.4 -6.1]"); |
| 179 assert_equals(transformList.numberOfItems, 1); |
| 180 assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE
matrix=[0.7 0.7 -0.7 0.7 85.4 -6.1]"); |
| 181 assert_equals(circle1.getAttribute('transform'), "rotate(45 50 100)"); |
| 182 }); |
| 183 </script> |
OLD | NEW |