Bug 1509859 [wpt PR 14234] - Align resource timing buffer full processing to spec PR 168 (reland), a=testonly

Automatic update from web-platform-tests
Align resource timing buffer full processing to spec PR 168 (reland)

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
https://chromium-review.googlesource.com/c/chromium/src/+/1345269
(but with nicer tests).

[1] https://github.com/w3c/resource-timing/pull/168

Change-Id: I10431bfda7f79b484c7ee5c608bb8a360d905339
Bug: 908181, 908414
Reviewed-on: https://chromium-review.googlesource.com/c/1350950
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611174}

--

wpt-commits: cccb52680a601f4de432124092c808e91fad8a15
wpt-pr: 14234
This commit is contained in:
Yoav Weiss 2018-11-30 18:04:00 +00:00 коммит произвёл moz-wptsync-bot
Родитель 5dc8b08c41
Коммит 81475a7768
15 изменённых файлов: 669 добавлений и 106 удалений

Просмотреть файл

@ -0,0 +1,77 @@
<!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);
});
let loadResourcesToFillFutureBuffer = () => {
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();
});
};
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 = () => {
return new Promise((resolve, reject) => {
let waitForIt = function() {
if (performance.getEntriesByType("resource").length) {
resolve();
} else {
reject("After buffer full, entry never added to primary");
}
}
step_timeout(waitForIt, 0);
});
};
promise_test(async () => {
await loadResourcesToFillFutureBuffer();
setBufferFullEventAndBufferSize();
// Overflow the buffer.
await loadRandomResource();
await waitForEventToFire();
await clearAndAddAnotherEntryToBuffer();
await testThatEntryWasAdded();
}, "Test that entry was added to the buffer after a buffer full event");
</script>

Просмотреть файл

@ -0,0 +1,51 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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();
}, "Test that entries synchronously added to the buffer during the callback are dropped");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,50 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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();
}, "Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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 = () => {
// These resources overflow the entry buffer, and go into the secondary buffer.
xhrScript('resources/empty.js?xhr2');
xhrScript('resources/empty.js?xhr3');
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();
await waitForNextTask();
testThatBufferContainsTheRightResources();
}, "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>
</html>

Просмотреть файл

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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();
}, "Test that decreasing the buffer limit during the callback does not drop entries");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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();
}, "Test that increasing the buffer during the callback is enough for entries not to be dropped");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,56 @@
<!DOCTYPE HTML>
<html>
<head onload>
<meta charset="utf-8" />
<title>This test validates the buffer doesn't contain more entries than it should inside onresourcetimingbufferfull callback.</title>
<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/buffer-full-utilities.js"></script>
</head>
<body>
<script>
let resource_timing_buffer_size = 2;
let eventFired = false;
setup(() => {
clearBufferAndSetSize(resource_timing_buffer_size);
var resize = function() {
assert_equals(performance.getEntriesByType("resource").length, resource_timing_buffer_size, "resource timing buffer in resourcetimingbufferfull is the size of the limit");
++resource_timing_buffer_size;
performance.setResourceTimingBufferSize(resource_timing_buffer_size);
xhrScript("resources/empty.js?xhr");
assert_equals(performance.getEntriesByType("resource").length, resource_timing_buffer_size - 1, "A sync request was not added to the primary buffer just yet, because it is full");
++resource_timing_buffer_size;
performance.setResourceTimingBufferSize(resource_timing_buffer_size);
eventFired = true;
}
performance.addEventListener('resourcetimingbufferfull', resize);
});
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, resource_timing_buffer_size,
'All 4 entries should be stored in resource timing buffer.');
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");
assert_true(entries[2].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
assert_true(entries[3].name.includes('empty.js?xhr'), "empty.js?xhr is in the entries buffer");
};
promise_test(async () => {
await fillUpTheBufferWithTwoResources('resources/empty.js');
await overflowTheBuffer();
await waitForEventToFire();
testThatBufferContainsTheRightResources();
}, "Test that entries in the secondary buffer are not exposed during the callback and before they are copied to the primary buffer");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,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>

Просмотреть файл

