2012-04-27 00:22:06 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for High Resolution Timer</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
2012-05-07 08:44:26 -07:00
|
|
|
ok(window.performance, "Performance object should exist.");
|
|
|
|
ok(typeof window.performance.now == 'function', "Performance object should have a 'now' method.");
|
|
|
|
var n = window.performance.now(), d = Date.now();
|
|
|
|
ok(n >= 0, "The value of now() should be equal to or greater than 0.");
|
|
|
|
ok(window.performance.now() >= n, "The value of now() should monotonically increase.");
|
2012-04-27 00:22:06 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2012-05-07 08:44:26 -07:00
|
|
|
|
|
|
|
var checks = 0;
|
|
|
|
function checkAfterTimeout() {
|
|
|
|
checks++;
|
|
|
|
var d2 = Date.now();
|
|
|
|
// Timeouts aren't extremely reliable and especially on Windows we are prone to fallback to
|
|
|
|
// millisecond timers, in which case this test might occasionally fail. This is a workaround:
|
|
|
|
if (navigator.platform.indexOf("Win") == 0 &&
|
|
|
|
window.performance.now() == n && d == d2 &&
|
|
|
|
checks < 5) {
|
|
|
|
setTimeout(checkAfterTimeout, 20);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(window.performance.now() > n, "After a timeout, the value of now() should be strictly greater than before.");
|
2012-04-27 00:22:06 -07:00
|
|
|
SimpleTest.finish();
|
2012-05-07 08:44:26 -07:00
|
|
|
};
|
|
|
|
setTimeout(checkAfterTimeout, 20);
|
2012-04-27 00:22:06 -07:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|