Skip to content

Commit

Permalink
test: update user-timing web-platform tests
Browse files Browse the repository at this point in the history
PR-URL: #48321
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
anonrig authored Jun 5, 2023
1 parent 6327d45 commit 7f9fd76
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// META: script=/resources/idlharness-shadowrealm.js
idl_test_shadowrealm(["user-timing"], ["hr-time", "performance-timeline", "dom"]);
59 changes: 47 additions & 12 deletions test/fixtures/wpt/user-timing/mark-errors.any.js
Original file line number Diff line number Diff line change
@@ -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}`);
}
8 changes: 4 additions & 4 deletions test/fixtures/wpt/user-timing/measure-l3.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions test/fixtures/wpt/user-timing/resources/webperftestharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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.");

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"path": "url"
},
"user-timing": {
"commit": "df24fb604e2d40528ac1d1b5dd970e32fc5c2978",
"commit": "5ae85bf8267ac617833dc013dee9774c9e2a18b7",
"path": "user-timing"
},
"wasm/jsapi": {
Expand Down

0 comments on commit 7f9fd76

Please sign in to comment.