Skip to content

Commit a7c28fd

Browse files
authored
Merge pull request web-platform-tests#18 from alancutter/documentTimelineAGAIN
Upstream time-consistent-across-frames.html from Blink
2 parents a2bf927 + 485952a commit a7c28fd

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

web-animations/interfaces/AnimationTimeline/document-timeline.html

+39-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<link rel="help" href="https://w3c.github.io/web-animations/#the-documents-default-timeline">
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
7+
<script src="../../testcommon.js"></script>
78
<div id="log"></div>
89
<iframe width="10" height="10" id="iframe"></iframe>
910
<script>
@@ -20,6 +21,18 @@
2021
}, 'document.timeline identity tests');
2122

2223
promise_test(function(t) {
24+
var baseTime = document.timeline.currentTime;
25+
var iframe = document.getElementById('iframe');
26+
var iframeBaseTime = iframe.contentDocument.timeline.currentTime;
27+
return waitForAnimationFrames(4).then(function() {
28+
var delta = document.timeline.currentTime - baseTime;
29+
var iframeDelta = iframe.contentDocument.timeline.currentTime - iframeBaseTime;
30+
assert_greater_than(delta, 0);
31+
assert_times_equal(delta, iframeDelta, 'different document timelines should progress at the same rate');
32+
});
33+
}, 'document.timeline should tick consistently across frames');
34+
35+
async_test(function(t) {
2336
assert_true(document.timeline.currentTime > 0,
2437
'document.timeline.currentTime is positive');
2538
// document.timeline.currentTime should be set even before document
@@ -35,11 +48,14 @@
3548
// We can't just compare document.timeline.currentTime to
3649
// window.performance.now() because currentTime is only updated on a sample
3750
// so we use requestAnimationFrame instead.
38-
return window.requestAnimationFrame(t.step_func(function(rafTime) {
39-
assert_equals(document.timeline.currentTime, rafTime,
40-
'document.timeline.currentTime matches' +
41-
' requestAnimationFrame time');
42-
}));
51+
window.requestAnimationFrame(function(rafTime) {
52+
t.step(function() {
53+
assert_equals(document.timeline.currentTime, rafTime,
54+
'document.timeline.currentTime matches' +
55+
' requestAnimationFrame time');
56+
});
57+
t.done();
58+
});
4359
}, 'document.timeline.currentTime value tests');
4460

4561
promise_test(function(t) {
@@ -50,12 +66,27 @@
5066
}
5167
assert_equals(document.timeline.currentTime, valueAtStart,
5268
'document.timeline.currentTime does not change within a script block');
53-
return window.requestAnimationFrame(t.step_func(function() {
54-
assert_true(document.timeline.currentTime > valueAtStart,
69+
return waitForAnimationFrames(1).then(function() {
70+
assert_greater_than(document.timeline.currentTime, valueAtStart,
5571
'document.timeline.currentTime increases between script blocks');
56-
}));
72+
});
5773
}, 'document.timeline.currentTime liveness tests');
5874

75+
promise_test(function(t) {
76+
var iframeTimeline = iframe.contentDocument.timeline;
77+
var valueAtStart = iframeTimeline.currentTime;
78+
var timeAtStart = window.performance.now();
79+
while (window.performance.now() - timeAtStart < 100) {
80+
// Wait 100ms
81+
}
82+
assert_equals(iframeTimeline.currentTime, valueAtStart,
83+
'iframe document.timeline.currentTime does not change within a script block');
84+
return waitForAnimationFrames(1).then(function() {
85+
assert_greater_than(iframeTimeline.currentTime, valueAtStart,
86+
'iframe document.timeline.currentTime increases between script blocks');
87+
});
88+
}, 'iframe document.timeline.currentTime liveness tests');
89+
5990
async_test(function(t) {
6091
var startTime = document.timeline.currentTime;
6192
var firstRafTime;

0 commit comments

Comments
 (0)