@ -0,0 +1,55 @@
<!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/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;
let global_buffer = [];
let eventFired = false;
setup(() => {
clearBufferAndSetSize(resource_timing_buffer_size);
let store_and_clear = function() {
const entryList = performance.getEntriesByType('resource');
entryList.forEach(function (entry) {
global_buffer.push(entry);
});
performance.clearResourceTimings();
eventFired = true;
}
performance.addEventListener('resourcetimingbufferfull', store_and_clear);
});
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, 1,
"Only the last entry should be stored in resource timing buffer since it's cleared once it overflows.");
assert_equals(global_buffer.length, 1, '1 resource timing entry should be moved to global buffer.');
assert_true(global_buffer[0].name.includes('empty.js'), "empty.js is in the global buffer");
assert_true(entries[0].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();
}, "Test that entries overflowing the buffer trigger the buffer full event, can be stored, and find themselves in the primary buffer after it's cleared.");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<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"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 1;
setup(() => {
clearBufferAndSetSize(resource_timing_buffer_size);
performance.addEventListener('resourcetimingbufferfull', () => { assert_unreached("resourcetimingbufferfull should not fire"); });
});
let overflowTheBuffer = () => {
// These resources overflow the entry buffer, and go into the secondary buffer.
xhrScript('resources/empty.js?xhr2');
xhrScript('resources/empty.js?xhr3');
performance.setResourceTimingBufferSize(3);
};
let testThatBufferContainsTheRightResources = () => {
let entries = performance.getEntriesByType('resource');
assert_equals(entries.length, 3,
'All resources should be in the buffer, since its size was increased');
assert_true(entries[0].name.includes('empty.js'), "empty.js?xhr2 is in the entries buffer");
assert_true(entries[1].name.includes('empty.js?xhr2'), "empty.js?xhr3 is in the entries buffer");
assert_true(entries[2].name.includes('empty.js?xhr3'), "empty.js?xhr3 is in the entries buffer");
};
promise_test(async () => {
await fillUpTheBufferWithSingleResource("resources/empty.js");
overflowTheBuffer();
await waitForNextTask();
testThatBufferContainsTheRightResources();
}, "Test that overflowing the buffer and immediately increasing its limit does not trigger the resourcetimingbufferfull event");
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<link rel="author" title="Intel" href="http://www.intel.com/" />
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<title>This test validates the functionality of onresourcetimingbufferfull in resource timing.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/buffer-full-utilities.js"></script>
</head>
<body>
<script>
const resource_timing_buffer_size = 2;
let bufferFullCount = 0;
let eventFired = false;
setup(() => {
clearBufferAndSetSize(resource_timing_buffer_size);
performance.addEventListener('resourcetimingbufferfull', e => {
assert_equals(e.bubbles, false, "Event bubbles attribute is false");
bufferFullCount++;
eventFired = true;
});
});
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 = () => {
assert_equals(performance.getEntriesByType('resource').length, resource_timing_buffer_size, 'There should only be |bufferSize| resource entries.');
assert_equals(bufferFullCount, 1, 'onresourcetimingbufferfull should have been invoked once.');
};
promise_test(async () => {
await fillUpTheBufferWithTwoResources('resources/empty.js');
await overflowTheBuffer();
await waitForEventToFire();
testThatBufferContainsTheRightResources();
}, "Test that a buffer full event does not bubble and that resourcetimingbufferfull is called only once per overflow");
</script>
</body>
</html>

Просмотреть файл

@ -1,41 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<link rel="author" title="Intel" href="http://www.intel.com/" />
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<title>This test validates the functionality of onresourcetimingbufferfull in resource timing.</title>
<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 bufferSize = 5;
context.setResourceTimingBufferSize(bufferSize);
let bufferFullCount = 0;
function buffer_full_callback() {
bufferFullCount++;
}
context.registerResourceTimingBufferFullCallback(buffer_full_callback);
// 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, bufferSize, 'There should only be |bufferSize| resource entries.');
test_equals(bufferFullCount, 1, 'onresourcetimingbufferfull should have been invoked once buffer is full.');
done();
}
</script>
</body>
</html>

Просмотреть файл

@ -1,56 +0,0 @@
<!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>

Просмотреть файл

@ -0,0 +1,58 @@
let appendScript = (src, resolve) => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.onload = resolve;
document.body.appendChild(script);
}
let xhrScript = src => {
var xhr = new XMLHttpRequest();
xhr.open("GET", src, false);
xhr.send(null);
}
let waitForNextTask = () => {
return new Promise(resolve => {
step_timeout(resolve, 0);
});
};
let waitForEventToFire = () => {
return new Promise(resolve => {
let waitForIt = function() {
if (eventFired) {
eventFired = false;
resolve();
} else {
step_timeout(waitForIt, 0);
}
}
step_timeout(waitForIt, 0);
});
};
let clearBufferAndSetSize = size => {
performance.clearResourceTimings();
performance.setResourceTimingBufferSize(size);
}
let fillUpTheBufferWithSingleResource = src => {
return new Promise(resolve => {
// This resource gets buffered in the resource timing entry buffer.
appendScript(src, resolve);
});
};
let loadResource = src => {
return new Promise(resolve => {
appendScript(src, resolve);
});
};
let fillUpTheBufferWithTwoResources = async src => {
// These resources get buffered in the resource timing entry buffer.
await loadResource(src);
await loadResource(src + '?second');
};

Просмотреть файл

@ -44,19 +44,13 @@ promise_test(function(test) {
assert_greater_than(entry.startTime, 0);
assert_greater_than(entry.responseEnd, entry.startTime);
}
return Promise.race([
new Promise(function(resolve) {
return new Promise(function(resolve) {
performance.onresourcetimingbufferfull = _ => {
resolve('bufferfull');
}
performance.setResourceTimingBufferSize(expectedResources.length);
}),
// Race the bufferfull event against another fetch. We should get the
// event before this completes. This allows us to detect a failure
// to dispatch the event without timing out the entire test.
fetch('dummy.txt').then(resp => resp.text())
]);
fetch('dummy.txt');
});
})
.then(function(result) {
assert_equals(result, 'bufferfull');