| 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
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 
 | <!doctype html>
<meta charset=utf-8>
<title>Scroll based animation: AnimationEffect.updateTiming</title>
<!-- Adapted to progressed based scroll animations from "wpt\web-animations\interfaces\AnimationEffect\updateTiming.html" -->
<link rel="help" href="https://drafts.csswg.org/web-animations-1/#dom-animationeffect-updatetiming">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="testcommon.js"></script>
<script src="/web-animations/resources/easing-tests.js"></script>
<script src="/web-animations/resources/timing-tests.js"></script>
<style>
  .scroller {
    overflow: auto;
    height: 100px;
    width: 100px;
    will-change: transform;
  }
  .contents {
    height: 1000px;
    width: 100%;
  }
</style>
<body>
<div id="log"></div>
<script>
'use strict';
// ------------------------------
//  delay
// ------------------------------
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, {duration: 1000, delay: 200})
  anim.play();
  assert_equals(anim.effect.getTiming().delay, 200, 'initial delay 200');
  assert_equals(anim.effect.getComputedTiming().delay, 200,
                'getComputedTiming() initially delay 200');
  anim.effect.updateTiming({ delay: 100 });
  assert_equals(anim.effect.getTiming().delay, 100, 'set delay 100');
  assert_equals(anim.effect.getComputedTiming().delay, 100,
                'getComputedTiming() after set delay 100');
}, 'Allows setting the delay to a positive number');
test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t, {duration: 100, delay: -100})
  anim.play();
  anim.effect.updateTiming({ delay: -100 });
  assert_equals(anim.effect.getTiming().delay, -100, 'set delay -100');
  assert_equals(anim.effect.getComputedTiming().delay, -100,
                'getComputedTiming() after set delay -100');
  assert_percents_equal(anim.effect.getComputedTiming().endTime, 0,
                        'getComputedTiming().endTime after set delay -100');
}, 'Allows setting the delay to a negative number');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, {duration: 100})
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ delay: 100 });
  assert_equals(anim.effect.getComputedTiming().progress, null);
  assert_equals(anim.effect.getComputedTiming().currentIteration, null);
}, 'Allows setting the delay of an animation in progress: positive delay that'
   + ' causes the animation to be no longer in-effect');
promise_test(async t => {
  const anim =
      createScrollLinkedAnimationWithTiming(t, { fill: 'both', duration: 100 });
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ delay: -50 });
  assert_equals(anim.effect.getComputedTiming().progress, 0.5);
}, 'Allows setting the delay of an animation in progress: negative delay that'
   + ' seeks into the active interval');
promise_test(async t => {
  const anim =
      createScrollLinkedAnimationWithTiming(t, { fill: 'both', duration: 100 });
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ delay: -100 });
  assert_equals(anim.effect.getComputedTiming().progress, 1);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0);
}, 'Allows setting the delay of an animation in progress: large negative delay'
   + ' that causes the animation to be finished');
for (const invalid of gBadDelayValues) {
  test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t)
  anim.play();
    assert_throws_js(TypeError, () => {
      anim.effect.updateTiming({ delay: invalid });
    });
  }, `Throws when setting invalid delay value: ${invalid}`);
}
// ------------------------------
//  endDelay
// ------------------------------
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ endDelay: 123.45 });
  assert_time_equals_literal(anim.effect.getTiming().endDelay, 123.45,
                             'set endDelay 123.45');
  assert_time_equals_literal(anim.effect.getComputedTiming().endDelay, 123.45,
                             'getComputedTiming() after set endDelay 123.45');
}, 'Allows setting the endDelay to a positive number');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ endDelay: -1000 });
  assert_equals(anim.effect.getTiming().endDelay, -1000, 'set endDelay -1000');
  assert_equals(anim.effect.getComputedTiming().endDelay, -1000,
                'getComputedTiming() after set endDelay -1000');
}, 'Allows setting the endDelay to a negative number');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  await anim.ready;
  assert_throws_js(TypeError, () => {
    anim.effect.updateTiming({ endDelay: Infinity });
  });
}, 'Throws when setting the endDelay to infinity');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  await anim.ready;
  assert_throws_js(TypeError, () => {
    anim.effect.updateTiming({ endDelay: -Infinity });
  });
}, 'Throws when setting the endDelay to negative infinity');
// ------------------------------
//  fill
// ------------------------------
for (const fill of ['none', 'forwards', 'backwards', 'both']) {
  test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 100 })
  anim.play();
    anim.effect.updateTiming({ fill });
    assert_equals(anim.effect.getTiming().fill, fill, 'set fill ' + fill);
    assert_equals(anim.effect.getComputedTiming().fill, fill,
                  'getComputedTiming() after set fill ' + fill);
  }, `Allows setting the fill to '${fill}'`);
}
// ------------------------------
//  iterationStart
// ------------------------------
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { iterationStart: 0.2,
                                      iterations: 1,
                                      fill: 'both',
                                      duration: 100,
                                      delay: 1 })
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ iterationStart: 2.5 });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.5);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 2);
}, 'Allows setting the iterationStart of an animation in progress:'
   + ' backwards-filling');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { iterationStart: 0.2,
                                      iterations: 1,
                                      fill: 'both',
                                      duration: 100,
                                      delay: 0 })
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ iterationStart: 2.5 });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.5);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 2);
}, 'Allows setting the iterationStart of an animation in progress:'
   + ' active phase');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { iterationStart: 0.3,
                                      iterations: 1,
                                      fill: 'both',
                                      duration: 200,
                                      delay: 0 })
  anim.play();
  await anim.ready;
  assert_percents_equal(anim.currentTime, 0);
  assert_percents_equal(anim.effect.getComputedTiming().localTime, 0,
                        "localTime");
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.3);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0);
  anim.finish();
  assert_percents_equal(anim.currentTime, 100);
  assert_percents_equal(anim.effect.getComputedTiming().localTime, 100,
                        "localTime");
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.3);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 1);
  anim.effect.updateTiming({ iterationStart: 2.5 });
  assert_percents_equal(anim.currentTime, 100);
  assert_percents_equal(anim.effect.getComputedTiming().localTime, 100,
                        "localTime");
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.5);
  assert_equals(anim.effect.getComputedTiming().currentIteration, 3);
}, 'Allows setting the iterationStart of an animation in progress:'
   + ' forwards-filling');
