OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 | 4 |
5 <script> | 5 <script> |
6 | 6 |
7 var simpleLength = new CSSSimpleLength(0, "px"); | 7 var simpleLength = new CSSSimpleLength(0, "px"); |
8 var decimalLength = new CSSSimpleLength(1.1, "px"); | 8 var decimalLength = new CSSSimpleLength(1.1, "px"); |
9 var negativeLength = new CSSSimpleLength(-2.2, "em"); | 9 var negativeLength = new CSSSimpleLength(-2.2, "em"); |
10 var calcLengthPx = new CSSCalcLength({px: 1}); | 10 var calcLengthPx = new CSSCalcLength({px: 1}); |
11 var calcLength = new CSSCalcLength({px: 1, em: -2.2}); | 11 var calcLength = new CSSCalcLength({px: 1, em: -2.2}); |
12 | 12 |
13 var simplePercent = new CSSSimpleLength(10, "percent"); | 13 var simplePercent = new CSSSimpleLength(10, "percent"); |
14 var calcPercent = new CSSCalcLength({px: 1, percent: 2.2}); | 14 var calcPercent = new CSSCalcLength({px: 1, percent: 2.2}); |
15 | 15 |
16 var values = [ | 16 var values = [ |
17 // 2D CSSTranslation Transform Components | 17 // 2D CSSTranslation Transform Components |
18 {input: new CSSTranslation(simpleLength, simpleLength), | 18 {input: new CSSTranslation(simpleLength, simpleLength), |
19 x: simpleLength, y: simpleLength, is2DComponent: true}, | 19 x: simpleLength, y: simpleLength, is2D: true}, |
20 {input: new CSSTranslation(decimalLength, negativeLength), | 20 {input: new CSSTranslation(decimalLength, negativeLength), |
21 x: decimalLength, y: negativeLength, is2DComponent: true}, | 21 x: decimalLength, y: negativeLength, is2D: true}, |
22 {input: new CSSTranslation(negativeLength, calcLengthPx), | 22 {input: new CSSTranslation(negativeLength, calcLengthPx), |
23 x: negativeLength, y: calcLengthPx, is2DComponent: true}, | 23 x: negativeLength, y: calcLengthPx, is2D: true}, |
24 {input: new CSSTranslation(calcLengthPx, negativeLength), | 24 {input: new CSSTranslation(calcLengthPx, negativeLength), |
25 x: calcLengthPx, y: negativeLength, is2DComponent: true}, | 25 x: calcLengthPx, y: negativeLength, is2D: true}, |
26 {input: new CSSTranslation(calcLengthPx, calcLength), | 26 {input: new CSSTranslation(calcLengthPx, calcLength), |
27 x: calcLengthPx, y: calcLength, is2DComponent: true}, | 27 x: calcLengthPx, y: calcLength, is2D: true}, |
28 {input: new CSSTranslation(simplePercent, simpleLength), | 28 {input: new CSSTranslation(simplePercent, simpleLength), |
29 x: simplePercent, y: simpleLength, is2DComponent: true}, | 29 x: simplePercent, y: simpleLength, is2D: true}, |
30 {input: new CSSTranslation(calcLengthPx, simplePercent), | 30 {input: new CSSTranslation(calcLengthPx, simplePercent), |
31 x: calcLengthPx, y: simplePercent, is2DComponent: true}, | 31 x: calcLengthPx, y: simplePercent, is2D: true}, |
32 {input: new CSSTranslation(calcPercent, calcLength), | 32 {input: new CSSTranslation(calcPercent, calcLength), |
33 x: calcPercent, y: calcLength, is2DComponent: true}, | 33 x: calcPercent, y: calcLength, is2D: true}, |
34 {input: new CSSTranslation(simplePercent, calcPercent), | 34 {input: new CSSTranslation(simplePercent, calcPercent), |
35 x: simplePercent, y: calcPercent, is2DComponent: true}, | 35 x: simplePercent, y: calcPercent, is2D: true}, |
36 | 36 |
37 // 3D CSSTranslation Transform Components | 37 // 3D CSSTranslation Transform Components |
38 {input: new CSSTranslation(simpleLength, simpleLength, simpleLength), | 38 {input: new CSSTranslation(simpleLength, simpleLength, simpleLength), |
39 x: simpleLength, y: simpleLength, z: simpleLength, is2DComponent: false}, | 39 x: simpleLength, y: simpleLength, z: simpleLength, is2D: false}, |
40 {input: new CSSTranslation(simpleLength, decimalLength, negativeLength), | 40 {input: new CSSTranslation(simpleLength, decimalLength, negativeLength), |
41 x: simpleLength, y: decimalLength, z: negativeLength, is2DComponent: false}, | 41 x: simpleLength, y: decimalLength, z: negativeLength, is2D: false}, |
42 {input: new CSSTranslation(simpleLength, simpleLength, calcLengthPx), | 42 {input: new CSSTranslation(simpleLength, simpleLength, calcLengthPx), |
43 x: simpleLength, y: simpleLength, z: calcLengthPx, is2DComponent: false}, | 43 x: simpleLength, y: simpleLength, z: calcLengthPx, is2D: false}, |
44 {input: new CSSTranslation(calcLengthPx, calcLength, calcLength), | 44 {input: new CSSTranslation(calcLengthPx, calcLength, calcLength), |
45 x: calcLengthPx, y: calcLength, z: calcLength, is2DComponent: false}, | 45 x: calcLengthPx, y: calcLength, z: calcLength, is2D: false}, |
46 {input: new CSSTranslation(simplePercent, decimalLength, simpleLength), | 46 {input: new CSSTranslation(simplePercent, decimalLength, simpleLength), |
47 x: simplePercent, y: decimalLength, z: simpleLength, is2DComponent: false}, | 47 x: simplePercent, y: decimalLength, z: simpleLength, is2D: false}, |
48 {input: new CSSTranslation(simpleLength, calcPercent, decimalLength), | 48 {input: new CSSTranslation(simpleLength, calcPercent, decimalLength), |
49 x: simpleLength, y: calcPercent, z: decimalLength, is2DComponent: false}, | 49 x: simpleLength, y: calcPercent, z: decimalLength, is2D: false}, |
50 {input: new CSSTranslation(calcPercent, simplePercent, calcLength), | 50 {input: new CSSTranslation(calcPercent, simplePercent, calcLength), |
51 x: calcPercent, y: simplePercent, z: calcLength, is2DComponent: false} | 51 x: calcPercent, y: simplePercent, z: calcLength, is2D: false} |
52 ]; | 52 ]; |
53 | 53 |
54 function expectedCssString(obj) { | 54 function expectedCssString(obj) { |
55 var cssText = obj.is2DComponent ? "translate(" : "translate3d("; | 55 var cssText = obj.is2D ? "translate(" : "translate3d("; |
56 cssText += obj.x.cssText + ", " + obj.y.cssText; | 56 cssText += obj.x.cssText + ", " + obj.y.cssText; |
57 if (!obj.is2DComponent) | 57 if (!obj.is2D) |
58 cssText += ", " + obj.z.cssText; | 58 cssText += ", " + obj.z.cssText; |
59 cssText += ")"; | 59 cssText += ")"; |
60 return cssText; | 60 return cssText; |
61 } | 61 } |
62 | 62 |
63 test(function() { | 63 test(function() { |
64 for (var i = 0; i < values.length; ++i) { | 64 for (var i = 0; i < values.length; ++i) { |
65 assert_equals(values[i].input.x, values[i].x); | 65 assert_equals(values[i].input.x, values[i].x); |
66 assert_equals(values[i].input.y, values[i].y); | 66 assert_equals(values[i].input.y, values[i].y); |
67 if (values[i].is2DComponent) | 67 if (values[i].is2D) |
68 assert_equals(values[i].input.z, null); | 68 assert_equals(values[i].input.z, null); |
69 else | 69 else |
70 assert_equals(values[i].input.z, values[i].z); | 70 assert_equals(values[i].input.z, values[i].z); |
71 } | 71 } |
72 }, "Test that the (x, y, z) values for CSSTranslation are correct."); | 72 }, "Test that the (x, y, z) values for CSSTranslation are correct."); |
73 | 73 |
74 test(function() { | 74 test(function() { |
75 for (var i = 0; i < values.length; ++i) { | 75 for (var i = 0; i < values.length; ++i) { |
76 assert_equals(values[i].input.is2DComponent(), values[i].is2DComponent); | 76 assert_equals(values[i].input.is2D(), values[i].is2D); |
77 } | 77 } |
78 }, "Test that the is2DComponent values for CSSTranslation is correct."); | 78 }, "Test that the is2D values for CSSTranslation is correct."); |
79 | 79 |
80 test(function() { | 80 test(function() { |
81 for (var i = 0; i < values.length; ++i) { | 81 for (var i = 0; i < values.length; ++i) { |
82 assert_equals(values[i].input.cssText, expectedCssString(values[i])); | 82 assert_equals(values[i].input.cssText, expectedCssString(values[i])); |
83 } | 83 } |
84 }, "Test that cssText values for CSSTranslation is correct."); | 84 }, "Test that cssText values for CSSTranslation is correct."); |
85 | 85 |
86 test(function() { | 86 test(function() { |
87 assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength
, simplePercent); }); | 87 assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength
, simplePercent); }); |
88 assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength
, calcPercent); }); | 88 assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength
, calcPercent); }); |
89 assert_throws(null, function() { new CSSTranslation(simplePercent, simplePerce
nt, simplePercent); }); | 89 assert_throws(null, function() { new CSSTranslation(simplePercent, simplePerce
nt, simplePercent); }); |
90 }, "Test that CSSTranslation constructor throws when z component contains percen
t."); | 90 }, "Test that CSSTranslation constructor throws when z component contains percen
t."); |
91 | 91 |
92 test(function() { | 92 test(function() { |
93 assert_throws(null, function() { new CSSTranslation(); }); | 93 assert_throws(null, function() { new CSSTranslation(); }); |
94 assert_throws(null, function() { new CSSTranslation(simpleLength); }); | 94 assert_throws(null, function() { new CSSTranslation(simpleLength); }); |
95 }, "Test that invalid number of arguments for CSSTranslation throws an exception
."); | 95 }, "Test that invalid number of arguments for CSSTranslation throws an exception
."); |
96 | 96 |
97 </script> | 97 </script> |
OLD | NEW |