mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
Automatic update from web-platform-tests Align resource timing buffer full processing to spec PR 168 (take 3) This change implements the processing model from PR 168[1], when it comes to setResourceTimingBufferSize(), clearResourceTimings() and the firing of the resourcetimingbufferfull event. This is a reland of [2] which is a reland of [3] (but with nicer tests). [1] https://github.com/w3c/resource-timing/pull/168 [2] https://chromium-review.googlesource.com/c/chromium/src/+/1350950 [3] https://chromium-review.googlesource.com/c/chromium/src/+/1345269 Bug: 908181, 908414 Change-Id: I3a6c6e9d6a9aa5b5f907d1e86bec701ff2fa022d Reviewed-on: https://chromium-review.googlesource.com/c/1373819 Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Commit-Queue: Yoav Weiss <yoavweiss@chromium.org> Cr-Commit-Position: refs/heads/master@{#615929} -- wpt-commits: 79001b1d0d4a111b7f44608404d7b5504d755a1c wpt-pr: 14479
82 lines
2.6 KiB
HTML
82 lines
2.6 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="help" href="https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize">
|
|
<title>This test validates that setResourceTimingBufferFull behaves appropriately when set to the current buffer level.</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/buffer-full-utilities.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
let eventFired = false;
|
|
|
|
let loadRandomResource = () => {
|
|
return fetch(window.location.href + "?" + Math.random());
|
|
};
|
|
|
|
setup(() => {
|
|
// Get the browser into a consistent state.
|
|
clearBufferAndSetSize(100);
|
|
window.result = "";
|
|
});
|
|
|
|
let fillUpTheBuffer = () => {
|
|
return new Promise(resolve => {
|
|
// Gather up 3 Resource Entries to kick off the rest of test behavior.
|
|
let resources = 0;
|
|
let observer = new PerformanceObserver(list => {
|
|
resources += list.getEntriesByType("resource").length;
|
|
if (resources !== 3)
|
|
return;
|
|
observer.disconnect();
|
|
resolve();
|
|
});
|
|
observer.observe({entryTypes: ["resource"]});
|
|
for (let i = 0; i < 3; ++i)
|
|
loadRandomResource();
|
|
});
|
|
};
|
|
|
|
let setBufferSize = () => {
|
|
performance.onresourcetimingbufferfull = () => {
|
|
eventFired = true;
|
|
window.result += "Event Fired with " + performance.getEntriesByType("resource").length + " entries. ";
|
|
performance.clearResourceTimings();
|
|
};
|
|
window.result += "before setLimit(3). ";
|
|
performance.setResourceTimingBufferSize(3);
|
|
window.result += "after setLimit(3). ";
|
|
};
|
|
|
|
let overflowTheBuffer = () => {
|
|
return new Promise(resolve => {
|
|
loadRandomResource().then(() => {
|
|
window.result += "after loading 4th resource. ";
|
|
resolve();
|
|
});
|
|
});
|
|
};
|
|
|
|
let checkResult = () => {
|
|
return new Promise((resolve, reject) => {
|
|
if (window.result != "before setLimit(3). after setLimit(3). after loading 4th resource. Event Fired with 3 entries. ") {
|
|
reject("Non matching value: " + window.result);
|
|
}
|
|
let entries = performance.getEntriesByType("resource");
|
|
if (entries.length != 1) {
|
|
reject("Number of entries in resource timing buffer is unexpected: " + entries.length);
|
|
}
|
|
resolve();
|
|
});
|
|
};
|
|
|
|
promise_test(async () => {
|
|
await fillUpTheBuffer();
|
|
setBufferSize();
|
|
await overflowTheBuffer();
|
|
await waitForEventToFire();
|
|
await checkResult();
|
|
}, "Test that entries added and event firing happened in the right sequence");
|
|
</script>
|