File: event-dispatch.tentative.html

package info (click to toggle)
firefox-esr 140.3.1esr-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,016 kB
  • sloc: cpp: 7,380,478; javascript: 6,388,099; ansic: 3,710,142; python: 1,393,715; xml: 628,165; asm: 426,918; java: 184,025; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (580 lines) | stat: -rw-r--r-- 18,280 bytes parent folder | download | duplicates (7)
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
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
<!doctype html>
<meta charset=utf-8>
<title>Tests for CSS animation event dispatch</title>
<meta name="timeout" content="long">
<link rel="help" href="https://drafts.csswg.org/css-animations-2/#event-dispatch"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/testcommon.js"></script>
<style>
@keyframes anim {
  from { margin-left: 0px; }
  to { margin-left: 100px; }
}
@keyframes anim2 {
  from { margin-top: 100px; }
  to { margin-top: 200px; }
}
@keyframes anim3 {
  from { padding-left: 100px; }
  to { padding-left: 200px; }
}
</style>
<div id="log"></div>
<script>
'use strict';

const setupAnimation = (t, animationStyle) => {
  const div = addDiv(t, { style: 'animation: ' + animationStyle });
  const animation = div.getAnimations()[0];
  const timeoutPromise = armTimeoutWhenReady(animation, fastEventsTimeout);

  const watcher = new EventWatcher(t, div, [ 'animationstart',
                                             'animationiteration',
                                             'animationend',
                                             'animationcancel' ],
                                   timeoutPromise);

  return { animation, watcher, div };
};

promise_test(async t => {
  // Add 1ms delay to ensure that the delay is not included in the elapsedTime.
  const { animation, watcher } = setupAnimation(t, 'anim 100s 1ms');

  const evt = await watcher.wait_for('animationstart');
  assert_equals(evt.elapsedTime, 0.0);
}, 'Idle -> Active');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  // Seek to After phase.
  animation.finish();

  const events = await watcher.wait_for(['animationstart', 'animationend'], {
    record: 'all',
  });
  assert_equals(events[0].elapsedTime, 0.0);
  assert_equals(events[1].elapsedTime, 100);
}, 'Idle -> After');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s paused');

  await animation.ready;

  // Seek to Active phase.
  animation.currentTime = 100 * MS_PER_SEC;

  const evt = await watcher.wait_for('animationstart');
  assert_equals(evt.elapsedTime, 0.0);
}, 'Before -> Active');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s paused');
  const allEvents = watcher.wait_for(['animationstart', 'animationend'], {
    record: 'all',
  });

  await animation.ready;

  // Seek to After phase.
  animation.finish();

  const events = await allEvents;
  assert_equals(events[0].elapsedTime, 0.0);
  assert_equals(events[1].elapsedTime, 100.0);
}, 'Before -> After');

promise_test(async t => {
  const { animation, watcher, div } = setupAnimation(t, 'anim 100s paused');

  await watcher.wait_for('animationstart');

  // Make idle
  div.style.display = 'none';

  const evt = await watcher.wait_for('animationcancel');
  assert_equals(evt.elapsedTime, 0.0);
}, 'Active -> Idle, display: none');

promise_test(async t => {
  const { animation, watcher, div } = setupAnimation(t, 'anim 100s paused');

  // Seek to After phase.
  animation.finish();
  await watcher.wait_for(['animationstart', 'animationend']);

  div.style.display = 'none';

  // Wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'After -> Idle, display: none');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  animation.currentTime = 100.0;

  // Make idle
  animation.timeline = null;

  const evt = await watcher.wait_for('animationcancel');
  assert_time_equals_literal(evt.elapsedTime, 0.1);
}, 'Active -> Idle, setting Animation.timeline = null');

