Skip to content

Commit

Permalink
Upstream high resolution event timestamp test to WPT.
Browse files Browse the repository at this point in the history
This is in anticipation of DOM spec patch landing [1].
Upstreaming two tests:
 - verify constructed events get a high-resolution time from perfomance.now()
 - verify the minimum resolution is larger that 5µs.

[1] whatwg/dom#23
[2] whatwg/dom#420

BUG=538600

Review-Url: https://codereview.chromium.org/2744553007
Cr-Commit-Position: refs/heads/master@{#485966}
  • Loading branch information
majido authored and chromium-wpt-export-bot committed Jul 12, 2017
1 parent f2a1304 commit 0a0c7d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dom/events/Event-timestamp-high-resolution.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
'use strict';
for (let eventType of [MouseEvent, KeyboardEvent, WheelEvent, GamepadEvent, FocusEvent]) {
test(function() {
let before = performance.now();
let e = new eventType('test');
let after = performance.now();
assert_greater_than_equal(e.timeStamp, before, "Event timestamp should be greater than performance.now() timestamp taken before its creation");
assert_less_than_equal(e.timeStamp, after, "Event timestamp should be less than performance.now() timestamp taken after its creation");
}, `Constructed ${eventType.prototype.constructor.name} timestamp should be high resolution and have the same time origin as performance.now()`);
}
</script>
20 changes: 20 additions & 0 deletions dom/events/Event-timestamp-safe-resolution.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
'use strict';

test(function() {
let e1 = new MouseEvent('test1');
let e2 = new MouseEvent('test2');

while (e1.timeStamp == e2.timeStamp)
e2 = new MouseEvent('test2');

let expectedResolutionMilliseconds = 0.005;
let integerMultipleOfResolution = (e2.timeStamp - e1.timeStamp) / expectedResolutionMilliseconds;
let shouldBeNearZeroOrOne = integerMultipleOfResolution % 1;
assert_true(shouldBeNearZeroOrOne < 1e-10 || Math.abs(shouldBeNearZeroOrOne - 1) < 1e-10);
}, 'Event timestamp should not have a resolution better that 5 microseconds');
</script>

0 comments on commit 0a0c7d8

Please sign in to comment.