|
| 1 | +<!-- webkit-test-runner [ UsesBackForwardCache=true ] --> |
| 2 | +<!DOCTYPE html> |
| 3 | +<html> |
| 4 | +<body> |
| 5 | +<a id="link" href="resources/go-back-after-delay.html" style="display:block; width:100px; height:100px;">Navigate</a> |
| 6 | +<script src="../../resources/js-test.js"></script> |
| 7 | +<script src="../../resources/ui-helper.js"></script> |
| 8 | +<script> |
| 9 | +description("Tests that event timing entries do not have inflated durations after back-forward cache restore."); |
| 10 | +window.jsTestIsAsync = true; |
| 11 | + |
| 12 | +const collectedEntries = []; |
| 13 | +const observer = new PerformanceObserver(list => { |
| 14 | + for (const entry of list.getEntries()) { |
| 15 | + collectedEntries.push({ |
| 16 | + name: entry.name, |
| 17 | + duration: entry.duration, |
| 18 | + }); |
| 19 | + } |
| 20 | +}); |
| 21 | +observer.observe({ type: 'event', durationThreshold: 16 }); |
| 22 | + |
| 23 | +const link = document.getElementById('link'); |
| 24 | +link.addEventListener('click', () => { |
| 25 | + const target = performance.now() + 20; |
| 26 | + while (performance.now() < target); |
| 27 | +}, { once: true }); |
| 28 | + |
| 29 | +window.addEventListener("pageshow", function(event) { |
| 30 | + if (!event.persisted) |
| 31 | + return; |
| 32 | + |
| 33 | + // Wait for any remaining entries to be dispatched after restoration. |
| 34 | + requestAnimationFrame(async () => { |
| 35 | + await new Promise(r => setTimeout(r, 0)); |
| 36 | + await new Promise(r => requestAnimationFrame(r)); |
| 37 | + await new Promise(r => setTimeout(r, 0)); |
| 38 | + |
| 39 | + let hasClickEntry = false; |
| 40 | + let hasInflatedDuration = false; |
| 41 | + for (const entry of collectedEntries) { |
| 42 | + if (entry.name === 'click') |
| 43 | + hasClickEntry = true; |
| 44 | + if (entry.duration >= 1500) { |
| 45 | + testFailed("'" + entry.name + "' entry has inflated duration: " + entry.duration + "ms"); |
| 46 | + hasInflatedDuration = true; |
| 47 | + } |
| 48 | + } |
| 49 | + if (!hasClickEntry) |
| 50 | + testFailed("No 'click' event timing entry collected"); |
| 51 | + else if (!hasInflatedDuration) |
| 52 | + testPassed("Event timing entries have reasonable durations after back-forward restore"); |
| 53 | + finishJSTest(); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +window.addEventListener("pagehide", function(event) { |
| 58 | + if (!event.persisted) { |
| 59 | + testFailed("Page did not enter the page cache"); |
| 60 | + finishJSTest(); |
| 61 | + } |
| 62 | +}); |
| 63 | + |
| 64 | +window.addEventListener('load', async function() { |
| 65 | + // Click the link to generate event timing entries and navigate via |
| 66 | + // the link's default action. The navigation happens as part of click |
| 67 | + // event dispatch, so no rendering update can drain entries beforehand. |
| 68 | + await UIHelper.activateElement(link); |
| 69 | +}); |
| 70 | +</script> |
| 71 | +</body> |
| 72 | +</html> |
0 commit comments