Skip to content

Commit 3da57d1

Browse files
anonrigruyadorno
authored andcommittedAug 29, 2023
test: update user-timing web-platform tests
PR-URL: #48321 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent fe9da9d commit 3da57d1

9 files changed

+75
-20
lines changed
 

‎test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Last update:
2828
- resources: https://github.com/web-platform-tests/wpt/tree/fbf1e7d247/resources
2929
- streams: https://github.com/web-platform-tests/wpt/tree/9e5ef42bd3/streams
3030
- url: https://github.com/web-platform-tests/wpt/tree/7c5c3cc125/url
31-
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
31+
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3232
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3333
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
3434
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/17b7ca10fd/WebCryptoAPI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// META: script=/resources/idlharness-shadowrealm.js
2+
idl_test_shadowrealm(["user-timing"], ["hr-time", "performance-timeline", "dom"]);
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
1-
test(function() {
2-
assert_throws_js(TypeError, function() { self.performance.mark("mark1", 123); }, "Number passed as a dict argument should cause type-error.")
3-
}, "Number should be rejected as the mark-options.")
1+
// If you're testing an API that constructs a PerformanceMark, add your test here.
2+
// See the for loop below for details.
3+
const markConstructionTests = [
4+
{
5+
testName: "Number should be rejected as the mark-options.",
6+
testFunction: function(newMarkFunction) {
7+
assert_throws_js(TypeError, function() { newMarkFunction("mark1", 123); }, "Number passed as a dict argument should cause type-error.");
8+
},
9+
},
410

5-
test(function() {
6-
assert_throws_js(TypeError, function() { self.performance.mark("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.")
7-
}, "NaN should be rejected as the mark-options.")
11+
{
12+
testName: "NaN should be rejected as the mark-options.",
13+
testFunction: function(newMarkFunction) {
14+
assert_throws_js(TypeError, function() { newMarkFunction("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.");
15+
},
16+
},
817

9-
test(function() {
10-
assert_throws_js(TypeError, function() { self.performance.mark("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.")
11-
}, "Infinity should be rejected as the mark-options.")
18+
{
19+
testName: "Infinity should be rejected as the mark-options.",
20+
testFunction: function(newMarkFunction) {
21+
assert_throws_js(TypeError, function() { newMarkFunction("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.");
22+
},
23+
},
1224

13-
test(function() {
14-
assert_throws_js(TypeError, function() { self.performance.mark("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
15-
}, "String should be rejected as the mark-options.")
25+
{
26+
testName: "String should be rejected as the mark-options.",
27+
testFunction: function(newMarkFunction) {
28+
assert_throws_js(TypeError, function() { newMarkFunction("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
29+
},
30+
},
31+
32+
{
33+
testName: "Negative startTime in mark-options should be rejected",
34+
testFunction: function(newMarkFunction) {
35+
assert_throws_js(TypeError, function() { newMarkFunction("mark1", {startTime: -1}); }, "Negative startTime should cause type-error.")
36+
},
37+
},
38+
];
39+
40+
// There are multiple function calls that can construct a mark using the same arguments so we run
41+
// each test on each construction method here, avoiding duplication.
42+
for (let testInfo of markConstructionTests) {
43+
test(function() {
44+
testInfo.testFunction(self.performance.mark);
45+
}, `[performance.mark]: ${testInfo.testName}`);
46+
47+
test(function() {
48+
testInfo.testFunction((markName, obj) => new PerformanceMark(markName, obj));
49+
}, `[new PerformanceMark]: ${testInfo.testName}`);
50+
}

‎test/fixtures/wpt/user-timing/measure-l3.any.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ test(function() {
1717
performance.clearMarks();
1818
performance.clearMeasures();
1919
const markEntry = performance.mark("mark", {startTime: 123});
20-
const endMin = performance.now();
20+
const endMin = Number(performance.now().toFixed(2));
2121
const measureEntry = performance.measure("A", "mark", undefined);
22-
const endMax = performance.now();
22+
const endMax = Number(performance.now().toFixed(2));
2323
assert_equals(measureEntry.startTime, markEntry.startTime);
24-
assert_greater_than_equal(endTime(measureEntry), endMin);
25-
assert_greater_than_equal(endMax, endTime(measureEntry));
24+
assert_greater_than_equal(Number(endTime(measureEntry).toFixed(2)), endMin);
25+
assert_greater_than_equal(endMax, Number(endTime(measureEntry).toFixed(2)));
2626
}, "When the start mark is given and the end is unprovided, the start time of the measure entry should be the start mark's time, the end should be now.");
2727

2828
test(function() {

‎test/fixtures/wpt/user-timing/measure_associated_with_navigation_timing.html

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
test_greater_than(0, context.getEntriesByName('negativeValue', 'measure')[0].duration, 'Measure of current mark to navigationStart should be negative value.');
3535
test_equals(context.getEntriesByName('loadTime', 'measure')[0].duration + context.getEntriesByName('loadEventEnd2a', 'measure')[0].duration, context.getEntriesByName('nav2a', 'measure')[0].duration, 'loadTime plus loadEventEnd to a mark "a" should equal to navigationStart to "a".');
3636

37+
// We later assert that time has passed between setting one set of marks and another set.
38+
// However, this assertion will fail if the test executes fast enough such that the marks occur
39+
// at the same clock time. This is more likely in browsers such as Firefox that reduce the
40+
// precision of the clock exposed through this API to mitigate timing attacks. To mitigate the
41+
// test failure, we sleep. Firefox may round timestamps to the nearest millisecond in either
42+
// direction - e.g. 10ms & 11.999ms may both round to 11ms - so we need to sleep at least 2ms to
43+
// avoid test failures. To be safe, we sleep 3ms.
44+
sleep_milliseconds(3);
45+
3746
// Following cases test for scenarios that measure names are tied twice.
3847
mark_names.forEach(function(name) {
3948
context.mark(name);

‎test/fixtures/wpt/user-timing/performance-measure-invalid.worker.js

+7
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ test(() => {
66
});
77
}, "When converting 'navigationStart' to a timestamp, the global object has to be a Window object.");
88

9+
test(() => {
10+
assert_throws_js(TypeError, () => {
11+
performance.mark('navigationStart');
12+
performance.measure('name', 'navigationStart', 'navigationStart');
13+
});
14+
}, "When converting 'navigationStart' to a timestamp and a mark named 'navigationStart' exists, the global object has to be a Window object.");
15+
916
done();

‎test/fixtures/wpt/user-timing/resources/webperftestharness.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ function sleep_milliseconds(n)
110110

111111
function test_greater_than(value, greater_than, msg, properties)
112112
{
113-
wp_test(function () { assert_true(value > greater_than, msg); }, msg, properties);
113+
wp_test(function () { assert_greater_than(value, greater_than, msg); }, msg, properties);
114114
}
115115

116116
function test_greater_or_equals(value, greater_than, msg, properties)
117117
{
118-
wp_test(function () { assert_true(value >= greater_than, msg); }, msg, properties);
118+
wp_test(function () { assert_greater_than_equal(value, greater_than, msg); }, msg, properties);
119119
}
120120

121121
function test_not_equals(value, notequals, msg, properties)

‎test/fixtures/wpt/user-timing/structured-serialize-detail.any.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test(function() {
1010
performance.clearMarks();
1111
const detail = { randomInfo: 123 }
1212
const markEntry = performance.mark("A", { detail });
13+
assert_equals(markEntry.detail.randomInfo, detail.randomInfo);
1314
assert_not_equals(markEntry.detail, detail);
1415
}, "The detail property in the mark method should be structured-clone.");
1516

@@ -31,6 +32,7 @@ test(function() {
3132
performance.clearMeasures();
3233
const detail = { randomInfo: 123 }
3334
const measureEntry = performance.measure("A", { start: 0, detail });
35+
assert_equals(measureEntry.detail.randomInfo, detail.randomInfo);
3436
assert_not_equals(measureEntry.detail, detail);
3537
}, "The detail property in the measure method should be structured-clone.");
3638

‎test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"path": "url"
7373
},
7474
"user-timing": {
75-
"commit": "df24fb604e2d40528ac1d1b5dd970e32fc5c2978",
75+
"commit": "5ae85bf8267ac617833dc013dee9774c9e2a18b7",
7676
"path": "user-timing"
7777
},
7878
"wasm/jsapi": {

0 commit comments

Comments
 (0)
Please sign in to comment.