DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (8ec2329bef74)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
<!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>