blob: d61d2af05c6730c57703e7ba9482067689e78fbb [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 synchronously adding entries in onresourcetimingbufferfull callback results in these entries being properly handled.</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 = 1;
14
15setup(() => {
16 // Get the browser into a consistent state.
17 clearBufferAndSetSize(resource_timing_buffer_size);
18});
19
20let overflowTheBufferAndWaitForEvent = () => {
21 return new Promise(resolve => {
22 var add_entry = () => {
23 performance.setResourceTimingBufferSize(resource_timing_buffer_size + 1);
24 // The sync entry is added to the secondary buffer, so will be the last one there and eventually dropped.
25 xhrScript("resources/empty.js?xhr");
26 resolve();
27 }
28 performance.addEventListener('resourcetimingbufferfull', add_entry);
29 // This resource overflows the entry buffer, and goes into the secondary buffer.
30 appendScript('resources/empty_script.js');
31 });
32};
33
34let testThatBufferContainsTheRightResources = () => {
35 let entries = performance.getEntriesByType('resource');
36 assert_equals(entries.length, 2,
37 'Both entries should be stored in resource timing buffer since its increases size once it overflows.');
38 assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer");
39 assert_true(entries[1].name.includes('empty_script.js'), "empty_script.js is in the entries buffer");
40};
41
42promise_test(async () => {
43 await fillUpTheBufferWithSingleResource("resources/empty.js");
44 await overflowTheBufferAndWaitForEvent();
45 // TODO(yoav): Figure out why this task is needed
46 await waitForNextTask();
47 testThatBufferContainsTheRightResources();
48}, "Test that entries synchronously added to the buffer during the callback are dropped");
49</script>
50</body>
51</html>