Bug 1067769 - Part 13: Test for setting the target in basic cases. r=birtles draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 28 Apr 2016 23:22:44 +0800
changeset 357399 9620f2a3bbaed34456e340ccef5738272beb954d
parent 357398 7ef6e5d70104942b21671e2143c107e678f400a7
child 357400 218ac06dcb2b9d75d4078c66aa0f112678d42ba0
push id16759
push userbchiou@mozilla.com
push dateThu, 28 Apr 2016 15:27:13 +0000
reviewersbirtles
bugs1067769
milestone49.0a1
Bug 1067769 - Part 13: Test for setting the target in basic cases. r=birtles MozReview-Commit-ID: HG1Ttqzkti7
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/web-animations/keyframe-effect/setTarget.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -35389,16 +35389,22 @@
           }
         ],
         "web-animations/animation/startTime.html": [
           {
             "path": "web-animations/animation/startTime.html",
             "url": "/web-animations/animation/startTime.html"
           }
         ],
+        "web-animations/keyframe-effect/setTarget.html": [
+          {
+            "path": "web-animations/keyframe-effect/setTarget.html",
+            "url": "/web-animations/keyframe-effect/setTarget.html"
+          }
+        ],
         "web-animations/timing-model/animation-effects/active-time.html": [
           {
             "path": "web-animations/timing-model/animation-effects/active-time.html",
             "url": "/web-animations/timing-model/animation-effects/active-time.html"
           }
         ],
         "web-animations/timing-model/animation-effects/current-iteration.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/web-animations/keyframe-effect/setTarget.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Writable effect.target tests</title>
+<link rel="help"
+  href="https://w3c.github.io/web-animations/#dom-keyframeeffect-target">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../testcommon.js"></script>
+<body>
+<div id="log"></div>
+<script>
+"use strict";
+
+var gKeyFrames = { 'marginLeft': ['0px', '100px'] };
+
+test(function(t) {
+  var div = createDiv(t);
+  var effect = new KeyframeEffect(null, gKeyFrames, 100 * MS_PER_SEC);
+  effect.target = div;
+
+  var anim = new Animation(effect, document.timeline);
+  anim.play();
+
+  anim.currentTime = 50 * MS_PER_SEC;
+  assert_equals(getComputedStyle(div).marginLeft, '50px',
+                'Value at 50% progress');
+}, 'Test setting target before constructing the associated animation');
+
+test(function(t) {
+  var div = createDiv(t);
+  div.style.marginLeft = '10px';
+  var effect = new KeyframeEffect(null, gKeyFrames, 100 * MS_PER_SEC);
+  var anim = new Animation(effect, document.timeline);
+  anim.play();
+
+  anim.currentTime = 50 * MS_PER_SEC;
+  assert_equals(getComputedStyle(div).marginLeft, '10px',
+                'Value at 50% progress before setting new target');
+  effect.target = div;
+  assert_equals(getComputedStyle(div).marginLeft, '50px',
+                'Value at 50% progress after setting new target');
+}, 'Test setting target from null to a valid target');
+
+test(function(t) {
+  var div = createDiv(t);
+  div.style.marginLeft = '10px';
+  var anim = div.animate(gKeyFrames, 100 * MS_PER_SEC);
+
+  anim.currentTime = 50 * MS_PER_SEC;
+  assert_equals(getComputedStyle(div).marginLeft, '50px',
+                'Value at 50% progress before clearing the target')
+
+  anim.effect.target = null;
+  assert_equals(getComputedStyle(div).marginLeft, '10px',
+                'Value after clearing the target')
+}, 'Test setting target from a valid target to null');
+
+test(function(t) {
+  var a = createDiv(t);
+  var b = createDiv(t);
+  a.style.marginLeft = '10px';
+  b.style.marginLeft = '20px';
+  var anim = a.animate(gKeyFrames, 100 * MS_PER_SEC);
+
+  anim.currentTime = 50 * MS_PER_SEC;
+  assert_equals(getComputedStyle(a).marginLeft, '50px',
+                'Value of 1st element (currently targeted) before ' +
+                'changing the effect target');
+  assert_equals(getComputedStyle(b).marginLeft, '20px',
+                'Value of 2nd element (currently not targeted) before ' +
+                'changing the effect target');
+  anim.effect.target = b;
+  assert_equals(getComputedStyle(a).marginLeft, '10px',
+                'Value of 1st element (currently not targeted) after ' +
+                'changing the effect target');
+  assert_equals(getComputedStyle(b).marginLeft, '50px',
+                'Value of 2nd element (currently targeted) after ' +
+                'changing the effect target');
+
+  // This makes sure the animation property is changed correctly on new
+  // targeted element.
+  anim.currentTime = 75 * MS_PER_SEC;
+  assert_equals(getComputedStyle(b).marginLeft, '75px',
+                'Value of 2nd target (currently targeted) after ' +
+                'changing the animation current time.');
+}, 'Test setting target from a valid target to another target');
+
+</script>
+</body>