Skip to content

Commit

Permalink
[ResourceTiming] Cleanup buffer-full tests
Browse files Browse the repository at this point in the history
Change-Id: Ic5f9968f5c0a1c9b5ad4760f4aa2d8ee85c73c40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2911104
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Tom McKee <tommckee@chromium.org>
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#887367}
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed May 27, 2021
1 parent 98d7820 commit 8a1c14c
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 488 deletions.
82 changes: 12 additions & 70 deletions resource-timing/buffer-full-add-after-full-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,26 @@
<html>
<head>
<meta charset="utf-8">
<link rel="help" href="https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize">
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#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/resource-loaders.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()).then(r => r.text());
}

setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(100);
});

let loadResourcesToFillFutureBuffer = () => {
promise_test(async t => {
await forceBufferFullEvent();
performance.clearResourceTimings();
return new Promise(resolve => {
// Gather up 3 Resource Entries to kick off the rest of test behavior.
let resources = 0;
let observer = new PerformanceObserver(function(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();
new PerformanceObserver(t.step_func(() => {
assert_equals(performance.getEntriesByType('resource').length, 1,
'The entry should be available in the performance timeline!');
resolve();
})).observe({type: 'resource'});
load.script(scriptResources[2]);
});
};

let setBufferFullEventAndBufferSize = () => {
performance.setResourceTimingBufferSize(3);
performance.onresourcetimingbufferfull = function() {
eventFired = true;
performance.clearResourceTimings();
};
};

let clearAndAddAnotherEntryToBuffer = () => {
return new Promise(resolve => {
performance.clearResourceTimings();
loadRandomResource().then(resolve);
});
};

let testThatEntryWasAdded = () => {
let tries = 1;
let maxTries = 5;
return waitUntilConditionIsMet( function() {
if (performance.getEntriesByType("resource").length) {
return true;
} else {
if (tries < maxTries) {
tries++;
return false;
} else {
return true;
}
}
}).then( () => {
assert_true((performance.getEntriesByType("resource").length) === 1);
});
};

promise_test(async () => {
await loadResourcesToFillFutureBuffer();
setBufferFullEventAndBufferSize();
// Overflow the buffer.
await loadRandomResource();
await waitForEventToFire();
await clearAndAddAnotherEntryToBuffer();
// Since we have no strict guarantees when an entry will be added to the
// buffer, waiting till next task to try to avoid flakiness.
await testThatEntryWasAdded();
}, "Test that entry was added to the buffer after a buffer full event");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,26 @@
<head onload>
<meta charset="utf-8" />
<title>This test validates that synchronously adding entries in onresourcetimingbufferfull callback results in these entries being properly handled.</title>
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performance-onresourcetimingbufferfull"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;

setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(resource_timing_buffer_size);
});

let overflowTheBufferAndWaitForEvent = () => {
return new Promise(resolve => {
var add_entry = () => {
performance.setResourceTimingBufferSize(resource_timing_buffer_size + 1);
// The sync entry is added to the secondary buffer, so will be the last one there and eventually dropped.
xhrScript("resources/empty.js?xhr");
resolve();
}
performance.addEventListener('resourcetimingbufferfull', add_entry);
// This resource overflows the entry buffer, and goes into the secondary buffer.
appendScript('resources/empty_script.js');
});
};

let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 2,
'Both entries should be stored in resource timing buffer since its increases size once it overflows.');
assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
assert_true(entries[1].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
};

promise_test(async () => {
await fillUpTheBufferWithSingleResource("resources/empty.js");
await overflowTheBufferAndWaitForEvent();
// TODO(yoav): Figure out why this task is needed
await waitForNextTask();
testThatBufferContainsTheRightResources();
await fillUpTheBufferWithSingleResource();
performance.addEventListener('resourcetimingbufferfull', () => {
performance.setResourceTimingBufferSize(2);
// The sync entry is added to the secondary buffer, so will be the last one there and eventually dropped.
load.xhr_sync(scriptResources[2]);
});
// This resource overflows the entry buffer, and goes into the secondary buffer.
load.script(scriptResources[1]);
await bufferFullFirePromise;
checkEntries(2);
}, "Test that entries synchronously added to the buffer during the callback are dropped");
</script>
</body>
Expand Down
46 changes: 12 additions & 34 deletions resource-timing/buffer-full-add-entries-during-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,25 @@
<head onload>
<meta charset="utf-8" />
<title>This test validates that synchronously adding entries in onresourcetimingbufferfull callback results in these entries being properly handled.</title>
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performance-onresourcetimingbufferfull"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;

setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(resource_timing_buffer_size);
});

let overflowTheBufferAndWaitForEvent = () => {
return new Promise(resolve => {
var add_entry = () => {
performance.setResourceTimingBufferSize(resource_timing_buffer_size + 2);
xhrScript("resources/empty.js?xhr");
resolve();
}
performance.addEventListener('resourcetimingbufferfull', add_entry);
// This resource overflows the entry buffer, and goes into the secondary buffer.
appendScript('resources/empty_script.js');
});
};

let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 3,
'All entries should be stored in resource timing buffer since its increases size once it overflows.');
assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
assert_true(entries[1].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
assert_true(entries[2].name.includes('empty.js?xhr'), "empty.js?xhr is in the entries buffer");
};