for (const invalid of gBadIterationStartValues) {
  test(t => {
    const anim = createScrollLinkedAnimationWithTiming(t)
    anim.play();
    assert_throws_js(TypeError, () => {
      anim.effect.updateTiming({ iterationStart: invalid });
    }, `setting ${invalid}`);
  }, `Throws when setting invalid iterationStart value: ${invalid}`);
}
// ------------------------------
//  iterations
// ------------------------------
test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  anim.effect.updateTiming({ iterations: 2 });
  assert_equals(anim.effect.getTiming().iterations, 2, 'set duration 2');
  assert_equals(anim.effect.getComputedTiming().iterations, 2,
                'getComputedTiming() after set iterations 2');
}, 'Allows setting iterations to a double value');
test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  assert_throws_js(TypeError, () => {
    anim.effect.updateTiming({ iterations: Infinity });
  }, "test");
}, `Throws when setting iterations to Infinity`);
// progress based animations behave a bit differently than time based animations
// when changing iterations.
test(t => {
  const anim =
      createScrollLinkedAnimationWithTiming(
          t, { duration: 100000, fill: 'both' });
  anim.play();
  anim.finish();
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress when animation is finished');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 100,
                        'duration when animation is finished');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0,
                'current iteration when animation is finished');
  anim.effect.updateTiming({ iterations: 2 });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after adding an iteration');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 50,
                        'duration after adding an iteration');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 1,
                'current iteration after adding an iteration');
  anim.effect.updateTiming({ iterations: 4 });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after setting iterations to 4');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 25,
                        'duration after setting iterations to 4');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 3,
                'current iteration after setting iterations to 4');
  anim.effect.updateTiming({ iterations: 0 });
  assert_equals(anim.effect.getComputedTiming().progress, 0,
                'progress after setting iterations to zero');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 0,
                        'duration after setting iterations to zero');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0,
                'current iteration after setting iterations to zero');
}, 'Allows setting the iterations of an animation in progress');
// Added test for checking duration "auto"
test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t,  { fill: 'both' });
  anim.play();
  anim.finish();
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress when animation is finished');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 100,
                        'duration when animation is finished');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0,
                'current iteration when animation is finished');
  anim.effect.updateTiming({ iterations: 2 });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after adding an iteration');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 50,
                        'duration after adding an iteration');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 1,
                'current iteration after adding an iteration');
  anim.effect.updateTiming({ iterations: 4 });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after setting iterations to 4');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 25,
                        'duration after setting iterations to 4');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 3,
                'current iteration after setting iterations to 4');
  anim.effect.updateTiming({ iterations: 0 });
  assert_equals(anim.effect.getComputedTiming().progress, 0,
                'progress after setting iterations to zero');
  assert_percents_equal(anim.effect.getComputedTiming().duration, 0,
                        'duration after setting iterations to zero');
  assert_equals(anim.effect.getComputedTiming().currentIteration, 0,
                'current iteration after setting iterations to zero');
}, 'Allows setting the iterations of an animation in progress with duration ' +
   '"auto"');
