test_bug1364364.html (2093B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1364364 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1364364</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** Test for Bug 1364364 */ 14 let testWin, testDoc; 15 async function test() { 16 SimpleTest.waitForExplicitFinish(); 17 if (SpecialPowers.Services.appinfo.sessionHistoryInParent) { 18 // This test relies on the possibility to modify the bfcached document. 19 // The new implementation is more restricted and thus works only 20 // when the bfcached browsing context is the only top level one 21 // in the browsing context group. 22 ok(true, "This test is for the old bfcache implementation only."); 23 SimpleTest.finish(); 24 return; 25 } 26 testWin = window.open("file_bug1364364-1.html"); 27 await waitForLoad(testWin); 28 testDoc = testWin.document; 29 30 // file_bug1364364-1.html will load a few dynamic iframes and then navigate 31 // top browsing context to file_bug1364364-2.html, which will postMessage 32 // back. 33 } 34 35 function waitForLoad(win) { 36 return new Promise(r => win.addEventListener("load", r, { once: true})); 37 } 38 39 window.addEventListener("message", async function(msg) { 40 if (msg.data == "navigation-done") { 41 is(testWin.history.length, 6, "check history.length"); 42 43 // Modify a document in bfcache should cause the cache being dropped tho 44 // RemoveFromBFCacheAsync. 45 testDoc.querySelector("#content").textContent = "modified"; 46 await new Promise(r => setTimeout(r, 0)); 47 48 is(testWin.history.length, 2, "check history.length after bfcache dropped"); 49 testWin.close(); 50 SimpleTest.finish(); 51 } 52 }); 53 54 </script> 55 </head> 56 <body onload="test();"> 57 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1364364">Mozilla Bug 1364364</a> 58 <p id="display"></p> 59 <div id="content" style="display: none"> 60 61 </div> 62 <pre id="test"> 63 </pre> 64 </body> 65 </html>