back-forward-cache-restoration.tentative.html (3993B)
1 <!doctype html> 2 <html> 3 4 <head> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/utils.js"></script> 8 <script src="/common/dispatcher/dispatcher.js"></script> 9 <script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> 10 </head> 11 12 <body> 13 <script> 14 const BackForwardCacheRestorationName = ''; 15 const BackForwardCacheRestorationType = 'back-forward-cache-restoration'; 16 17 let getNavigationId = (i) => { 18 let identifier = 'mark' + i; 19 performance.mark(identifier); 20 return window.performance.getEntriesByName(identifier)[0].navigationId; 21 } 22 23 let getNumberofBackForwardCacheRestorationEntries = (BackForwardCacheRestorationType) => { 24 return window.performance.getEntriesByType(BackForwardCacheRestorationType).length; 25 } 26 27 let getBackForwardCacheRestorationByType = (BackForwardCacheRestorationType) => { 28 let entries = window.performance.getEntriesByType(BackForwardCacheRestorationType); 29 return entries[entries.length - 1]; 30 } 31 32 let getBackForwardCacheRestorationByGetAllAndFilter = (BackForwardCacheRestorationType) => { 33 let entries = window.performance.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType); 34 return entries[entries.length - 1]; 35 } 36 37 let getBackForwardCacheRestorationByPerformanceObserverBuffered = async (BackForwardCacheRestorationType) => { 38 let p = new Promise(resolve => { 39 new PerformanceObserver((list) => { 40 const entries = list.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType); 41 if (entries.length > 0) { 42 resolve(entries[entries.length - 1]); 43 } 44 }).observe({ type: BackForwardCacheRestorationType, buffered: true }); 45 }); 46 return await p; 47 } 48 49 let checkEntry = (entry, previousNavigationId) => { 50 assert_equals(entry.name, BackForwardCacheRestorationName); 51 assert_equals(entry.entryType, BackForwardCacheRestorationType); 52 assert_not_equals(entry.navigationId, previousNavigationId); 53 assert_true(entry.pageshowEventStart > entry.startTime); 54 assert_true(entry.pageshowEventEnd >= entry.pageshowEventStart); 55 } 56 57 promise_test(async t => { 58 const pageA = new RemoteContext(token()); 59 const pageB = new RemoteContext(token()); 60 61 const urlA = executorPath + pageA.context_id; 62 const urlB = originCrossSite + executorPath + pageB.context_id; 63 // Open url A. 64 window.open(urlA, '_blank', 'noopener'); 65 await pageA.execute_script(waitForPageShow); 66 67 // Assert no instance of BackForwardCacheRestoration exists without back forward cache navigatoin. 68 let size = await pageA.execute_script(getNumberofBackForwardCacheRestorationEntries); 69 assert_equals(0, size); 70 71 let entry; 72 for (i = 0; i < 2; i++) { 73 let curr_nav_id = await pageA.execute_script(getNavigationId, [i]); 74 75 // Navigate away to url B and back. 76 await navigateAndThenBack(pageA, pageB, urlB); 77 78 // Assert Performance Observer API supports BackForwardCacheRestoration. 79 entry = await pageA.execute_script(getBackForwardCacheRestorationByPerformanceObserverBuffered, [BackForwardCacheRestorationType]); 80 // The navigation id after a bfcache restoration should be different 81 // from that before. 82 checkEntry(entry, curr_nav_id); 83 84 // Assert Performance Timeline API supports BackForwardCacheRestoration. 85 entry = await pageA.execute_script(getBackForwardCacheRestorationByType, [BackForwardCacheRestorationType]); 86 checkEntry(entry, curr_nav_id); 87 88 entry = await pageA.execute_script(getBackForwardCacheRestorationByGetAllAndFilter, [BackForwardCacheRestorationType]); 89 checkEntry(entry, curr_nav_id); 90 } 91 }, 'Performance API for the back forward cache restoration entry.'); 92 </script> 93 </body> 94 95 </html>