-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream high resolution event timestamp test to WPT.
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
1 parent
199b65f
commit 2b27aa0
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |