mirror of
https://github.com/servo/servo.git
synced 2025-10-16 08:20:22 +01:00
111 lines
4.1 KiB
HTML
111 lines
4.1 KiB
HTML
<!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>
|
|
<script src="../../testcommon.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');
|
|
|
|
async_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.
|
|
window.requestAnimationFrame(function(rafTime) {
|
|
t.step(function() {
|
|
assert_equals(document.timeline.currentTime, rafTime,
|
|
'document.timeline.currentTime matches' +
|
|
' requestAnimationFrame time');
|
|
});
|
|
t.done();
|
|
});
|
|
}, 'document.timeline.currentTime value tests');
|
|
|
|
promise_test(function(t) {
|
|
var valueAtStart = document.timeline.currentTime;
|
|
var timeAtStart = window.performance.now();
|
|
while (window.performance.now() - timeAtStart < 50) {
|
|
// Wait 50ms
|
|
}
|
|
assert_equals(document.timeline.currentTime, valueAtStart,
|
|
'document.timeline.currentTime does not change within a script block');
|
|
return waitForAnimationFrames(1).then(function() {
|
|
assert_greater_than(document.timeline.currentTime, valueAtStart,
|
|
'document.timeline.currentTime increases between script blocks');
|
|
});
|
|
}, 'document.timeline.currentTime liveness tests');
|
|
|
|
async_test(function(t) {
|
|
const iframe = document.createElement('iframe');
|
|
iframe.width = 10;
|
|
iframe.height = 10;
|
|
|
|
iframe.addEventListener('load', t.step_func(() => {
|
|
const iframeTimeline = iframe.contentDocument.timeline;
|
|
const valueAtStart = iframeTimeline.currentTime;
|
|
const timeAtStart = window.performance.now();
|
|
while (iframe.contentWindow.performance.now() - timeAtStart < 50) {
|
|
// Wait 50ms
|
|
}
|
|
assert_equals(iframeTimeline.currentTime, valueAtStart,
|
|
'iframe document.timeline.currentTime does not change within a '
|
|
+ ' script block');
|
|
|
|
iframe.contentWindow.requestAnimationFrame(t.step_func_done(() => {
|
|
assert_greater_than(iframeTimeline.currentTime, valueAtStart,
|
|
'iframe document.timeline.currentTime increases between script blocks');
|
|
iframe.remove();
|
|
}));
|
|
}));
|
|
|
|
document.body.appendChild(iframe);
|
|
}, 'iframe document.timeline.currentTime liveness tests');
|
|
|
|
async_test(function(t) {
|
|
var startTime = document.timeline.currentTime;
|
|
var firstRafTime;
|
|
|
|
requestAnimationFrame(function() {
|
|
t.step(function() {
|
|
assert_greater_than_equal(document.timeline.currentTime, startTime,
|
|
'currentTime should have progressed');
|
|
firstRafTime = document.timeline.currentTime;
|
|
});
|
|
});
|
|
|
|
requestAnimationFrame(function() {
|
|
t.step(function() {
|
|
assert_equals(document.timeline.currentTime, firstRafTime,
|
|
'currentTime should be the same');
|
|
});
|
|
t.done();
|
|
});
|
|
}, 'document.timeline.currentTime time should be the same for all RAF'
|
|
+ ' callbacks in a frame');
|
|
|
|
</script>
|