[Web Animations] Update WPT tests and move them to imported/w3c/web-platform-tests
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / web-animations / interfaces / Document / getAnimations.html
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>Document.getAnimations</title>
4 <link rel="help" href="https://drafts.csswg.org/web-animations/#dom-document-getanimations">
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script src="../../testcommon.js"></script>
8 <body>
9 <div id="log"></div>
10 <div id="target"></div>
11 <script>
12 'use strict';
13
14 const gKeyFrames = { 'marginLeft': ['100px', '200px'] };
15
16 test(t => {
17   assert_equals(document.getAnimations().length, 0,
18                 'getAnimations returns an empty sequence for a document ' +
19                 'with no animations');
20 }, 'Test document.getAnimations for non-animated content');
21
22 test(t => {
23   const div = createDiv(t);
24   const anim1 = div.animate(gKeyFrames, 100 * MS_PER_SEC);
25   const anim2 = div.animate(gKeyFrames, 100 * MS_PER_SEC);
26   assert_equals(document.getAnimations().length, 2,
27                 'getAnimation returns running animations');
28
29   anim1.finish();
30   anim2.finish();
31   assert_equals(document.getAnimations().length, 0,
32                 'getAnimation only returns running animations');
33 }, 'Test document.getAnimations for script-generated animations')
34
35 test(t => {
36   const div = createDiv(t);
37   const anim1 = div.animate(gKeyFrames, 100 * MS_PER_SEC);
38   const anim2 = div.animate(gKeyFrames, 100 * MS_PER_SEC);
39   assert_array_equals(document.getAnimations(),
40                       [ anim1, anim2 ],
41                       'getAnimations() returns running animations');
42 }, 'Test the order of document.getAnimations with script generated animations')
43
44 test(t => {
45   const effect = new KeyframeEffectReadOnly(null, gKeyFrames, 100 * MS_PER_SEC);
46   const anim = new Animation(effect, document.timeline);
47   anim.play();
48
49   assert_equals(document.getAnimations().length, 0,
50                 'document.getAnimations() only returns animations targeting ' +
51                 'elements in this document');
52 }, 'Test document.getAnimations with null target');
53
54 </script>
55 </body>