blob: e6de33ded1b73345a763692a1bac9138c8f208de [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 that decreasing the buffer size in onresourcetimingbufferfull callback does not result in extra entries being dropped.</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>
13const resource_timing_buffer_size = 2;
14let eventFired = false;
15setup(() => {
16 // Get the browser into a consistent state.
17 clearBufferAndSetSize(resource_timing_buffer_size);
18 let resize = () => {
19 performance.setResourceTimingBufferSize(resource_timing_buffer_size - 1);
20 eventFired = true;
21 }
22 performance.addEventListener('resourcetimingbufferfull', resize);
23});
24
25let overflowTheBuffer = () => {
26 return new Promise(resolve => {
27 // This resource overflows the entry buffer, and goes into the secondary buffer.
28 // Since the buffer size doesn't increase, it will eventually be dropped.
29 appendScript('resources/empty_script.js', resolve);
30 });
31};
32
33let testThatBufferContainsTheRightResources = () => {
34 let entries = performance.getEntriesByType('resource');
35 assert_equals(entries.length, 2,
36 'Both entries should be stored in resource timing buffer since it decreased its limit only after it overflowed.');
37 assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
38 assert_true(entries[1].name.includes('empty.js?second'), "empty.js?second is in the entries buffer");
39};
40
41promise_test(async () => {
42 await fillUpTheBufferWithTwoResources('resources/empty.js');
43 await overflowTheBuffer();
44 await waitForEventToFire();
45 testThatBufferContainsTheRightResources();
46}, "Test that decreasing the buffer limit during the callback does not drop entries");
47</script>
48</body>
49</html>