OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
3 <title>Web Animations API: DocumentTimeline tests</title> | 3 <title>Default document timeline tests</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#the-documents-defau
lt-timeline"> |
4 <script src="/resources/testharness.js"></script> | 5 <script src="/resources/testharness.js"></script> |
5 <script src="/resources/testharnessreport.js"></script> | 6 <script src="/resources/testharnessreport.js"></script> |
6 <div id="log"></div> | 7 <div id="log"></div> |
7 <iframe width="10" height="10" id="iframe"></iframe> | 8 <iframe width="10" height="10" id="iframe"></iframe> |
8 <script> | 9 <script> |
9 'use strict'; | 10 'use strict'; |
10 | 11 |
11 test(function() { | 12 test(function() { |
12 assert_equals(document.timeline, document.timeline, | 13 assert_equals(document.timeline, document.timeline, |
13 'document.timeline returns the same object every time'); | 14 'document.timeline returns the same object every time'); |
14 var iframe = document.getElementById('iframe'); | 15 var iframe = document.getElementById('iframe'); |
15 assert_not_equals(document.timeline, iframe.contentDocument.timeline, | 16 assert_not_equals(document.timeline, iframe.contentDocument.timeline, |
16 'document.timeline returns a different object for each document'); | 17 'document.timeline returns a different object for each document'); |
17 assert_not_equals(iframe.contentDocument.timeline, null, | 18 assert_not_equals(iframe.contentDocument.timeline, null, |
18 'document.timeline on an iframe is not null'); | 19 'document.timeline on an iframe is not null'); |
19 }, | 20 }, 'document.timeline identity tests'); |
20 'document.timeline identity tests', | |
21 { | |
22 help: 'http://dev.w3.org/fxtf/web-animations/#the-document-timeline', | |
23 assert: [ 'Each document has a timeline called the document timeline' ], | |
24 author: 'Brian Birtles' | |
25 }); | |
26 | 21 |
27 async_test(function(t) { | 22 promise_test(function(t) { |
28 assert_true(document.timeline.currentTime > 0, | 23 assert_true(document.timeline.currentTime > 0, |
29 'document.timeline.currentTime is positive'); | 24 'document.timeline.currentTime is positive'); |
30 // document.timeline.currentTime should be set even before document | 25 // document.timeline.currentTime should be set even before document |
31 // load fires. We expect this code to be run before document load and hence | 26 // load fires. We expect this code to be run before document load and hence |
32 // the above assertion is sufficient. | 27 // the above assertion is sufficient. |
33 // If the following assertion fails, this test needs to be redesigned. | 28 // If the following assertion fails, this test needs to be redesigned. |
34 assert_true(document.readyState !== 'complete', | 29 assert_true(document.readyState !== 'complete', |
35 'Test is running prior to document load'); | 30 'Test is running prior to document load'); |
36 | 31 |
37 // Test that the document timeline's current time is measured from | 32 // Test that the document timeline's current time is measured from |
38 // navigationStart. | 33 // navigationStart. |
39 // | 34 // |
40 // We can't just compare document.timeline.currentTime to | 35 // We can't just compare document.timeline.currentTime to |
41 // window.performance.now() because currentTime is only updated on a sample | 36 // window.performance.now() because currentTime is only updated on a sample |
42 // so we use requestAnimationFrame instead. | 37 // so we use requestAnimationFrame instead. |
43 window.requestAnimationFrame(t.step_func(function(rafTime) { | 38 return window.requestAnimationFrame(t.step_func(function(rafTime) { |
44 assert_equals(document.timeline.currentTime, rafTime, | 39 assert_equals(document.timeline.currentTime, rafTime, |
45 'document.timeline.currentTime matches' + | 40 'document.timeline.currentTime matches' + |
46 ' requestAnimationFrame time'); | 41 ' requestAnimationFrame time'); |
47 t.done(); | |
48 })); | 42 })); |
49 }, | 43 }, 'document.timeline.currentTime value tests'); |
50 'document.timeline.currentTime value tests', | |
51 { | |
52 help: [ | |
53 'http://dev.w3.org/fxtf/web-animations/#the-global-clock', | |
54 'http://dev.w3.org/fxtf/web-animations/#the-document-timeline' | |
55 ], | |
56 assert: [ | |
57 'The global clock is a source of monotonically increasing time values', | |
58 'The time values of the document timeline are calculated as a fixed' + | |
59 ' offset from the global clock', | |
60 'the zero time corresponds to the navigationStart moment', | |
61 'the time value of each document timeline must be equal to the time ' + | |
62 'passed to animation frame request callbacks for that browsing context' | |
63 ], | |
64 author: 'Brian Birtles' | |
65 }); | |
66 | 44 |
67 async_test(function(t) { | 45 promise_test(function(t) { |
68 var valueAtStart = document.timeline.currentTime; | 46 var valueAtStart = document.timeline.currentTime; |
69 var timeAtStart = window.performance.now(); | 47 var timeAtStart = window.performance.now(); |
70 while (window.performance.now() - timeAtStart < 100) { | 48 while (window.performance.now() - timeAtStart < 100) { |
71 // Wait 100ms | 49 // Wait 100ms |
72 } | 50 } |
73 assert_equals(document.timeline.currentTime, valueAtStart, | 51 assert_equals(document.timeline.currentTime, valueAtStart, |
74 'document.timeline.currentTime does not change within a script block'); | 52 'document.timeline.currentTime does not change within a script block'); |
75 window.requestAnimationFrame(t.step_func(function() { | 53 return window.requestAnimationFrame(t.step_func(function() { |
76 assert_true(document.timeline.currentTime > valueAtStart, | 54 assert_true(document.timeline.currentTime > valueAtStart, |
77 'document.timeline.currentTime increases between script blocks'); | 55 'document.timeline.currentTime increases between script blocks'); |
78 t.done(); | |
79 })); | 56 })); |
80 }, | 57 }, 'document.timeline.currentTime liveness tests'); |
81 'document.timeline.currentTime liveness tests', | |
82 { | |
83 help: 'http://dev.w3.org/fxtf/web-animations/#script-execution-and-live-update
s-to-the-model', | |
84 assert: [ 'The value returned by the currentTime attribute of a' + | |
85 ' document timeline will not change within a script block' ], | |
86 author: 'Brian Birtles' | |
87 }); | |
88 | 58 |
89 </script> | 59 </script> |
OLD | NEW |