promise_test(async () => {
await fillUpTheBufferWithSingleResource("resources/empty.js");
await overflowTheBufferAndWaitForEvent();
await waitForNextTask();
testThatBufferContainsTheRightResources();
await fillUpTheBufferWithSingleResource();
performance.addEventListener('resourcetimingbufferfull', () => {
performance.setResourceTimingBufferSize(3);
load.xhr_sync(scriptResources[2]);
});
// This resource overflows the entry buffer, and goes into the secondary buffer.
load.script(scriptResources[1]);
await bufferFullFirePromise;
checkEntries(3);
}, "Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased");
</script>
</body>
Expand Down
42 changes: 12 additions & 30 deletions resource-timing/buffer-full-add-then-clear.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,28 @@
<head onload>
<meta charset="utf-8" />
<title>This test validates that synchronously adding entries in onresourcetimingbufferfull callback results in these entries being properly handled.</title>
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performance-onresourcetimingbufferfull"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;

setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(resource_timing_buffer_size);
performance.addEventListener('resourcetimingbufferfull', () => { assert_unreached("resourcetimingbufferfull should not fire")});
});

let overflowTheBuffer = () => {
promise_test(async t => {
addAssertUnreachedBufferFull(t);
await fillUpTheBufferWithSingleResource('resources/empty.js?willbelost');
// These resources overflow the entry buffer, and go into the secondary buffer.
xhrScript('resources/empty.js?xhr2');
xhrScript('resources/empty.js?xhr3');
load.xhr_sync(scriptResources[0]);
load.xhr_sync(scriptResources[1]);
performance.clearResourceTimings();
performance.setResourceTimingBufferSize(3);
xhrScript('resources/empty.js?xhr4');
window.entriesAfterAddition = performance.getEntriesByType('resource');
};

let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 3,
'the last 3 resources should be in the buffer, since the first one was cleared');
assert_true(entries[0].name.includes('empty.js?xhr2'), "empty.js?xhr2 is in the entries buffer");
assert_true(entries[1].name.includes('empty.js?xhr3'), "empty.js?xhr3 is in the entries buffer");
assert_true(entries[2].name.includes('empty.js?xhr4'), "empty.js?xhr4 is in the entries buffer");
assert_equals(entriesAfterAddition.length, 0, "No entries should have been added to the primary buffer before the task to 'fire a buffer full event'.");
};

promise_test(async () => {
await fillUpTheBufferWithSingleResource("resources/empty.js");
overflowTheBuffer();
load.xhr_sync(scriptResources[2]);
const entriesAfterAddition = performance.getEntriesByType('resource');
await waitForNextTask();
testThatBufferContainsTheRightResources();
checkEntries(3);
assert_equals(entriesAfterAddition.length, 0, "No entries should have been added to the primary buffer before the task to 'fire a buffer full event'.");
}, "Test that if the buffer is cleared after entries were added to the secondary buffer, those entries make it into the primary one");
</script>
</body>
Expand Down
43 changes: 10 additions & 33 deletions resource-timing/buffer-full-decrease-buffer-during-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,23 @@
<head onload>
<meta charset="utf-8" />
<title>This test validates that decreasing the buffer size in onresourcetimingbufferfull callback does not result in extra entries being dropped.</title>
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performance-onresourcetimingbufferfull"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 2;
let eventFired = false;
setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(resource_timing_buffer_size);
let resize = () => {
performance.setResourceTimingBufferSize(resource_timing_buffer_size - 1);
eventFired = true;
}
performance.addEventListener('resourcetimingbufferfull', resize);
});

let overflowTheBuffer = () => {
return new Promise(resolve => {
// This resource overflows the entry buffer, and goes into the secondary buffer.
// Since the buffer size doesn't increase, it will eventually be dropped.
appendScript('resources/empty_script.js', resolve);
});
};

let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 2,
'Both entries should be stored in resource timing buffer since it decreased its limit only after it overflowed.');
assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
assert_true(entries[1].name.includes('empty.js?second'), "empty.js?second is in the entries buffer");
};

promise_test(async () => {
await fillUpTheBufferWithTwoResources('resources/empty.js');
await overflowTheBuffer();
await waitForEventToFire();
testThatBufferContainsTheRightResources();
performance.addEventListener('resourcetimingbufferfull', () => {
performance.setResourceTimingBufferSize(1);
});
await fillUpTheBufferWithTwoResources();
load.script(scriptResources[2]);
await bufferFullFirePromise;
checkEntries(2);
}, "Test that decreasing the buffer limit during the callback does not drop entries");
</script>
</body>
Expand Down
43 changes: 10 additions & 33 deletions resource-timing/buffer-full-increase-buffer-during-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,23 @@
<head onload>
<meta charset="utf-8" />
<title>This test validates increasing the buffer size in onresourcetimingbufferfull callback of resource timing.</title>
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performance-onresourcetimingbufferfull"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;
let eventFired = false;

setup(() => {
// Get the browser into a consistent state.
clearBufferAndSetSize(resource_timing_buffer_size);
var increase = function() {
performance.setResourceTimingBufferSize(resource_timing_buffer_size * 2);
eventFired = true;
}
performance.addEventListener('resourcetimingbufferfull', increase);
});

let overflowTheBuffer = () => {
return new Promise(resolve => {
// This resource overflows the entry buffer, and goes into the secondary buffer.
appendScript('resources/empty_script.js', resolve);
});
};

let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 2,
'Both entries should be stored in resource timing buffer since its increases size once it overflows.');
assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
assert_true(entries[1].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
};

promise_test(async () => {
await fillUpTheBufferWithSingleResource("resources/empty.js");
await overflowTheBuffer();
await waitForEventToFire();
testThatBufferContainsTheRightResources();
await fillUpTheBufferWithSingleResource();
performance.addEventListener('resourcetimingbufferfull', () => {
performance.setResourceTimingBufferSize(2);
});
await load.script(scriptResources[1]);
await bufferFullFirePromise;
checkEntries(2);
}, "Test that increasing the buffer during the callback is enough for entries not to be dropped");
</script>
</body>
Expand Down

0 comments on commit 8a1c14c

Please sign in to comment.