summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-animations/animation-model/keyframe-effects/effect-value-context.html
blob: 07fb6097c9fed469b6d7a0fc11bc09c710a0750e (plain)
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
<!DOCTYPE html>
<meta charset=utf-8>
<title>Tests that property values respond to changes to their context</title>
<link rel="help" href="https://w3c.github.io/web-animations/#keyframes-section">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<body>
<div id="log"></div>
<script>

test(function(t) {
  var div = createDiv(t);
  div.style.fontSize = '10px';
  var animation = div.animate([ { marginLeft: '10em' },
                                { marginLeft: '20em' } ], 1000);
  animation.currentTime = 500;
  assert_equals(getComputedStyle(div).marginLeft, '150px',
                'Effect value before updating font-size');
  div.style.fontSize = '20px';
  assert_equals(getComputedStyle(div).marginLeft, '300px',
                'Effect value after updating font-size');
}, 'Effect values reflect changes to font-size on element');

test(function(t) {
  var parentDiv = createDiv(t);
  var div = createDiv(t);
  parentDiv.appendChild(div);
  parentDiv.style.fontSize = '10px';

  var animation = div.animate([ { marginLeft: '10em' },
                                { marginLeft: '20em' } ], 1000);
  animation.currentTime = 500;
  assert_equals(getComputedStyle(div).marginLeft, '150px',
                'Effect value before updating font-size on parent element');
  parentDiv.style.fontSize = '20px';
  assert_equals(getComputedStyle(div).marginLeft, '300px',
                'Effect value after updating font-size on parent element');
}, 'Effect values reflect changes to font-size on parent element');

promise_test(function(t) {
  var parentDiv = createDiv(t);
  var div = createDiv(t);
  parentDiv.appendChild(div);
  parentDiv.style.fontSize = '10px';
  var animation = div.animate([ { marginLeft: '10em' },
                                { marginLeft: '20em' } ], 1000);

  animation.pause();
  animation.currentTime = 500;
  parentDiv.style.fontSize = '20px';

  return animation.ready.then(function() {
    assert_equals(getComputedStyle(div).marginLeft, '300px',
                  'Effect value after updating font-size on parent element');
  });
}, 'Effect values reflect changes to font-size when computed style is not'
   + ' immediately flushed');

promise_test(function(t) {
  var divWith10pxFontSize = createDiv(t);
  divWith10pxFontSize.style.fontSize = '10px';
  var divWith20pxFontSize = createDiv(t);
  divWith20pxFontSize.style.fontSize = '20px';

  var div = createDiv(t);
  div.remove(); // Detach
  var animation = div.animate([ { marginLeft: '10em' },
                                { marginLeft: '20em' } ], 1000);
  animation.pause();

  return animation.ready.then(function() {
    animation.currentTime = 500;

    divWith10pxFontSize.appendChild(div);
    assert_equals(getComputedStyle(div).marginLeft, '150px',
                  'Effect value after attaching to font-size:10px parent');
    divWith20pxFontSize.appendChild(div);
    assert_equals(getComputedStyle(div).marginLeft, '300px',
                  'Effect value after attaching to font-size:20px parent');
  });
}, 'Effect values reflect changes to font-size from reparenting');

test(function(t) {
  var divA = createDiv(t);
  divA.style.fontSize = '10px';

  var divB = createDiv(t);
  divB.style.fontSize = '20px';

  var animation = divA.animate([ { marginLeft: '10em' },
                                 { marginLeft: '20em' } ], 1000);
  animation.currentTime = 500;
  assert_equals(getComputedStyle(divA).marginLeft, '150px',
                'Effect value before updating target element');

  animation.effect.target = divB;
  assert_equals(getComputedStyle(divB).marginLeft, '300px',
                'Effect value after updating target element');
}, 'Effect values reflect changes to target element');

</script>
</body>