1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Animatable.animate</title>
<link rel="help" href="https://drafts.csswg.org/web-animations/#dom-animatable-animate">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<script src="../../resources/easing-tests.js"></script>
<script src="../../resources/keyframe-utils.js"></script>
<script src="../../resources/keyframe-tests.js"></script>
<script src="../../resources/timing-utils.js"></script>
<script src="../../resources/timing-tests.js"></script>
<body>
<div id="log"></div>
<iframe width="10" height="10" id="iframe"></iframe>
<script>
'use strict';
// Tests on Element
test(t => {
const anim = createDiv(t).animate(null);
assert_class_string(anim, 'Animation', 'Returned object is an Animation');
}, 'Element.animate() creates an Animation object');
test(t => {
const iframe = window.frames[0];
const div = createDiv(t, iframe.document);
const anim = Element.prototype.animate.call(div, null);
assert_equals(Object.getPrototypeOf(anim), iframe.Animation.prototype,
'The prototype of the created Animation is that defined on'
+ ' the relevant global for the target element');
assert_not_equals(Object.getPrototypeOf(anim), Animation.prototype,
'The prototype of the created Animation is NOT that of'
+ ' the current global');
}, 'Element.animate() creates an Animation object in the relevant realm of'
+ ' the target element');
test(t => {
const div = createDiv(t);
const anim = Element.prototype.animate.call(div, null);
assert_class_string(anim.effect, 'KeyframeEffect',
'Returned Animation has a KeyframeEffect');
}, 'Element.animate() creates an Animation object with a KeyframeEffect');
test(t => {
const iframe = window.frames[0];
const div = createDiv(t, iframe.document);
const anim = Element.prototype.animate.call(div, null);
assert_equals(Object.getPrototypeOf(anim.effect),
iframe.KeyframeEffect.prototype,
'The prototype of the created KeyframeEffect is that defined on'
+ ' the relevant global for the target element');
assert_not_equals(Object.getPrototypeOf(anim.effect),
KeyframeEffect.prototype,
'The prototype of the created KeyframeEffect is NOT that of'
+ ' the current global');
}, 'Element.animate() creates an Animation object with a KeyframeEffect'
+ ' that is created in the relevant realm of the target element');
for (const subtest of gEmptyKeyframeListTests) {
test(t => {
const anim = createDiv(t).animate(subtest, 2000);
assert_not_equals(anim, null);
}, 'Element.animate() accepts empty keyframe lists ' +
`(input: ${JSON.stringify(subtest)})`);
}
for (const subtest of gKeyframesTests) {
test(t => {
const anim = createDiv(t).animate(subtest.input, 2000);
assert_frame_lists_equal(anim.effect.getKeyframes(), subtest.output);
}, `Element.animate() accepts ${subtest.desc}`);
}
for (const subtest of gInvalidKeyframesTests) {
test(t => {
const div = createDiv(t);
assert_throws(new TypeError, () => {
div.animate(subtest.input, 2000);
});
}, `Element.animate() does not accept ${subtest.desc}`);
}
test(t => {
const anim = createDiv(t).animate(null, 2000);
assert_equals(anim.effect.getTiming().duration, 2000);
assert_default_timing_except(anim.effect, ['duration']);
}, 'Element.animate() accepts a double as an options argument');
test(t => {
const anim = createDiv(t).animate(null,
{ duration: Infinity, fill: 'forwards' });
assert_equals(anim.effect.getTiming().duration, Infinity);
assert_equals(anim.effect.getTiming().fill, 'forwards');
assert_default_timing_except(anim.effect, ['duration', 'fill']);
}, 'Element.animate() accepts a KeyframeAnimationOptions argument');
test(t => {
const anim = createDiv(t).animate(null);
assert_default_timing_except(anim.effect, []);
}, 'Element.animate() accepts an absent options argument');
for (const invalid of gBadDelayValues) {
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate(null, { delay: invalid });
});
}, `Element.animate() does not accept invalid delay value: ${invalid}`);
}
test(t => {
const anim = createDiv(t).animate(null, { duration: 'auto' });
assert_equals(anim.effect.getTiming().duration, 'auto', 'set duration \'auto\'');
assert_equals(anim.effect.getComputedTiming().duration, 0,
'getComputedTiming() after set duration \'auto\'');
}, 'Element.animate() accepts a duration of \'auto\' using a dictionary'
+ ' object');
for (const invalid of gBadDurationValues) {
if (typeof invalid === 'string' && !isNaN(parseFloat(invalid))) {
continue;
}
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate(null, invalid);
});
}, 'Element.animate() does not accept invalid duration value: '
+ (typeof invalid === 'string' ? `"${invalid}"` : invalid));
}
for (const invalid of gBadDurationValues) {
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate(null, { duration: invalid });
});
}, 'Element.animate() does not accept invalid duration value: '
+ (typeof invalid === 'string' ? `"${invalid}"` : invalid)
+ ' using a dictionary object');
}
for (const invalidEasing of gInvalidEasings) {
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate({ easing: invalidEasing }, 2000);
});
}, `Element.animate() does not accept invalid easing: '${invalidEasing}'`);
}
for (const invalid of gBadIterationStartValues) {
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate(null, { iterationStart: invalid });
});
}, 'Element.animate() does not accept invalid iterationStart value: ' +
invalid);
}
for (const invalid of gBadIterationsValues) {
test(t => {
assert_throws(new TypeError, () => {
createDiv(t).animate(null, { iterations: invalid });
});
}, 'Element.animate() does not accept invalid iterations value: ' +
invalid);
}
test(t => {
const anim = createDiv(t).animate(null, 2000);
assert_equals(anim.id, '');
}, 'Element.animate() correctly sets the id attribute when no id is specified');
test(t => {
const anim = createDiv(t).animate(null, { id: 'test' });
assert_equals(anim.id, 'test');
}, 'Element.animate() correctly sets the id attribute');
test(t => {
const anim = createDiv(t).animate(null, 2000);
assert_equals(anim.timeline, document.timeline);
}, 'Element.animate() correctly sets the Animation\'s timeline');
async_test(t => {
const iframe = document.createElement('iframe');
iframe.width = 10;
iframe.height = 10;
iframe.addEventListener('load', t.step_func(() => {
const div = createDiv(t, iframe.contentDocument);
const anim = div.animate(null, 2000);
assert_equals(anim.timeline, iframe.contentDocument.timeline);
iframe.remove();
t.done();
}));
document.body.appendChild(iframe);
}, 'Element.animate() correctly sets the Animation\'s timeline when ' +
'triggered on an element in a different document');
test(t => {
const anim = createDiv(t).animate(null, 2000);
assert_equals(anim.playState, 'running');
}, 'Element.animate() calls play on the Animation');
promise_test(async t => {
const div = createDiv(t);
let gotTransition = false;
div.addEventListener('transitionrun', () => {
gotTransition = true;
});
// Setup transition start point.
div.style.transition = 'opacity 100s';
getComputedStyle(div).opacity;
// Update specified style but don't flush style.
div.style.opacity = '0.5';
// Trigger a new animation at the same time.
const anim = div.animate({ opacity: [0, 1] }, 100 * MS_PER_SEC);
// If Element.animate() produces a style change event it will have triggered
// a transition.
//
// If it does NOT produce a style change event, the animation will override
// the before-change style and after-change style such that a transition is
// never triggered.
// Wait for the animation to start and then for one more animation
// frame to give the transitionrun event a chance to be dispatched.
await anim.ready;
await waitForAnimationFrames(1);
assert_false(gotTransition, 'A transition should NOT have been triggered');
}, 'Element.animate() does NOT trigger a style change event');
// Tests on CSSPseudoElement
test(t => {
const pseudoTarget = getPseudoElement(t, 'before');
const anim = pseudoTarget.animate(null);
assert_class_string(anim, 'Animation', 'The returned object is an Animation');
}, 'CSSPseudoElement.animate() creates an Animation object');
test(t => {
const pseudoTarget = getPseudoElement(t, 'marker');
const anim = pseudoTarget.animate(null);
assert_class_string(anim, 'Animation', 'The returned object is an Animation for ::marker');
}, 'CSSPseudoElement.animate() creates an Animation object for ::marker');
test(t => {
const pseudoTarget = getPseudoElement(t, 'before');
const anim = pseudoTarget.animate(null);
assert_equals(anim.effect.target, pseudoTarget,
'The returned Animation targets to the correct object');
}, 'CSSPseudoElement.animate() creates an Animation object targeting ' +
'to the correct CSSPseudoElement object');
test(t => {
const pseudoTarget = getPseudoElement(t, 'marker');
const anim = pseudoTarget.animate(null);
assert_equals(anim.effect.target, pseudoTarget,
'The returned Animation targets to the correct object for ::marker');
}, 'CSSPseudoElement.animate() creates an Animation object targeting ' +
'to the correct CSSPseudoElement object for ::marker');
</script>
</body>
|