summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/animation/script-tests/request-animation-frame-prefix.js
blob: eedb0769b850bf8a9b463e4b8f44ce6b6b658c1d (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
description("Tests the timestamps provided to prefixed webkitRequestAnimationFrame callbacks");

var firstTimestamp = undefined;
var secondTimestamp = undefined;
var legacyFirstTimestamp = undefined;
var legacySecondTimestamp = undefined;
var deltaError = undefined;

function busyWait(millis) {
    var start = Date.now();
    while (Date.now()-start < millis) {}
}

window.requestAnimationFrame(function(timestamp) {
    firstTimestamp = timestamp;
});

window.webkitRequestAnimationFrame(function(timestamp) {
    legacyFirstTimestamp = timestamp;

    window.requestAnimationFrame(function(timestamp) {
        secondTimestamp = timestamp;
    });

    window.webkitRequestAnimationFrame(function(timestamp) {
        legacySecondTimestamp = timestamp;

        shouldBeGreaterThanOrEqual("legacyFirstTimestamp", "firstTimestamp");
        shouldBeGreaterThanOrEqual("legacySecondTimestamp", "secondTimestamp");
        deltaError = Math.abs((legacySecondTimestamp - legacyFirstTimestamp) - (secondTimestamp - firstTimestamp));
        shouldBeTrue("deltaError < 0.001");
        testRunner.notifyDone();
    });

    busyWait(10);
});

if (window.testRunner)
    testRunner.waitUntilDone();