OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <meta charset=utf-8> | |
3 <title>Web Animations API: DocumentTimeline tests</title> | |
4 <script src="../../../../resources/testharness.js"></script> | |
5 <script src="../../../../resources/testharnessreport.js"></script> | |
6 <div id="log"></div> | |
7 <iframe src="data:text/html;charset=utf-8," width="10" height="10" id="iframe"><
/iframe> | |
8 <script> | |
9 'use strict'; | |
10 | |
11 test(function() { | |
12 assert_equals(document.timeline, document.timeline, | |
13 'document.timeline returns the same object every time'); | |
14 var iframe = document.getElementById('iframe'); | |
15 assert_not_equals(document.timeline, iframe.contentDocument.timeline, | |
16 'document.timeline returns a different object for each document'); | |
17 assert_not_equals(iframe.contentDocument.timeline, null, | |
18 'document.timeline on an iframe is not null'); | |
19 }, | |
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 | |
27 async_test(function(t) { | |
28 assert_true(document.timeline.currentTime > 0, | |
29 'document.timeline.currentTime is positive'); | |
30 // document.timeline.currentTime should be set even before document | |
31 // load fires. We expect this code to be run before document load and hence | |
32 // the above assertion is sufficient. | |
33 // If the following assertion fails, this test needs to be redesigned. | |
34 assert_true(document.readyState !== 'complete', | |
35 'Test is running prior to document load'); | |
36 | |
37 // Test that the document timeline's current time is measured from | |
38 // navigationStart. | |
39 // | |
40 // We can't just compare document.timeline.currentTime to | |
41 // window.performance.now() because currentTime is only updated on a sample | |
42 // so we use requestAnimationFrame instead. | |
43 window.requestAnimationFrame(t.step_func(function(rafTime) { | |
44 assert_equals(document.timeline.currentTime, rafTime, | |
45 'document.timeline.currentTime matches' + | |
46 ' requestAnimationFrame time'); | |
47 t.done(); | |
48 })); | |
49 }, | |
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 | |
67 async_test(function(t) { | |
68 var valueAtStart = document.timeline.currentTime; | |
69 var timeAtStart = window.performance.now(); | |
70 while (window.performance.now() - timeAtStart < 100) { | |
71 // Wait 100ms | |
72 } | |
73 assert_equals(document.timeline.currentTime, valueAtStart, | |
74 'document.timeline.currentTime does not change within a script block'); | |
75 window.requestAnimationFrame(t.step_func(function() { | |
76 assert_true(document.timeline.currentTime > valueAtStart, | |
77 'document.timeline.currentTime increases between script blocks'); | |
78 t.done(); | |
79 })); | |
80 }, | |
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 | |
89 </script> | |
OLD | NEW |