blob: 218fc0c2bcd5f987c2aee511bb66fd338476215f [file] [log] [blame]
<!DOCTYPE HTML>
<html>
<head onload>
<meta charset="utf-8" />
<title>This test validates the behavior of read and clear operation in onresourcetimingbufferfull callback of resource timing.</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webperftestharness.js"></script>
<script src="resources/webperftestharnessextension.js"></script>
</head>
<body onload=onload_test()>
<script>
const context = new PerformanceContext(performance);
const resource_timing_buffer_size = 1;
let global_buffer = [];
function store_and_clear() {
const entryList = context.getEntriesByType('resource');
entryList.forEach(function (entry) {
global_buffer.push(entry);
});
context.clearResourceTimings();
}
context.registerResourceTimingBufferFullCallback(store_and_clear);
context.setResourceTimingBufferSize(resource_timing_buffer_size);
// Scripts appended in JS to ensure setResourceTimingBufferSize is called before.
function appendScript(src) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
document.body.appendChild(script);
}
appendScript('resources/empty.js');
appendScript('resources/empty_script.js');
appendScript('resources/resource_timing_test0.js');
setup({ explicit_done: true });
function onload_test() {
test_equals(context.getEntriesByType('resource').length, 0, 'No entry should be stored in resource timing buffer since its cleared once an item arrived.');
// The entry for empty.js must not be in the global buffer, but all others should be.
test_equals(global_buffer.length, 6, '6 resource timing entries should be moved to global buffer.');
const index = window.location.pathname.lastIndexOf('resource-timing');
const pathname = window.location.pathname.substring(0, index);
let expected_entries = {};
expected_entries[pathname + 'resources/testharness.js'] = 'script';
expected_entries[pathname + 'resources/testharnessreport.js'] = 'script';
expected_entries[pathname + 'resource-timing/resources/webperftestharness.js'] = 'script';
expected_entries[pathname + 'resource-timing/resources/webperftestharnessextension.js'] = 'script';
expected_entries[pathname + 'resource-timing/resources/empty_script.js'] = 'script';
expected_entries[pathname + 'resource-timing/resources/resource_timing_test0.js'] = 'script';
test_resource_entries(global_buffer, expected_entries);
done();
}
</script>
</body>
</html>