| 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 | }); |
| 19 | |
| 20 | let overflowTheBufferAndWaitForEvent = () => { |
| 21 | return new Promise(resolve => { |
| 22 | var add_entry = () => { |
| 23 | performance.setResourceTimingBufferSize(resource_timing_buffer_size + 2); |
| 24 | xhrScript("resources/empty.js?xhr"); |
| 25 | resolve(); |
| 26 | } |
| 27 | performance.addEventListener('resourcetimingbufferfull', add_entry); |
| 28 | // This resource overflows the entry buffer, and goes into the secondary buffer. |
| 29 | appendScript('resources/empty_script.js'); |
| 30 | }); |
| 31 | }; |
| 32 | |
| 33 | let testThatBufferContainsTheRightResources = () => { |
| 34 | let entries = performance.getEntriesByType('resource'); |
| 35 | assert_equals(entries.length, 3, |
| 36 | 'All entries should be stored in resource timing buffer since its increases size once it overflows.'); |
| 37 | assert_true(entries[0].name.includes('empty.js'), "empty.js is in the entries buffer"); |
| 38 | assert_true(entries[1].name.includes('empty_script.js'), "empty_script.js is in the entries buffer"); |
| 39 | assert_true(entries[2].name.includes('empty.js?xhr'), "empty.js?xhr is in the entries buffer"); |
| 40 | }; |
| 41 | |
| 42 | promise_test(async () => { |
| 43 | await fillUpTheBufferWithSingleResource("resources/empty.js"); |
| 44 | await overflowTheBufferAndWaitForEvent(); |
| 45 | await waitForNextTask(); |
| 46 | testThatBufferContainsTheRightResources(); |
| 47 | }, "Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased"); |
| 48 | </script> |
| 49 | </body> |
| 50 | </html> |