Bug 1067769 - Part 3: Test for KeyframeEffectReadOnly with null target. r=birtles draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 28 Apr 2016 23:22:42 +0800
changeset 357389 44b919cb3e227a3aa6b2d0adce582d4e8338b8f9
parent 357388 4ba2d616d6b2cdfe7985ced29e4454e818d076b8
child 357390 4cb041aea661f2355bd693e983e407f9df6838b5
push id16759
push userbchiou@mozilla.com
push dateThu, 28 Apr 2016 15:27:13 +0000
reviewersbirtles
bugs1067769
milestone49.0a1
Bug 1067769 - Part 3: Test for KeyframeEffectReadOnly with null target. r=birtles MozReview-Commit-ID: DQ5k6W1bgUC
dom/animation/test/chrome/test_animation_observers.html
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/web-animations/animation/constructor.html
testing/web-platform/tests/web-animations/animation/finish.html
testing/web-platform/tests/web-animations/document/getAnimations.html
testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
--- a/dom/animation/test/chrome/test_animation_observers.html
+++ b/dom/animation/test/chrome/test_animation_observers.html
@@ -1713,16 +1713,31 @@ addAsyncAnimTest("exclude_animations_tar
 
   anim.finish();
   pAnim.finish();
   yield await_frame();
   assert_records([{ added: [], changed: [], removed: [anim] }],
                  "records after animation is finished");
 });
 
+addAsyncAnimTest("create_animation_without_target",
+                 { observe: document, subtree: true }, function*() {
+  var effect = new KeyframeEffectReadOnly(null,
+                                          { opacity: [ 0, 1 ] },
+                                          { duration: 10000 });
+  var anim = new Animation(effect, document.timeline);
+  anim.play();
+  yield await_frame();
+  assert_records([], "no records after animation is added");
+
+  anim.cancel();
+  yield await_frame();
+  assert_records([], "no records after animation is removed");
+});
+
 // Run the tests.
 SimpleTest.requestLongerTimeout(2);
 SimpleTest.waitForExplicitFinish();
 
 runAllAsyncTests().then(function() {
   SimpleTest.finish();
 }, function(aError) {
   ok(false, "Something failed: " + aError);
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -28845,16 +28845,20 @@
         "path": "web-animations/animation/ready.html",
         "url": "/web-animations/animation/ready.html"
       },
       {
         "path": "web-animations/animation/reverse.html",
         "url": "/web-animations/animation/reverse.html"
       },
       {
+        "path": "web-animations/document/getAnimations.html",
+        "url": "/web-animations/document/getAnimations.html"
+      },
+      {
         "path": "web-animations/keyframe-effect/constructor.html",
         "url": "/web-animations/keyframe-effect/constructor.html"
       },
       {
         "path": "web-animations/keyframe-effect/effect-easing.html",
         "url": "/web-animations/keyframe-effect/effect-easing.html"
       },
       {
--- a/testing/web-platform/tests/web-animations/animation/constructor.html
+++ b/testing/web-platform/tests/web-animations/animation/constructor.html
@@ -50,10 +50,24 @@ gTestArguments.forEach(function(args) {
     assert_equals(animation.timeline, args.timeline,
                   "Animation returns the same timeline passed to " +
                   "the Constructor");
     assert_equals(animation.playState, "idle",
                   "Animation.playState should be initially 'idle'");
   }, "Animation can be constructed " + args.description);
 });
 
+test(function(t) {
+  var effect = new KeyframeEffectReadOnly(null,
+                                          { left: ["10px", "20px"] },
+                                          { duration: 10000,
+                                            fill: "forwards" });
+  var anim = new Animation(effect, document.timeline);
+  anim.pause();
+  assert_equals(effect.getComputedTiming().progress, 0.0);
+  anim.currentTime += 5000;
+  assert_equals(effect.getComputedTiming().progress, 0.5);
+  anim.finish();
+  assert_equals(effect.getComputedTiming().progress, 1.0);
+}, "Animation constructed by an effect with null target runs normally");
+
 </script>
 </body>
