mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: update user-timing web-platform tests
PR-URL: https://github.com/nodejs/node/pull/48321 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
parent
6327d4582a
commit
7f9fd76f25
2
test/fixtures/wpt/README.md
vendored
2
test/fixtures/wpt/README.md
vendored
@ -28,7 +28,7 @@ Last update:
|
||||
- resources: https://github.com/web-platform-tests/wpt/tree/919874f84f/resources
|
||||
- streams: https://github.com/web-platform-tests/wpt/tree/51750bc8d7/streams
|
||||
- url: https://github.com/web-platform-tests/wpt/tree/c4726447f3/url
|
||||
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
|
||||
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
|
||||
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
|
||||
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
|
||||
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/17b7ca10fd/WebCryptoAPI
|
||||
|
2
test/fixtures/wpt/user-timing/idlharness-shadowrealm.window.js
vendored
Normal file
2
test/fixtures/wpt/user-timing/idlharness-shadowrealm.window.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
// META: script=/resources/idlharness-shadowrealm.js
|
||||
idl_test_shadowrealm(["user-timing"], ["hr-time", "performance-timeline", "dom"]);
|
59
test/fixtures/wpt/user-timing/mark-errors.any.js
vendored
59
test/fixtures/wpt/user-timing/mark-errors.any.js
vendored
@ -1,15 +1,50 @@
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { self.performance.mark("mark1", 123); }, "Number passed as a dict argument should cause type-error.")
|
||||
}, "Number should be rejected as the mark-options.")
|
||||
// If you're testing an API that constructs a PerformanceMark, add your test here.
|
||||
// See the for loop below for details.
|
||||
const markConstructionTests = [
|
||||
{
|
||||
testName: "Number should be rejected as the mark-options.",
|
||||
testFunction: function(newMarkFunction) {
|
||||
assert_throws_js(TypeError, function() { newMarkFunction("mark1", 123); }, "Number passed as a dict argument should cause type-error.");
|
||||
},
|
||||
},
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { self.performance.mark("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.")
|
||||
}, "NaN should be rejected as the mark-options.")
|
||||
{
|
||||
testName: "NaN should be rejected as the mark-options.",
|
||||
testFunction: function(newMarkFunction) {
|
||||
assert_throws_js(TypeError, function() { newMarkFunction("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.");
|
||||
},
|
||||
},
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { self.performance.mark("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.")
|
||||
}, "Infinity should be rejected as the mark-options.")
|
||||
{
|
||||
testName: "Infinity should be rejected as the mark-options.",
|
||||
testFunction: function(newMarkFunction) {
|
||||
assert_throws_js(TypeError, function() { newMarkFunction("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.");
|
||||
},
|
||||
},
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { self.performance.mark("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
|
||||
}, "String should be rejected as the mark-options.")
|
||||
{
|
||||
testName: "String should be rejected as the mark-options.",
|
||||
testFunction: function(newMarkFunction) {
|
||||
assert_throws_js(TypeError, function() { newMarkFunction("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
testName: "Negative startTime in mark-options should be rejected",
|
||||
testFunction: function(newMarkFunction) {
|
||||
assert_throws_js(TypeError, function() { newMarkFunction("mark1", {startTime: -1}); }, "Negative startTime should cause type-error.")
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// There are multiple function calls that can construct a mark using the same arguments so we run
|
||||
// each test on each construction method here, avoiding duplication.
|
||||
for (let testInfo of markConstructionTests) {
|
||||
test(function() {
|
||||
testInfo.testFunction(self.performance.mark);
|
||||
}, `[performance.mark]: ${testInfo.testName}`);
|
||||
|
||||
test(function() {
|
||||
testInfo.testFunction((markName, obj) => new PerformanceMark(markName, obj));
|
||||
}, `[new PerformanceMark]: ${testInfo.testName}`);
|
||||
}
|
||||
|
@ -17,12 +17,12 @@ test(function() {
|
||||
performance.clearMarks();
|
||||
performance.clearMeasures();
|
||||
const markEntry = performance.mark("mark", {startTime: 123});
|
||||
const endMin = performance.now();
|
||||
const endMin = Number(performance.now().toFixed(2));
|
||||
const measureEntry = performance.measure("A", "mark", undefined);
|
||||
const endMax = performance.now();
|
||||
const endMax = Number(performance.now().toFixed(2));
|
||||
assert_equals(measureEntry.startTime, markEntry.startTime);
|
||||
assert_greater_than_equal(endTime(measureEntry), endMin);
|
||||
assert_greater_than_equal(endMax, endTime(measureEntry));
|
||||
assert_greater_than_equal(Number(endTime(measureEntry).toFixed(2)), endMin);
|
||||
assert_greater_than_equal(endMax, Number(endTime(measureEntry).toFixed(2)));
|
||||
}, "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.");
|
||||
|
||||
test(function() {
|
||||
|
@ -34,6 +34,15 @@ function onload_test()
|
||||
test_greater_than(0, context.getEntriesByName('negativeValue', 'measure')[0].duration, 'Measure of current mark to navigationStart should be negative value.');
|
||||
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".');
|
||||
|
||||
// We later assert that time has passed between setting one set of marks and another set.
|
||||
// However, this assertion will fail if the test executes fast enough such that the marks occur
|
||||
// at the same clock time. This is more likely in browsers such as Firefox that reduce the
|
||||
// precision of the clock exposed through this API to mitigate timing attacks. To mitigate the
|
||||
// test failure, we sleep. Firefox may round timestamps to the nearest millisecond in either
|
||||
// direction - e.g. 10ms & 11.999ms may both round to 11ms - so we need to sleep at least 2ms to
|
||||
// avoid test failures. To be safe, we sleep 3ms.
|
||||
sleep_milliseconds(3);
|
||||
|
||||
// Following cases test for scenarios that measure names are tied twice.
|
||||
mark_names.forEach(function(name) {
|
||||
context.mark(name);
|
||||
|
@ -6,4 +6,11 @@ test(() => {
|
||||
});
|
||||
}, "When converting 'navigationStart' to a timestamp, the global object has to be a Window object.");
|
||||
|
||||
test(() => {
|
||||
assert_throws_js(TypeError, () => {
|
||||
performance.mark('navigationStart');
|
||||
performance.measure('name', 'navigationStart', 'navigationStart');
|
||||
});
|
||||
}, "When converting 'navigationStart' to a timestamp and a mark named 'navigationStart' exists, the global object has to be a Window object.");
|
||||
|
||||
done();
|
||||
|
@ -110,12 +110,12 @@ function sleep_milliseconds(n)
|
||||
|
||||
function test_greater_than(value, greater_than, msg, properties)
|
||||
{
|
||||
wp_test(function () { assert_true(value > greater_than, msg); }, msg, properties);
|
||||
wp_test(function () { assert_greater_than(value, greater_than, msg); }, msg, properties);
|
||||
}
|
||||
|
||||
function test_greater_or_equals(value, greater_than, msg, properties)
|
||||
{
|
||||
wp_test(function () { assert_true(value >= greater_than, msg); }, msg, properties);
|
||||
wp_test(function () { assert_greater_than_equal(value, greater_than, msg); }, msg, properties);
|
||||
}
|
||||
|
||||
function test_not_equals(value, notequals, msg, properties)
|
||||
|
@ -10,6 +10,7 @@ test(function() {
|
||||
performance.clearMarks();
|
||||
const detail = { randomInfo: 123 }
|
||||
const markEntry = performance.mark("A", { detail });
|
||||
assert_equals(markEntry.detail.randomInfo, detail.randomInfo);
|
||||
assert_not_equals(markEntry.detail, detail);
|
||||
}, "The detail property in the mark method should be structured-clone.");
|
||||
|
||||
@ -31,6 +32,7 @@ test(function() {
|
||||
performance.clearMeasures();
|
||||
const detail = { randomInfo: 123 }
|
||||
const measureEntry = performance.measure("A", { start: 0, detail });
|
||||
assert_equals(measureEntry.detail.randomInfo, detail.randomInfo);
|
||||
assert_not_equals(measureEntry.detail, detail);
|
||||
}, "The detail property in the measure method should be structured-clone.");
|
||||
|
||||
|
2
test/fixtures/wpt/versions.json
vendored
2
test/fixtures/wpt/versions.json
vendored
@ -72,7 +72,7 @@
|
||||
"path": "url"
|
||||
},
|
||||
"user-timing": {
|
||||
"commit": "df24fb604e2d40528ac1d1b5dd970e32fc5c2978",
|
||||
"commit": "5ae85bf8267ac617833dc013dee9774c9e2a18b7",
|
||||
"path": "user-timing"
|
||||
},
|
||||
"wasm/jsapi": {
|
||||
|
Loading…
Reference in New Issue
Block a user