summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-animations/interfaces/AnimationTimeline/document-timeline.html
blob: 0f782f50adcbe8be7fd792d1c99afe1a101a395f (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
<!doctype html>
<meta charset=utf-8>
<title>Default document timeline tests</title>
<link rel="help" href="https://w3c.github.io/web-animations/#the-documents-default-timeline">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe width="10" height="10" id="iframe"></iframe>
<script>
'use strict';

test(function() {
  assert_equals(document.timeline, document.timeline,
    'document.timeline returns the same object every time');
  var iframe = document.getElementById('iframe');
  assert_not_equals(document.timeline, iframe.contentDocument.timeline,
    'document.timeline returns a different object for each document');
  assert_not_equals(iframe.contentDocument.timeline, null,
    'document.timeline on an iframe is not null');
}, 'document.timeline identity tests');

promise_test(function(t) {
  assert_true(document.timeline.currentTime > 0,
    'document.timeline.currentTime is positive');
  // document.timeline.currentTime should be set even before document
  // load fires. We expect this code to be run before document load and hence
  // the above assertion is sufficient.
  // If the following assertion fails, this test needs to be redesigned.
  assert_true(document.readyState !== 'complete',
    'Test is running prior to document load');

  // Test that the document timeline's current time is measured from
  // navigationStart.
  //
  // We can't just compare document.timeline.currentTime to
  // window.performance.now() because currentTime is only updated on a sample
  // so we use requestAnimationFrame instead.
  return window.requestAnimationFrame(t.step_func(function(rafTime) {
    assert_equals(document.timeline.currentTime, rafTime,
                  'document.timeline.currentTime matches' +
                  ' requestAnimationFrame time');
  }));
}, 'document.timeline.currentTime value tests');

promise_test(function(t) {
  var valueAtStart = document.timeline.currentTime;
  var timeAtStart = window.performance.now();
  while (window.performance.now() - timeAtStart < 100) {
    // Wait 100ms
  }
  assert_equals(document.timeline.currentTime, valueAtStart,
    'document.timeline.currentTime does not change within a script block');
  return window.requestAnimationFrame(t.step_func(function() {
    assert_true(document.timeline.currentTime > valueAtStart,
      'document.timeline.currentTime increases between script blocks');
  }));
}, 'document.timeline.currentTime liveness tests');

</script>