Skip to content

Commit

Permalink
Timestamp fix for issue servo#5690
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Jun 5, 2015
1 parent ad5846f commit 1612f72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/script/dom/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> PerformanceMethods for JSRef<'a, Performance> {
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
fn Now(self) -> DOMHighResTimeStamp {
let navStart = self.timing.root().r().NavigationStartPrecise();
let now = (time::precise_time_ns() as f64 - navStart) * 1000000 as f64;
let now = (time::precise_time_ns() as f64 - navStart) / 1000000 as f64;
Finite::wrap(now)
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/wpt/include.ini
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ skip: true
skip: false
[_mozilla]
skip: false
[hr-time]
skip: false
8 changes: 8 additions & 0 deletions tests/wpt/metadata/hr-time/test_cross_frame_start.html.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[test_cross_frame_start.html]
type: testharness
[Child created at least 1 second after parent]
expected: FAIL

[Child and parent time bases are correct]
expected: FAIL

12 changes: 12 additions & 0 deletions tests/wpt/web-platform-tests/hr-time/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
test(function() {
assert_equals(typeof window.performance.now(), "number", "window.performance.now() returns a number");
}, "window.performance.now() returns a number", {assert: "The now method MUST return a DOMHighResTimeStamp"});

async_test(function() {
// Check whether the performance.now() method is close to Date() within 30ms (due to inaccuracies)
var initial_hrt = performance.now();
var initial_date = Date.now();
setTimeout(this.step_func(function() {
var final_hrt = performance.now();
var final_date = Date.now();
assert_approx_equals(final_hrt - initial_hrt, final_date - initial_date, 30, 'High resolution time value increased by approximately the same amount as time from date object');
this.done();
}), 2000);
}, 'High resolution time has approximately the right relative magnitude');
</script>
</head>
<body>
Expand Down

0 comments on commit 1612f72

Please sign in to comment.