--- a/testing/web-platform/tests/web-animations/animation/finish.html
+++ b/testing/web-platform/tests/web-animations/animation/finish.html
@@ -198,10 +198,50 @@ promise_test(function(t) {
   return animation.ready.then(function() {
     animation.finish();
   }).then(function() {
     assert_true(resolvedFinished,
       'Animation.finished should be resolved soon after ' +
       'Animation.finish()');
   });
 }, 'Test finish() resolves finished promise synchronously');
+
+promise_test(function(t) {
+  var effect = new KeyframeEffectReadOnly(null, gKeyFrames, 100 * MS_PER_SEC);
+  var animation = new Animation(effect, document.timeline);
+  var resolvedFinished = false;
+  animation.finished.then(function() {
+    resolvedFinished = true;
+  });
+
+  return animation.ready.then(function() {
+    animation.finish();
+  }).then(function() {
+    assert_true(resolvedFinished,
+                'Animation.finished should be resolved soon after ' +
+                'Animation.finish()');
+  });
+}, 'Test finish() resolves finished promise synchronously with an animation ' +
+   'without a target');
+
+promise_test(function(t) {
+  var effect = new KeyframeEffectReadOnly(null, gKeyFrames, 100 * MS_PER_SEC);
+  var animation = new Animation(effect, document.timeline);
+  animation.play();
+
+  var resolvedFinished = false;
+  animation.finished.then(function() {
+    resolvedFinished = true;
+  });
+
+  return animation.ready.then(function() {
+    animation.currentTime = animation.effect.getComputedTiming().endTime - 1;
+    return waitForAnimationFrames(2);
+  }).then(function() {
+    assert_true(resolvedFinished,
+                'Animation.finished should be resolved soon after ' +
+                'Animation finishes normally');
+  });
+}, 'Test normally finished animation resolves finished promise synchronously ' +
+   'with an animation without a target');
+
 </script>
 </body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/web-animations/document/getAnimations.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>document.getAnimations tests</title>
+<link rel="help" href="https://w3c.github.io/web-animations/#dom-document-getanimations">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../testcommon.js"></script>
+<body>
+<div id="log"></div>
+<div id="target"></div>
+<script>
+"use strict";
+
+test(function(t) {
+  var effect = new KeyframeEffectReadOnly(null,
+                                          { left: ['10px', '20px'] },
+                                          100 * MS_PER_SEC);
+  var anim = new Animation(effect, document.timeline);
+  anim.play();
+
+  assert_equals(document.getAnimations().length, 0,
+                'document.getAnimations() only returns animations targeting ' +
+                'elements in this document');
+}, 'Test document.getAnimations with null target');
+
+</script>
+</body>
--- a/testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
+++ b/testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
@@ -242,16 +242,25 @@ gInvalidKeyframeEffectOptionTests.forEac
       new KeyframeEffectReadOnly(target,
                                  { left: ["10px", "20px"] },
                                  stest.input);
     });
   }, "Invalid KeyframeEffectReadOnly option by " + stest.desc);
 });
 
 test(function(t) {
+  var effect = new KeyframeEffectReadOnly(null,
+                                          { left: ["10px", "20px"] },
+                                          { duration: 100 * MS_PER_SEC,
+                                            fill: "forwards" });
+  assert_equals(effect.target, null,
+                "Effect created with null target has correct target");
+}, "a KeyframeEffectReadOnly constructed with null target");
+
+test(function(t) {
   var effect = new KeyframeEffect(target, null);
   assert_class_string(effect, "KeyframeEffect");
   assert_class_string(effect.timing, "AnimationEffectTiming");
 }, "KeyframeEffect constructor creates an AnimationEffectTiming timing object");
 
 test(function(t) {
   var test_error = { name: "test" };