// ------------------------------
//  duration
// ------------------------------
// adapted for progress based animations
const gGoodDurationValuesForProgressBased = [
  // until duration returns a CSSNumberish which can handle percentages, 100%
  // will be represented as 100
  { specified: 123.45, computed: 100 },
  { specified: 'auto', computed: 100 },
];
for (const duration of gGoodDurationValuesForProgressBased) {
  test(t => {
    const anim = createScrollLinkedAnimationWithTiming(t, 2000);
    anim.play();
    anim.effect.updateTiming({ duration: duration.specified });
    if (typeof duration.specified === 'number') {
      assert_time_equals_literal(anim.effect.getTiming().duration,
                                 duration.specified,
                                 'Updates specified duration');
    } else {
      assert_equals(anim.effect.getTiming().duration, duration.specified,
                    'Updates specified duration');
    }
    assert_percents_equal(anim.effect.getComputedTiming().duration,
                          duration.computed,
                          'Updates computed duration');
  }, `Allows setting the duration to ${duration.specified}`);
}
// adapted for progress based animations
const gBadDurationValuesForProgressBased = [
  -1, NaN, Infinity, -Infinity, 'abc', '100'
];
for (const invalid of gBadDurationValuesForProgressBased) {
  test(t => {
    assert_throws_js(TypeError, () => {
      const anim = createScrollLinkedAnimationWithTiming(t,  { duration: invalid })
      anim.play();
    });
  }, 'Throws when setting invalid duration: '
     + (typeof invalid === 'string' ? `"${invalid}"` : invalid));
}
test(t => {
  const anim =
      createScrollLinkedAnimationWithTiming(
          t, { duration: 100000, fill: 'both' });
  anim.play();
  anim.finish();
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress when animation is finished');
  anim.effect.updateTiming({ duration: anim.effect.getTiming().duration * 2 });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 1,
                             'progress after doubling the duration');
  anim.effect.updateTiming({ duration: 0 });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after setting duration to zero');
  anim.effect.updateTiming({ duration: 'auto' });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after setting duration to \'auto\'');
}, 'Allows setting the duration of an animation in progress');
promise_test(t => {
  const anim =
      createScrollLinkedAnimationWithTiming(
          t,  { duration: 100000, fill: 'both' });
  anim.play();
  return anim.ready.then(() => {
    const originalStartTime   = anim.startTime;
    const originalCurrentTime = anim.currentTime;
    assert_percents_equal(
      anim.effect.getComputedTiming().duration,
      100,
      'Initial duration should be as set on KeyframeEffect'
    );
    anim.effect.updateTiming({ duration: 200000 });
    assert_percents_equal(
      anim.effect.getComputedTiming().duration,
      100,
      'Effect duration should remain at 100% for progress based animations'
    );
    assert_percents_equal(anim.startTime, originalStartTime,
                          'startTime should be unaffected by changing effect ' +
                          'duration');
    assert_percents_equal(anim.currentTime, originalCurrentTime,
                          'currentTime should be unaffected by changing ' +
                          'effect duration');
  });
}, 'Allows setting the duration of an animation in progress such that the' +
   ' the start and current time do not change');
// ------------------------------
//  direction
// ------------------------------
test(t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { duration: 2000 });
  anim.play();
  const directions = ['normal', 'reverse', 'alternate', 'alternate-reverse'];
  for (const direction of directions) {
    anim.effect.updateTiming({ direction: direction });
    assert_equals(anim.effect.getTiming().direction, direction,
                  `set direction to ${direction}`);
  }
}, 'Allows setting the direction to each of the possible keywords');
promise_test(async t => {
  const anim =
      createScrollLinkedAnimationWithTiming(
          t, { duration: 10000, direction: 'normal' });
  const scroller = anim.timeline.source;
  const maxScroll = scroller.scrollHeight - scroller.clientHeight;
  anim.play();
  await anim.ready;
  scroller.scrollTop = maxScroll * 0.07
  await waitForNextFrame();
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.07,
                             'progress before updating direction');
  anim.effect.updateTiming({ direction: 'reverse' });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.93,
                             'progress after updating direction');
}, 'Allows setting the direction of an animation in progress from \'normal\' ' +
   'to \'reverse\'');
