Skip to content

Commit cd92052

Browse files
targoscodebytere
authored andcommitted
test: add hr-time Web platform tests
Refs: #32790 PR-URL: #33287 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 68551d2 commit cd92052

19 files changed

Lines changed: 537 additions & 0 deletions

‎test/fixtures/wpt/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Last update:
1717
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
1818
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
1919
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers
20+
- hr-time: https://github.com/web-platform-tests/wpt/tree/a5d1774ecf/hr-time
2021

2122
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2223
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt

‎test/fixtures/wpt/hr-time/META.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spec: https://w3c.github.io/hr-time/
2+
suggested_reviewers:
3+
- plehegar
4+
- igrigorik
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
test(function(){
2+
assert_true((self.performance!==undefined),"self.performance exists");
3+
assert_equals(typeofself.performance,"object","self.performance is an object");
4+
assert_equals((typeofself.performance.now),"function","self.performance.now() is a function");
5+
assert_equals(typeofself.performance.now(),"number","self.performance.now() returns a number");
6+
},"self.performance.now() is a function that returns a number");
7+
8+
test(function(){
9+
assert_true(self.performance.now()>0);
10+
},"self.performance.now() returns a positive number");
11+
12+
test(function(){
13+
varnow1=self.performance.now();
14+
varnow2=self.performance.now();
15+
assert_true((now2-now1)>=0);
16+
},"self.performance.now() difference is not negative");
17+
18+
async_test(function(){
19+
// Check whether the performance.now() method is close to Date() within 30ms (due to inaccuracies)
20+
varinitial_hrt=self.performance.now();
21+
varinitial_date=Date.now();
22+
this.step_timeout(function(){
23+
varfinal_hrt=self.performance.now();
24+
varfinal_date=Date.now();
25+
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');
26+
this.done();
27+
},2000);
28+
},'High resolution time has approximately the right relative magnitude');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// META: global=window,worker
2+
// META: script=/resources/WebIDLParser.js
3+
// META: script=/resources/idlharness.js
4+
// META: timeout=long
5+
6+
'use strict';
7+
8+
// https://w3c.github.io/hr-time/
9+
10+
idl_test(
11+
['hr-time'],
12+
['html','dom'],
13+
asyncidl_array=>{
14+
if(self.GLOBAL.isWorker()){
15+
idl_array.add_objects({WorkerGlobalScope: ['self']});
16+
}else{
17+
idl_array.add_objects({Window: ['self']});
18+
}
19+
idl_array.add_objects({
20+
Performance: ['performance'],
21+
});
22+
}
23+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// The time values returned when calling the now method MUST be monotonically increasing and not subject to system clock adjustments or system clock skew.
2+
test(function(){
3+
assert_true(self.performance.now()>0,"self.performance.now() returns positive numbers");
4+
},"self.performance.now() returns a positive number");
5+
6+
// The difference between any two chronologically recorded time values returned from the now method MUST never be negative.
7+
test(function(){
8+
varnow1=self.performance.now();
9+
varnow2=self.performance.now();
10+
assert_true((now2-now1)>=0,"self.performance.now() difference is not negative");
11+
},
12+
"self.performance.now() difference is not negative"
13+
);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<scriptsrc="/resources/testharness.js"></script>
5+
<scriptsrc="/resources/testharnessreport.js"></script>
6+
</head>
7+
<body>
8+
<script>
9+
10+
test(()=>{
11+
// Check Performance attributes.
12+
assert_equals(typeof(performance.toJSON),'function');
13+
constjson=performance.toJSON();
14+
assert_equals(typeof(json),'object');
15+
assert_equals(json.timeOrigin,performance.timeOrigin,
16+
'performance.toJSON().timeOrigin should match performance.timeOrigin');
17+
18+
// Check PerformanceTiming toJSON.
19+
constjsonTiming=json.timing;
20+
consttiming=performance.timing;
21+
assert_equals(typeof(timing.toJSON),'function');
22+
consttimingJSON=timing.toJSON();
23+
assert_equals(typeof(timingJSON),'object');
24+
// Check PerformanceTiming attributes, from both:
25+
// 1) |jsonTiming| from Performance.
26+
// 2) |timingJSON| from PerformanceTiming.
27+
constperformanceTimingKeys=[
28+
'navigationStart',
29+
'unloadEventStart',
30+
'unloadEventEnd',
31+
'redirectStart',
32+
'redirectEnd',
33+
'fetchStart',
34+
'domainLookupStart',
35+
'domainLookupEnd',
36+
'connectStart',
37+
'connectEnd',
38+
'secureConnectionStart',
39+
'requestStart',
40+
'responseStart',
41+
'responseEnd',
42+
'domLoading',
43+
'domInteractive',
44+
'domContentLoadedEventStart',
45+
'domContentLoadedEventEnd',
46+
'domComplete',
47+
'loadEventStart',
48+
'loadEventEnd'
49+
];
50+
for(constkeyofperformanceTimingKeys){
51+
assert_equals(jsonTiming[key],timing[key],
52+
`performance.toJSON().timing.${key} should match performance.timing.${key}`);
53+
assert_equals(timingJSON[key],timing[key],
54+
`performance.timing.toJSON().${key} should match performance.timing.${key}`);
55+
}
56+
57+
// Check PerformanceNavigation toJSON.
58+
constjsonNavigation=json.navigation;
59+
constnavigation=performance.navigation;
60+
assert_equals(typeof(navigation.toJSON),'function');
61+
constnavigationJSON=navigation.toJSON();
62+
assert_equals(typeof(navigationJSON),'object');
63+
// Check PerformanceNavigation attributes, from both:
64+
// 1) |jsonNavigation| from Performance.
65+
// 2) |navigationJSON| from PerformanceNavigation.
66+
letperformanceNavigationKeys=['type','redirectCount'];
67+
for(constkeyofperformanceNavigationKeys){
68+
assert_equals(jsonNavigation[key],navigation[key],
69+
`performance.toJSON().navigation.${key} should match performance.navigation.${key}`);
70+
assert_equals(navigationJSON[key],navigation[key],
71+
`performance.navigation.toJSON().${key} should match performance.navigation.${key}`);
72+
}
73+
},'Test performance.toJSON()');
74+
</script>
75+
</body>
76+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<metacontent="text/html; charset=utf-8" http-equiv="Content-Type" />
5+
<title>window.performance.now frame</title>
6+
<linkrel="author" title="Google" href="http://www.google.com/" />
7+
</head>
8+
<body></body>
9+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Helper page for ../unload-manual.html</title>
5+
</head>
6+
<body>
7+
<scriptsrc="./unload.js"></script>
8+
<script>
9+
setupListeners("a","./unload-b.html");
10+
</script>
11+
<buttonid="proceed">Click me!</button>
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Helper page for ../unload-manual.html</title>
5+
</head>
6+
<body>
7+
<scriptsrc="./unload.js"></script>
8+
<script>
9+
setupListeners("b","./unload-c.html");
10+
</script>
11+
<buttonid="proceed">Click me again!</button>
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Helper page for ../unload-manual.html</title>
5+
</head>
6+
<body>
7+
<scriptsrc="./unload.js"></script>
8+
<script>
9+
setupListeners("c",null);
10+
</script>
11+
<buttonid="proceed">Click me, one last time!</button>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)