promise_test(async t => {
  // We should NOT pause animation since calling cancel synchronously.
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  animation.currentTime = 50.0;
  animation.cancel();

  const evt = await watcher.wait_for('animationcancel');
  assert_time_equals_literal(evt.elapsedTime, 0.05);
}, 'Active -> Idle, calling Animation.cancel()');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s paused');

  // Seek to Active phase.
  animation.currentTime = 100 * MS_PER_SEC;
  await watcher.wait_for('animationstart');

  // Seek to Before phase.
  animation.currentTime = 0;

  const evt = await watcher.wait_for('animationend');
  assert_equals(evt.elapsedTime, 0.0);
}, 'Active -> Before');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s paused');

  await watcher.wait_for('animationstart');

  // Seek to After phase.
  animation.finish();

  const evt = await watcher.wait_for('animationend');
  assert_equals(evt.elapsedTime, 100.0);
}, 'Active -> After');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s paused');

  // Seek to After phase.
  animation.finish();
  await watcher.wait_for([ 'animationstart', 'animationend' ]);

  // Seek to Before phase.
  animation.currentTime = 0;

  const events = await watcher.wait_for(['animationstart', 'animationend'], {
    record: 'all',
  });
  assert_equals(events[0].elapsedTime, 100.0);
  assert_equals(events[1].elapsedTime, 0.0);
}, 'After -> Before');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s paused');

  // Seek to After phase.
  animation.finish();
  await watcher.wait_for([ 'animationstart', 'animationend' ]);

  // Seek to Active phase.
  animation.currentTime = 100 * MS_PER_SEC;

  const evt = await watcher.wait_for('animationstart');
  assert_equals(evt.elapsedTime, 100.0);
}, 'After -> Active');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s 3 paused');

  await animation.ready;

  // Seek to iteration 0 (no animationiteration event should be dispatched)
  animation.currentTime = 100 * MS_PER_SEC;
  await watcher.wait_for('animationstart');

  // Seek to iteration 2
  animation.currentTime = 300 * MS_PER_SEC;
  let evt = await watcher.wait_for('animationiteration');
  assert_equals(evt.elapsedTime, 200);

  // Seek to After phase (no animationiteration event should be dispatched)
  animation.currentTime = 400 * MS_PER_SEC;
  evt = await watcher.wait_for('animationend');
  assert_equals(evt.elapsedTime, 300);
}, 'Active -> Active (forwards)');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s 3');

  // Seek to After phase.
  animation.finish();
  await watcher.wait_for([ 'animationstart', 'animationend' ]);

  // Seek to iteration 2 (no animationiteration event should be dispatched)
  animation.pause();
  animation.currentTime = 300 * MS_PER_SEC;
  await watcher.wait_for('animationstart');

  // Seek to mid of iteration 0 phase.
  animation.currentTime = 200 * MS_PER_SEC;

  const evt = await watcher.wait_for('animationiteration');
  assert_equals(evt.elapsedTime, 200.0);

  // Seek to before phase (no animationiteration event should be dispatched)
  animation.currentTime = 0;
  await watcher.wait_for('animationend');
}, 'Active -> Active (backwards)');

promise_test(async t => {
  const { animation, watcher, div } = setupAnimation(t, 'anim 100s paused');

  await watcher.wait_for('animationstart');

  // Seek to Idle phase.
  div.style.display = 'none';
  flushComputedStyle(div);

  await watcher.wait_for('animationcancel');

  // Restart this animation.
  div.style.display = '';
  await watcher.wait_for('animationstart');
}, 'Active -> Idle -> Active: animationstart is fired by restarting animation');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s 2 paused');

  // Make After.
  animation.finish();

  await watcher.wait_for([ 'animationstart', 'animationend' ]);
  animation.playbackRate = -1;

  let evt = await watcher.wait_for('animationstart');
  assert_equals(evt.elapsedTime, 200);

  // Seek to 1st iteration
  animation.currentTime = 200 * MS_PER_SEC - 1;

  evt = await watcher.wait_for('animationiteration');
  assert_equals(evt.elapsedTime, 100);

  // Seek to before
  animation.currentTime = 100 * MS_PER_SEC - 1;

  evt = await watcher.wait_for('animationend');
  assert_equals(evt.elapsedTime, 0);
  assert_equals(animation.playState, 'running'); // delay
}, 'Negative playbackRate sanity test(Before -> Active -> Before)');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  animation.currentTime = 150 * MS_PER_SEC;
  animation.currentTime = 50 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, before -> active, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  animation.currentTime = 250 * MS_PER_SEC;
  animation.currentTime = 50 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, before -> after, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  // Get us into the initial state:
  animation.currentTime = 150 * MS_PER_SEC;

  await watcher.wait_for('animationstart');

  animation.currentTime = 50 * MS_PER_SEC;
  animation.currentTime = 150 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, active -> before, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  // Get us into the initial state:
  animation.currentTime = 150 * MS_PER_SEC;

  await watcher.wait_for('animationstart');

  animation.currentTime = 250 * MS_PER_SEC;
  animation.currentTime = 150 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, active -> after, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  // Get us into the initial state:
  animation.currentTime = 250 * MS_PER_SEC;

  await watcher.wait_for(['animationstart', 'animationend']);

  animation.currentTime = 50 * MS_PER_SEC;
  animation.currentTime = 250 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, after -> before, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s 100s');

  // Get us into the initial state:
  animation.currentTime = 250 * MS_PER_SEC;

  await watcher.wait_for(['animationstart', 'animationend']);

  animation.currentTime = 150 * MS_PER_SEC;
  animation.currentTime = 250 * MS_PER_SEC;

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Redundant change, after -> active, then back');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Make idle
  animation.cancel();
  await watcher.wait_for('animationcancel');

  animation.cancel();
  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Call Animation.cancel after canceling animation.');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Make idle
  animation.cancel();
  animation.play();
  await watcher.wait_for([ 'animationcancel', 'animationstart' ]);
}, 'Restart animation after canceling animation immediately.');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Make idle
  animation.cancel();
  animation.play();
  animation.cancel();
  await watcher.wait_for('animationcancel');

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Call Animation.cancel after restarting animation immediately.');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Make idle
  animation.timeline = null;
  await watcher.wait_for('animationcancel');

  animation.timeline = document.timeline;
  animation.play();
  await watcher.wait_for('animationstart');
}, 'Set timeline and play transition after clearing the timeline.');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Make idle
  animation.cancel();
  await watcher.wait_for('animationcancel');

  animation.effect = null;
  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Set null target effect after canceling the animation.');

