blob: d46d4692a55b9cbef1aa5f882f38887e1f7940e9 [file] [log] [blame]
Yoav Weiss79001b12018-12-12 17:16:561<!DOCTYPE HTML>
2<html>
3<head onload>
4<meta charset="utf-8" />
5<title>This test validates the buffer doesn't contain more entries than it should inside onresourcetimingbufferfull callback.</title>
6<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
7<script src="/resources/testharness.js"></script>
8<script src="/resources/testharnessreport.js"></script>
9<script src="resources/buffer-full-utilities.js"></script>
10</head>
11<body>
12<script>
13let resource_timing_buffer_size = 2;
14let eventFired = false;
15
16setup(() => {
17 clearBufferAndSetSize(resource_timing_buffer_size);
18 var resize = function() {
19 assert_equals(performance.getEntriesByType("resource").length, resource_timing_buffer_size, "resource timing buffer in resourcetimingbufferfull is the size of the limit");
20 ++resource_timing_buffer_size;
21 performance.setResourceTimingBufferSize(resource_timing_buffer_size);
22 xhrScript("resources/empty.js?xhr");
23 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");
24 ++resource_timing_buffer_size;
25 performance.setResourceTimingBufferSize(resource_timing_buffer_size);
26 eventFired = true;
27 }
28 performance.addEventListener('resourcetimingbufferfull', resize);
29});
30
31let overflowTheBuffer = () => {
32 return new Promise(resolve => {
33 // This resource overflows the entry buffer, and goes into the secondary buffer.
34 appendScript('resources/empty_script.js', resolve);
35 });
36};
37
38let testThatBufferContainsTheRightResources = () => {
39 let entries = performance.getEntriesByType('resource');
40 assert_equals(entries.length, resource_timing_buffer_size,
41 'All 4 entries should be stored in resource timing buffer.');
42 assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
43 assert_true(entries[1].name.includes('empty.js?second'), "empty.js?second is in the entries buffer");
44 assert_true(entries[2].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
45 assert_true(entries[3].name.includes('empty.js?xhr'), "empty.js?xhr is in the entries buffer");
46};
47
48promise_test(async () => {
49 await fillUpTheBufferWithTwoResources('resources/empty.js');
50 await overflowTheBuffer();
51 await waitForEventToFire();
52 testThatBufferContainsTheRightResources();
53}, "Test that entries in the secondary buffer are not exposed during the callback and before they are copied to the primary buffer");
54</script>
55</body>
56</html>