| 12
 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
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 
 | <!doctype html>
<meta charset=utf-8>
<title>CSSTransition.effect</title>
<!-- TODO: Add a more specific link for this once it is specified. -->
<link rel="help" href="https://drafts.csswg.org/css-transitions-2/#csstransition">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='support/helper.js'></script>
<div id="log"></div>
<script>
'use strict';
function singleFrame() {
  return new Promise((resolve, reject) => {
    requestAnimationFrame(resolve);
  });
}
test(t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  transition.effect = null;
  assert_equals(transition.transitionProperty, 'left');
}, 'After setting a transition\'s effect to null, it still reports the'
   + ' original transition property');
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  await transition.ready;
  transition.effect = null;
  assert_equals(transition.playState, 'finished');
}, 'After setting a transition\'s effect to null, it becomes finished');
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  await transition.ready;
  transition.effect = null;
  assert_equals(getComputedStyle(div).left, '100px');
}, 'After setting a transition\'s effect to null, style is updated');
// This is a regression test for https://crbug.com/964113, where Chromium would
// crash if the running transition's effect was set to null and a new transition
// was started before the running one could finish.
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  assert_equals(div.getAnimations().length, 1);
  const transition = div.getAnimations()[0];
  await transition.ready;
  // Without yielding to the rendering loop, set the current transition's
  // effect to null and start a new transition. This should work correctly.
  transition.effect = null;
  div.style.left = '150px';
  // This will run style update.
  assert_equals(div.getAnimations().length, 1);
  const new_transition = div.getAnimations()[0];
  await new_transition.ready;
  assert_equals(getComputedStyle(div).left, '100px');
}, 'After setting a transition\'s effect to null, a new transition can be started');
// This is a regression test for https://crbug.com/992668, where Chromium would
// crash if the running transition's effect was set to null and the transition
// was interrupted before it could finish due to the null effect.
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  assert_equals(div.getAnimations().length, 1);
  const transition = div.getAnimations()[0];
  await transition.ready;
  // The transition needs to have a non-zero currentTime for the interruption
  // reversal logic to apply.
  while (getComputedStyle(div).left == '0px') {
    await singleFrame();
  }
  assert_not_equals(transition.currentTime, 0);
  // Without yielding to the rendering loop, set the current transition's
  // effect to null and interrupt the transition. This should work correctly.
  transition.effect = null;
  div.style.left = '0px';
  // Yield to the rendering loop. This should not crash.
  await singleFrame();
}, 'After setting a transition\'s effect to null, it should be possible to '
    + 'interrupt that transition');
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.width = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  await transition.ready;
  transition.currentTime = 50 * MS_PER_SEC;
  transition.effect = new KeyframeEffect(div,
                                         { left: [ '0px' , '100px'] },
                                         20 * MS_PER_SEC);
  assert_equals(transition.playState, 'finished');
}, 'After setting a new keyframe effect with a shorter duration,'
   + ' the transition becomes finished');
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.width = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  transition.effect = new KeyframeEffect(div,
                                         { marginLeft: [ '0px' , '100px'] },
                                         100 * MS_PER_SEC);
  assert_equals(transition.transitionProperty, 'left');
}, 'After setting a new keyframe effect targeting different properties,'
   + ' the transition continues to report the original transition property');
promise_test(async t => {
  const div = addDiv(t);
  div.style.left = '0px';
  div.style.width = '0px';
  div.style.transition = 'left 100s';
  getComputedStyle(div).left;
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  assert_true(transition.pending);
  transition.effect = new KeyframeEffect(div,
                                         { marginLeft: [ '0px' , '100px'] },
                                         100 * MS_PER_SEC);
  assert_true(transition.pending);
  // As a sanity check, check that the transition actually exits the
  // pending state.
  await transition.ready;
  assert_false(transition.pending);
}, 'After setting a new keyframe effect on a play-pending transition,'
   + ' the transition remains pending');
test(t => {
  const div = addDiv(t);
  div.style.left = '0px';
  getComputedStyle(div).transitionProperty;
  div.style.transition = 'left 100s';
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  transition.effect = null;
  assert_equals(transition.transitionProperty, 'left');
}, 'A transition with no effect still returns the original transitionProperty');
test(t => {
  const div = addDiv(t);
  div.style.left = '0px';
  getComputedStyle(div).transitionProperty;
  div.style.transition = 'left 100s';
  div.style.left = '100px';
  const transition = div.getAnimations()[0];
  // Seek to the middle and get the portion.
  transition.currentTime = 50 * MS_PER_SEC;
  const portion = transition.effect.getComputedTiming().progress;
  // Replace the effect but keep the original timing
  transition.effect = new KeyframeEffect(
    div,
    { top: ['200px', '300px', '100px'] },
    transition.effect.getTiming()
  );
  // Reverse the transition
  div.style.left = '0px';
  const reversedTransition = div.getAnimations()[0];
  const expectedDuration = 100 * MS_PER_SEC * portion;
  assert_approx_equals(
    reversedTransition.effect.getComputedTiming().activeDuration,
    expectedDuration,
    1
  );
}, 'A transition with a replaced effect still exhibits the regular transition'
   + ' reversing behavior');
</script>
 |