OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>KeyframeEffectReadOnly getComputedTiming() tests</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animationeffect
readonly-getcomputedtiming"> |
| 5 <link rel="author" title="Boris Chiou" href="mailto:boris.chiou@gmail.com"> |
| 6 <script src="../../../../resources/testharness.js"></script> |
| 7 <script src="../../../../resources/testharnessreport.js"></script> |
| 8 <script src="../testcommon.js"></script> |
| 9 <body> |
| 10 <div id="log"></div> |
| 11 <div id="target"></div> |
| 12 <script> |
| 13 "use strict"; |
| 14 |
| 15 var target = document.getElementById("target"); |
| 16 |
| 17 test(function(t) { |
| 18 var effect = new KeyframeEffectReadOnly(target, |
| 19 { left: ["10px", "20px"] }); |
| 20 |
| 21 var ct = effect.getComputedTiming(); |
| 22 assert_equals(ct.delay, 0, "computed delay"); |
| 23 assert_equals(ct.fill, "none", "computed fill"); |
| 24 assert_equals(ct.iterations, 1.0, "computed iterations"); |
| 25 assert_equals(ct.duration, 0, "computed duration"); |
| 26 assert_equals(ct.direction, "normal", "computed direction"); |
| 27 }, "values of getComputedTiming() when a KeyframeEffectReadOnly is " + |
| 28 "constructed without any KeyframeEffectOptions object"); |
| 29 |
| 30 var gGetComputedTimingTests = [ |
| 31 { desc: "an empty KeyframeEffectOptions object", |
| 32 input: { }, |
| 33 expected: { } }, |
| 34 { desc: "a normal KeyframeEffectOptions object", |
| 35 input: { delay: 1000, |
| 36 fill: "auto", |
| 37 iterations: 5.5, |
| 38 duration: "auto", |
| 39 direction: "alternate" }, |
| 40 expected: { delay: 1000, |
| 41 fill: "none", |
| 42 iterations: 5.5, |
| 43 duration: 0, |
| 44 direction: "alternate" } }, |
| 45 { desc: "a double value", |
| 46 input: 3000, |
| 47 timing: { duration: 3000 }, |
| 48 expected: { delay: 0, |
| 49 fill: "none", |
| 50 iterations: 1, |
| 51 duration: 3000, |
| 52 direction: "normal" } }, |
| 53 { desc: "+Infinity", |
| 54 input: Infinity, |
| 55 expected: { duration: Infinity } }, |
| 56 { desc: "an Infinity duration", |
| 57 input: { duration: Infinity }, |
| 58 expected: { duration: Infinity } }, |
| 59 { desc: "an auto duration", |
| 60 input: { duration: "auto" }, |
| 61 expected: { duration: 0 } }, |
| 62 { desc: "an Infinity iterations", |
| 63 input: { iterations: Infinity }, |
| 64 expected: { iterations: Infinity } }, |
| 65 { desc: "a negative Infinity iterations", |
| 66 input: { iterations: -Infinity}, |
| 67 expected: { iterations: 1 } }, |
| 68 { desc: "a NaN iterations", |
| 69 input: { iterations: NaN }, |
| 70 expected: { iterations: 1 } }, |
| 71 { desc: "a negative iterations", |
| 72 input: { iterations: -1 }, |
| 73 expected: { iterations: 1 } }, |
| 74 { desc: "an auto fill", |
| 75 input: { fill: "auto" }, |
| 76 expected: { fill: "none" } }, |
| 77 { desc: "a forwards fill", |
| 78 input: { fill: "forwards" }, |
| 79 expected: { fill: "forwards" } } |
| 80 ]; |
| 81 |
| 82 gGetComputedTimingTests.forEach(function(stest) { |
| 83 test(function(t) { |
| 84 var effect = new KeyframeEffectReadOnly(target, |
| 85 { left: ["10px", "20px"] }, |
| 86 stest.input); |
| 87 |
| 88 // Helper function to provide default expected values when the test does |
| 89 // not supply them. |
| 90 var expected = function(field, defaultValue) { |
| 91 return field in stest.expected ? stest.expected[field] : defaultValue; |
| 92 }; |
| 93 |
| 94 var ct = effect.getComputedTiming(); |
| 95 assert_equals(ct.delay, expected("delay", 0), |
| 96 "computed delay"); |
| 97 assert_equals(ct.fill, expected("fill", "none"), |
| 98 "computed fill"); |
| 99 assert_equals(ct.iterations, expected("iterations", 1), |
| 100 "computed iterations"); |
| 101 assert_equals(ct.duration, expected("duration", 0), |
| 102 "computed duration"); |
| 103 assert_equals(ct.direction, expected("direction", "normal"), |
| 104 "computed direction"); |
| 105 |
| 106 }, "values of getComputedTiming() when a KeyframeEffectReadOnly is " + |
| 107 "constructed by " + stest.desc); |
| 108 }); |
| 109 |
| 110 var gActiveDurationTests = [ |
| 111 { desc: "an empty KeyframeEffectOptions object", |
| 112 input: { }, |
| 113 expected: 0 }, |
| 114 { desc: "a non-zero duration and default iteration count", |
| 115 input: { duration: 1000 }, |
| 116 expected: 1000 }, |
| 117 { desc: "a non-zero duration and integral iteration count", |
| 118 input: { duration: 1000, iterations: 7 }, |
| 119 expected: 7000 }, |
| 120 { desc: "a non-zero duration and fractional iteration count", |
| 121 input: { duration: 1000, iterations: 2.5 }, |
| 122 expected: 2500 }, |
| 123 { desc: "an non-zero duration and infinite iteration count", |
| 124 input: { duration: 1000, iterations: Infinity }, |
| 125 expected: Infinity }, |
| 126 { desc: "an non-zero duration and zero iteration count", |
| 127 input: { duration: 1000, iterations: 0 }, |
| 128 expected: 0 }, |
| 129 { desc: "a zero duration and default iteration count", |
| 130 input: { duration: 0 }, |
| 131 expected: 0 }, |
| 132 { desc: "a zero duration and fractional iteration count", |
| 133 input: { duration: 0, iterations: 2.5 }, |
| 134 expected: 0 }, |
| 135 { desc: "a zero duration and infinite iteration count", |
| 136 input: { duration: 0, iterations: Infinity }, |
| 137 expected: 0 }, |
| 138 { desc: "a zero duration and zero iteration count", |
| 139 input: { duration: 0, iterations: 0 }, |
| 140 expected: 0 }, |
| 141 { desc: "an infinite duration and default iteration count", |
| 142 input: { duration: Infinity }, |
| 143 expected: Infinity }, |
| 144 { desc: "an infinite duration and zero iteration count", |
| 145 input: { duration: Infinity, iterations: 0 }, |
| 146 expected: 0 }, |
| 147 { desc: "an infinite duration and fractional iteration count", |
| 148 input: { duration: Infinity, iterations: 2.5 }, |
| 149 expected: Infinity }, |
| 150 { desc: "an infinite duration and infinite iteration count", |
| 151 input: { duration: Infinity, iterations: Infinity }, |
| 152 expected: Infinity }, |
| 153 { desc: "an infinite duration and zero iteration count", |
| 154 input: { duration: Infinity, iterations: 0 }, |
| 155 expected: 0 }, |
| 156 { desc: "a non-zero duration and invalid iteration count", |
| 157 input: { duration: 1000, iterations: "cabbage" }, |
| 158 expected: 1000 } |
| 159 ]; |
| 160 |
| 161 gActiveDurationTests.forEach(function(stest) { |
| 162 test(function(t) { |
| 163 var effect = new KeyframeEffectReadOnly(target, |
| 164 { left: ["10px", "20px"] }, |
| 165 stest.input); |
| 166 |
| 167 assert_equals(effect.getComputedTiming().activeDuration, |
| 168 stest.expected); |
| 169 |
| 170 }, "getComputedTiming().activeDuration for " + stest.desc); |
| 171 }); |
| 172 |
| 173 var gEndTimeTests = [ |
| 174 { desc: "an empty KeyframeEffectOptions object", |
| 175 input: { }, |
| 176 expected: 0 }, |
| 177 { desc: "a non-zero duration and default iteration count", |
| 178 input: { duration: 1000 }, |
| 179 expected: 1000 }, |
| 180 { desc: "a non-zero duration and non-default iteration count", |
| 181 input: { duration: 1000, iterations: 2.5 }, |
| 182 expected: 2500 }, |
| 183 { desc: "a non-zero duration and non-zero delay", |
| 184 input: { duration: 1000, delay: 1500 }, |
| 185 expected: 2500 }, |
| 186 { desc: "a non-zero duration, non-zero delay and non-default iteration", |
| 187 input: { duration: 1000, delay: 1500, iterations: 2 }, |
| 188 expected: 3500 }, |
| 189 { desc: "an infinite iteration count", |
| 190 input: { duration: 1000, iterations: Infinity }, |
| 191 expected: Infinity }, |
| 192 { desc: "an infinite duration", |
| 193 input: { duration: Infinity, iterations: 10 }, |
| 194 expected: Infinity }, |
| 195 { desc: "an infinite duration and delay", |
| 196 input: { duration: Infinity, iterations: 10, delay: 1000 }, |
| 197 expected: Infinity }, |
| 198 { desc: "an infinite duration and negative delay", |
| 199 input: { duration: Infinity, iterations: 10, delay: -1000 }, |
| 200 expected: Infinity }, |
| 201 { desc: "an non-zero duration and negative delay", |
| 202 input: { duration: 1000, iterations: 2, delay: -1000 }, |
| 203 expected: 1000 }, |
| 204 { desc: "an non-zero duration and negative delay greater than active " + |
| 205 "duration", |
| 206 input: { duration: 1000, iterations: 2, delay: -3000 }, |
| 207 expected: -1000 }, |
| 208 { desc: "a zero duration and negative delay", |
| 209 input: { duration: 0, iterations: 2, delay: -1000 }, |
| 210 expected: -1000 } |
| 211 ]; |
| 212 |
| 213 gEndTimeTests.forEach(function(stest) { |
| 214 test(function(t) { |
| 215 var effect = new KeyframeEffectReadOnly(target, |
| 216 { left: ["10px", "20px"] }, |
| 217 stest.input); |
| 218 |
| 219 assert_equals(effect.getComputedTiming().endTime, |
| 220 stest.expected); |
| 221 |
| 222 }, "getComputedTiming().endTime for " + stest.desc); |
| 223 }); |
| 224 |
| 225 done(); |
| 226 </script> |
| 227 </body> |
OLD | NEW |