file_bug1609475.html (1818B)
1 <html> 2 <head> 3 <script> 4 5 var loadCount = 0; 6 function loadListener() { 7 ++loadCount; 8 if (loadCount == 2) { 9 // Use a timer to ensure we don't get extra load events. 10 setTimeout(function() { 11 var doc1URI = document.getElementById("i1").contentDocument.documentURI; 12 opener.ok(doc1URI.includes("frame1.html"), 13 "Should have loaded the initial page to the first iframe. Got " + doc1URI); 14 var doc2URI = document.getElementById("i2").contentDocument.documentURI; 15 opener.ok(doc2URI.includes("frame1.html"), 16 "Should have loaded the initial page to the second iframe. Got " + doc2URI); 17 opener.finishTest(); 18 }, 1000); 19 } else if (loadCount > 2) { 20 opener.ok(false, "Too many load events"); 21 } 22 // if we don't get enough load events, the test will time out. 23 } 24 25 function setupIframe(id) { 26 var ifr = document.getElementById(id); 27 return new Promise(function(resolve) { 28 ifr.onload = function() { 29 // Replace load listener to catch page loads from the session history. 30 ifr.onload = loadListener; 31 // Need to use setTimeout, because triggering loads inside 32 // load event listener has special behavior since at the moment 33 // the docshell keeps track of whether it is executing a load handler or not. 34 setTimeout(resolve); 35 } 36 ifr.contentWindow.location.href = "frame2.html"; 37 }); 38 } 39 40 async function test() { 41 await setupIframe("i1"); 42 await setupIframe("i2"); 43 history.go(-2); 44 } 45 </script> 46 </head> 47 <body onload="setTimeout(test)"> 48 <iframe id="i1" src="frame1.html"></iframe> 49 <iframe id="i2" src="frame1.html"></iframe> 50 </body> 51 </html>