promise_test(async t => {
  const anim =
      createScrollLinkedAnimationWithTiming(
          t, { duration: 10000, direction: 'normal' });
  anim.play();
  await anim.ready;
  assert_equals(anim.effect.getComputedTiming().progress, 0,
                'progress before updating direction');
  anim.effect.updateTiming({ direction: 'reverse' });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after updating direction');
}, 'Allows setting the direction of an animation in progress from \'normal\' to'
   + ' \'reverse\' while at start of active interval');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { fill: 'backwards',
                                      duration: 10000,
                                      delay: 10000,
                                      direction: 'normal' });
  anim.play();
  await anim.ready;
  assert_equals(anim.effect.getComputedTiming().progress, 0,
                'progress before updating direction');
  anim.effect.updateTiming({ direction: 'reverse' });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'progress after updating direction');
}, 'Allows setting the direction of an animation in progress from \'normal\' to'
   + ' \'reverse\' while filling backwards');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { iterations: 2,
                                      duration: 10000,
                                      direction: 'normal' });
  const scroller = anim.timeline.source;
  const maxScroll = scroller.scrollHeight - scroller.clientHeight;
  anim.play();
  await anim.ready;
  scroller.scrollTop = maxScroll * 0.17 // 34% through first iteration
  await waitForNextFrame();
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.34,
                             'progress before updating direction');
  anim.effect.updateTiming({ direction: 'alternate' });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.34,
                             'progress after updating direction');
}, 'Allows setting the direction of an animation in progress from \'normal\' to'
   + ' \'alternate\'');
promise_test(async t => {
  const anim = createScrollLinkedAnimationWithTiming(t, { iterations: 2,
                                      duration: 10000,
                                      direction: 'alternate' });
  const scroller = anim.timeline.source;
  const maxScroll = scroller.scrollHeight - scroller.clientHeight;
  anim.play();
  await anim.ready;
  scroller.scrollTop = maxScroll * 0.17
  await waitForNextFrame();
  // anim.currentTime = 17000; // 34% through first iteration
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.34,
                             'progress before updating direction');
  anim.effect.updateTiming({ direction: 'alternate-reverse' });
  assert_time_equals_literal(anim.effect.getComputedTiming().progress, 0.66,
                             'progress after updating direction');
}, 'Allows setting the direction of an animation in progress from \'alternate\''
   + ' to \'alternate-reverse\'');
// ------------------------------
//  easing
// ------------------------------
async function assert_progress(animation, scrollPercent, easingFunction) {
  const scroller = animation.timeline.source;
  const maxScroll = scroller.scrollHeight - scroller.clientHeight;
  scroller.scrollTop = maxScroll * scrollPercent
  await waitForNextFrame();
  assert_approx_equals(animation.effect.getComputedTiming().progress,
                       easingFunction(scrollPercent),
                       0.01,
                       'The progress of the animation should be approximately'
                       + ` ${easingFunction(scrollPercent)} at ${scrollPercent}%`);
}
for (const options of gEasingTests) {
  promise_test(async t => {
    const anim = createScrollLinkedAnimationWithTiming(t, { duration: 100000,
                                  fill: 'forwards' });
    anim.play();
    anim.effect.updateTiming({ easing: options.easing });
    assert_equals(anim.effect.getTiming().easing,
                  options.serialization || options.easing);
    const easing = options.easingFunction;
    await assert_progress(anim, 0, easing);
    await assert_progress(anim, 0.25, easing);
    await assert_progress(anim, 0.5, easing);
    await assert_progress(anim, 0.75, easing);
    await assert_progress(anim, 1, easing);
  }, `Allows setting the easing to a ${options.desc}`);
}
for (const easing of gRoundtripEasings) {
  test(t => {
    const anim = createScrollLinkedAnimationWithTiming(t);
    anim.play();
    anim.effect.updateTiming({ easing: easing });
    assert_equals(anim.effect.getTiming().easing, easing);
  }, `Updates the specified value when setting the easing to '${easing}'`);
}
// Because of the delay being so large, this progress based animation is always
// in the finished state with progress 1. Included here because it is in the
// original test file for time based animations.
promise_test(async t => {
  const delay = 1000000;
  const anim = createScrollLinkedAnimationWithTiming(t,
    { duration: 1000000, fill: 'both', delay: delay, easing: 'steps(2, start)' });
  const scroller = anim.timeline.source;
  const maxScroll = scroller.scrollHeight - scroller.clientHeight;
  anim.play();
  await anim.ready;
  anim.effect.updateTiming({ easing: 'steps(2, end)' });
  assert_equals(anim.effect.getComputedTiming().progress, 0,
                'easing replace to steps(2, end) at before phase');
  scroller.scrollTop = maxScroll * 0.875
  await waitForNextFrame();
  assert_equals(anim.effect.getComputedTiming().progress, 0.5,
                'change currentTime to active phase');
  anim.effect.updateTiming({ easing: 'steps(2, start)' });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'easing replace to steps(2, start) at active phase');
  scroller.scrollTop = maxScroll * 1.25
  await waitForNextFrame();
  anim.effect.updateTiming({ easing: 'steps(2, end)' });
  assert_equals(anim.effect.getComputedTiming().progress, 1,
                'easing replace to steps(2, end) again at after phase');
}, 'Allows setting the easing of an animation in progress');
</script>
</body>
 |