chromium/third_party/blink/web_tests/fast/harness/should-be-now.html

<!DOCTYPE html>

<script src="../../resources/js-test.js"></script>
<script>
description('Test shouldBeNow() in js-test.js');

shouldBeNow("Date.now()");
shouldBeNow("new Date()");

debug("Testing type checking with a string. This should fail.");
shouldBeNow("'Hello world!'");

function stubDateNow(stubValue, callback)
{
    var realDateNow = Date.now;
    Date.now = function() { return stubValue; }
    try {
        callback();
    } finally {
        Date.now = realDateNow;
    }
}

debug("Testing past dates. This should fail.");
stubDateNow(60000, function() {
    shouldBeNow("50000");
});

debug("Testing future dates. This should fail.");
stubDateNow(60000, function() {
    shouldBeNow("70000");
});

debug("Testing a slightly past date with the implicit delta. This should pass.");
stubDateNow(60000, function() {
    shouldBeNow("59990");
});

debug("Testing a slightly future date with the implicit delta. This should pass.");
stubDateNow(60000, function() {
    shouldBeNow("60010");
});

debug("Testing a past date with a large delta. This should pass.");
stubDateNow(60000, function() {
    shouldBeNow("50000", 10000);
});

debug("Testing a future date with a large delta. This should pass.");
stubDateNow(60000, function() {
    shouldBeNow("70000", 10000);
});

debug("Simulating a defective clock that always goes backwards. The test below should fail.");
var badClock = Date.now();
var realDateNow = Date.now;
Date.now = function() { return --badClock; }
shouldBeNow("new Date()");
Date.now = realDateNow;
</script>