promise_test(async t => {
  const { animation, watcher } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  animation.effect = null;
  await watcher.wait_for('animationend');

  animation.cancel();
  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Cancel the animation after clearing the target effect.');

promise_test(async t => {
  const { animation, watcher, div } = setupAnimation(t, 'anim 100s');

  await watcher.wait_for('animationstart');

  // Replace the running animation.
  div.style.animation = 'anim2 100s';

  // animationcancel event should be fired before animationstart because we
  // expect to cancel the running animation first.
  const events = await watcher.wait_for(
    ['animationcancel', 'animationstart'],
    { record: 'all' }
  );
  assert_equals(events[0].animationName, 'anim');
  assert_equals(events[1].animationName, 'anim2');

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'Replacing a running animation should get animationcancel earlier than ' +
   'animationstart');

promise_test(async t => {
  const div = addDiv(t, { style: 'animation: anim 100s, anim2 100s' });
  const animations = div.getAnimations();
  const watcher = new EventWatcher(t, div, [ 'animationstart',
                                             'animationcancel' ],
    () => {
      return Promise.all([animations[0].ready, animations[1].ready]).then(() => {
        return fastEventsTimeout();
      });
    }
  );

  await watcher.wait_for(['animationstart', 'animationstart']);

  // Replace the first animation
  div.style.animation = 'anim3 100s, anim2 100s';

  // animationcancel event should be fired before animationstart because we
  // expect to cancel the running animation first.
  const events = await watcher.wait_for(
    ['animationcancel', 'animationstart'],
    { record: 'all' }
  );
  assert_equals(events[0].animationName, 'anim');
  assert_equals(events[1].animationName, 'anim3');

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'The cancel event should be fired before the new start event if both have ' +
   'the same position in the animation list');

promise_test(async t => {
  const div =
    addDiv(t, { style: 'animation: anim 100s, anim2 100s, anim3 100s' });
  const animations = div.getAnimations();
  const watcher = new EventWatcher(t, div, [ 'animationstart',
                                             'animationcancel' ],
    () => {
      return Promise.all([
        animations[0].ready,
        animations[1].ready,
        animations[2].ready
      ]).then(() => {
        return fastEventsTimeout();
      });
    }
  );

  await watcher.wait_for(
    ['animationstart', 'animationstart', 'animationstart']
  );

  // Cancel the first and the second animations.
  div.style.animation = 'anim3 100s';

  const events = await watcher.wait_for(
    ['animationcancel', 'animationcancel'],
    { record: 'all' }
  );
  // Per https://drafts.csswg.org/css-animations-2/#animation-composite-order,
  // the cancel event with the earlier position should be fired earlier.
  assert_equals(events[0].animationName, 'anim');
  assert_equals(events[1].animationName, 'anim2');

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'The cancel event with an earlier position in animation list should be ' +
   'fired earlier');

promise_test(async t => {
  const div =
    addDiv(t, { style: 'animation: anim 100s, anim2 100s, anim3 100s' });
  const animations = div.getAnimations();
  const watcher = new EventWatcher(t, div, [ 'animationstart',
                                             'animationcancel' ],
    () => {
      return Promise.all([
        animations[0].ready,
        animations[1].ready,
        animations[2].ready
      ]).then(() => {
        return fastEventsTimeout();
      });
    }
  );

  await watcher.wait_for(
    ['animationstart', 'animationstart', 'animationstart']
  );

  // Change the order, i.e. swap the order of |anim| and |anim2|.
  div.style.animation = 'anim2 100s, anim 100s, anim3 100s';
  getComputedStyle(div).animation;

  // Then we cancel the first and the second animations.
  div.style.animation = 'anim3 100s';

  const events = await watcher.wait_for(
    ['animationcancel', 'animationcancel'],
    { record: 'all' }
  );
  // Per https://drafts.csswg.org/css-animations-2/#animation-composite-order,
  // the cancel event to |anim2| should be dispatched before the cancel event to
  // |anim| since |anim2| appeared before |anim| in the animation-name at the
  // point when they were cancelled.
  assert_equals(events[0].animationName, 'anim2');
  assert_equals(events[1].animationName, 'anim');

  // Then wait a couple of frames and check that no event was dispatched.
  await waitForAnimationFrames(2);
}, 'The order of the cancel events follows the relative positions in the ' +
   'animation list at the point when they were cancelled');

</script>