| Yoav Weiss | 79001b1 | 2018-12-12 17:16:56 | [diff] [blame] | 1 | <!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> |
| 13 | const resource_timing_buffer_size = 1; |
| 14 | |
| 15 | setup(() => { |
| 16 | // Get the browser into a consistent state. |
| 17 | clearBufferAndSetSize(resource_timing_buffer_size); |
| 18 | performance.addEventListener('resourcetimingbufferfull', () => { assert_unreached("resourcetimingbufferfull should not fire")}); |
| 19 | }); |
| 20 | |
| 21 | let overflowTheBuffer = () => { |
| 22 | // These resources overflow the entry buffer, and go into the secondary buffer. |
| 23 | xhrScript('resources/empty.js?xhr2'); |
| 24 | xhrScript('resources/empty.js?xhr3'); |
| 25 | performance.clearResourceTimings(); |
| 26 | performance.setResourceTimingBufferSize(3); |
| 27 | xhrScript('resources/empty.js?xhr4'); |
| 28 | window.entriesAfterAddition = performance.getEntriesByType('resource'); |
| 29 | }; |
| 30 | |
| 31 | let testThatBufferContainsTheRightResources = () => { |
| 32 | let entries = performance.getEntriesByType('resource'); |
| 33 | assert_equals(entries.length, 3, |
| 34 | 'the last 3 resources should be in the buffer, since the first one was cleared'); |
| 35 | assert_true(entries[0].name.includes('empty.js?xhr2'), "empty.js?xhr2 is in the entries buffer"); |
| 36 | assert_true(entries[1].name.includes('empty.js?xhr3'), "empty.js?xhr3 is in the entries buffer"); |
| 37 | assert_true(entries[2].name.includes('empty.js?xhr4'), "empty.js?xhr4 is in the entries buffer"); |
| 38 | assert_equals(entriesAfterAddition.length, 0, "No entries should have been added to the primary buffer before the task to 'fire a buffer full event'."); |
| 39 | }; |
| 40 | |
| 41 | promise_test(async () => { |
| 42 | await fillUpTheBufferWithSingleResource("resources/empty.js"); |
| 43 | overflowTheBuffer(); |
| 44 | await waitForNextTask(); |
| 45 | testThatBufferContainsTheRightResources(); |
| 46 | }, "Test that if the buffer is cleared after entries were added to the secondary buffer, those entries make it into the primary one"); |
| 47 | </script> |
| 48 | </body> |
| 49 | </html> |