testing/web-platform/tests/web-animations/interfaces/KeyframeEffect/target.html
author Brian Birtles <birtles@gmail.com>
Fri, 10 Nov 2017 16:42:50 +0900
changeset 696132 48ffae92bb706796bbd4605f24d273221c093487
parent 696131 testing/web-platform/tests/web-animations/interfaces/KeyframeEffect/setTarget.html@1501d18b1fe1b51c6f992bfbbaf70c3cfeb73978
child 698820 44c2ebf6b9c62da63367bde5d08a7ac39a1851e9
permissions -rw-r--r--
Bug 1415448 - Rename setTarget.html to target.html; r?hiro This matches better the naming of other test files. MozReview-Commit-ID: KZ1VihXYhUQ

<!DOCTYPE html>
<meta charset=utf-8>
<title>KeyframeEffect.target</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>