entries-after-bfcache.html (2392B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/common/utils.js"></script> 5 <script src="/common/dispatcher/dispatcher.js"></script> 6 <script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> 7 <script src="resources/is_uuid.js"></script> 8 9 <script> 10 // This test ensures that navigation.entries() is properly updated when a page 11 // is restored from bfcache. Before navigating away and back, entries() contains 12 // a single entry representing this document. When restored from bfcache, 13 // entries() should now have two entries: [0] should still be this document, but 14 // [1] should represent the document that we navigated to and back from 15 // (assuming that document is same-origin to this one). 16 runBfcacheTest({ 17 targetOrigin: originSameOrigin, 18 funcBeforeNavigation: () => { 19 window.originalEntry0 = navigation.entries()[0]; 20 }, 21 async funcAfterAssertion(pageA, pageB) { 22 const entryData = await pageA.execute_script(() => { 23 return navigation.entries().map(e => ({ 24 url: e.url, 25 key: e.key, 26 id: e.id, 27 index: e.index, 28 sameDocument: e.sameDocument 29 })); 30 }); 31 32 assert_equals(entryData.length, 2); 33 34 // Ensure that [1] has the proper url, and otherwise is initialized as 35 // a cross-document NavigationHistoryEntry ought to be. 36 assert_equals(entryData[0].url, pageA.url); 37 assert_equals(entryData[1].url, pageB.url); 38 39 assert_true(isUUID(entryData[0].key)); 40 assert_true(isUUID(entryData[1].key)); 41 assert_not_equals(entryData[0].key, entryData[1].key); 42 43 assert_true(isUUID(entryData[0].id)); 44 assert_true(isUUID(entryData[1].id)); 45 assert_not_equals(entryData[0].id, entryData[1].id); 46 47 assert_equals(entryData[0].index, 0); 48 assert_equals(entryData[1].index, 1); 49 50 assert_true(entryData[0].sameDocument); 51 assert_false(entryData[1].sameDocument); 52 53 const currentIsZero = await pageA.execute_script(() => navigation.currentEntry === navigation.entries()[0]); 54 assert_true(currentIsZero); 55 56 const zeroIsSameAsOriginal = await pageA.execute_script(() => navigation.currentEntry === window.originalEntry0); 57 assert_true(zeroIsSameAsOriginal); 58 } 59 }, "entries() must contain the forward-history page after navigating back to a bfcached page"); 60 </script>