mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1558988 [wpt PR 17242] - Prevent fooling PerformanceObserver.supportedEntryTypes, a=testonly
Automatic update from web-platform-tests Prevent fooling PerformanceObserver.supportedEntryTypes (#17242) * Prevent fooling PerformanceObserver.supportedEntryTypes * Split between any and window * Long task is only on Window * CRLF -> LF -- wpt-commits: 2d2b6ee35d5f4c82c2f698fdb50c49583e8c7f70 wpt-pr: 17242
This commit is contained in:
parent
c8567f8059
commit
f4ed2a450c
@ -0,0 +1,6 @@
|
||||
spec: https://w3c.github.io/navigation-timing/
|
||||
suggested_reviewers:
|
||||
- plehegar
|
||||
- igrigorik
|
||||
- toddreifsteck
|
||||
- yoavweiss
|
@ -0,0 +1,25 @@
|
||||
// META: script=resources/utils.js
|
||||
|
||||
test(() => {
|
||||
assert_true(!!self.PerformanceObserver, "PerformanceObserver");
|
||||
assert_true(!!self.PerformanceObserver.supportedEntryTypes,
|
||||
"PerformanceObserver.supportedEntryTypes");
|
||||
}, "PerformanceObserver.supportedEntryTypes exists");
|
||||
|
||||
// UPDATE HERE if new entry
|
||||
[
|
||||
[ "mark", "PerformanceMark" ],
|
||||
[ "measure", "PerformanceMeasure" ],
|
||||
[ "resource", "PerformanceResourceTiming" ],
|
||||
].forEach(test_support);
|
||||
|
||||
// UPDATE BELOW to ensure the entry gets created
|
||||
|
||||
// mark
|
||||
self.performance.mark('mymark');
|
||||
|
||||
// measure
|
||||
self.performance.measure('mymeasure');
|
||||
|
||||
// resource
|
||||
fetch(self.location.href + "?" + Math.random());
|
@ -0,0 +1,33 @@
|
||||
// META: script=resources/utils.js
|
||||
|
||||
test(() => {
|
||||
assert_true(!!self.PerformanceObserver, "PerformanceObserver");
|
||||
assert_true(!!self.PerformanceObserver.supportedEntryTypes,
|
||||
"PerformanceObserver.supportedEntryTypes");
|
||||
}, "PerformanceObserver.supportedEntryTypes exists");
|
||||
|
||||
// UPDATE HERE if new entry
|
||||
[
|
||||
[ "navigation", "PerformanceNavigationTiming" ],
|
||||
[ "paint", "PerformancePaintTiming" ],
|
||||
[ "longtask", "PerformanceLongTaskTiming" ],
|
||||
].forEach(test_support);
|
||||
|
||||
// UPDATE BELOW to ensure the entry gets created
|
||||
|
||||
// paint
|
||||
if (self.document) document.head.parentNode.appendChild(document.createTextNode('text inserted on purpose'));
|
||||
|
||||
// longtask
|
||||
function syncWait(waitDuration) {
|
||||
if (waitDuration <= 0)
|
||||
return;
|
||||
|
||||
const startTime = performance.now();
|
||||
let unused = '';
|
||||
for (let i = 0; i < 10000; i++)
|
||||
unused += '' + Math.random();
|
||||
|
||||
return syncWait(waitDuration - (performance.now() - startTime));
|
||||
}
|
||||
syncWait(50);
|
@ -0,0 +1,29 @@
|
||||
const STEPS = {};
|
||||
|
||||
const types = (self.PerformanceObserver
|
||||
&& self.PerformanceObserver.supportedEntryTypes)?
|
||||
self.PerformanceObserver.supportedEntryTypes
|
||||
: undefined;
|
||||
|
||||
if (types) {
|
||||
// we observe everything as soon as possible
|
||||
new PerformanceObserver(function (list, observer) {
|
||||
for (const entry of list.getEntries())
|
||||
if (STEPS[entry.entryType]) STEPS[entry.entryType](entry);
|
||||
}).observe({entryTypes: self.PerformanceObserver.supportedEntryTypes});
|
||||
}
|
||||
|
||||
function test_support(def) {
|
||||
if (!types || !types.includes(def[0])) {
|
||||
return;
|
||||
}
|
||||
const desc = `'${def[0]}' entries should be observable`;
|
||||
const t = async_test(desc);
|
||||
|
||||
STEPS[def[0]] = (entry) => {
|
||||
t.step(() => assert_equals(Object.prototype.toString.call(entry),
|
||||
`[object ${def[1]}]`,
|
||||
`Class name of entry should be ${def[1]}.`));
|
||||
t.done();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user