traverseTo-navigates-multiple-iframes.html (2305B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <body> 5 <iframe id="i1" src="/common/blank.html"></iframe> 6 <iframe id="i2" src="resources/slow-no-store.py"></iframe> 7 <script> 8 promise_test(async t => { 9 let start_length = navigation.entries().length; 10 // Wait for after the load event so that the navigation doesn't get converted 11 // into a replace navigation. 12 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 13 14 i1.src = "/common/blank.html?navigated"; 15 await new Promise(resolve => i1.onload = resolve); 16 i2.src = "/common/blank.html?navigated"; 17 await new Promise(resolve => i2.onload = resolve); 18 assert_equals(navigation.entries().length, start_length); 19 assert_equals(i1.contentWindow.navigation.entries().length, 2); 20 assert_equals(i2.contentWindow.navigation.entries().length, 2); 21 assert_equals(i1.contentWindow.navigation.currentEntry.index, 1); 22 assert_equals(i2.contentWindow.navigation.currentEntry.index, 1); 23 24 function collectKeysAndIds(win) { 25 return win.navigation.entries().map(e => [e.key, e.id]).flat(); 26 } 27 let i1_keys_and_ids_before_back = collectKeysAndIds(i1.contentWindow); 28 let i2_keys_and_ids_before_back = collectKeysAndIds(i2.contentWindow); 29 30 // Go back to a point that requires both frames to navigate. Because i2 is 31 // going back to a slow, un-cached document, i1 will likely complete before 32 // the server sends the response for i2. This combination of a slow and fast 33 // traversal is less common than the case where multiple iframes navigate at 34 // similar speeds, and caused a bug in chromium. 35 i1.contentWindow.navigation.traverseTo(i1.contentWindow.navigation.entries()[0].key); 36 await Promise.all( 37 [ new Promise(resolve => i1.onload = resolve), 38 new Promise(resolve => i2.onload = resolve) ]); 39 assert_equals(i1.contentWindow.navigation.currentEntry.index, 0); 40 assert_equals(i2.contentWindow.navigation.currentEntry.index, 0); 41 42 assert_array_equals(i1_keys_and_ids_before_back, collectKeysAndIds(i1.contentWindow)); 43 assert_array_equals(i2_keys_and_ids_before_back, collectKeysAndIds(i2.contentWindow)); 44 }, "entries() should be correct after a traversal that navigates multiple browsing contexts"); 45 </script> 46 </body>