test_evict_from_bfcache.html (2147B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Evict a page from bfcache</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 <script> 9 /* 10 * This test checks that a page can be evicted from bfcache. Sending a 11 * message to an open BroadcastChannel is used for this. 12 * 13 * First the test opens a window and loads a page there. Another page is then 14 * loaded and then session history is navigated back to check if bfcache is 15 * enabled. If not, close message is sent to close the opened window and this 16 * controller page will finish the test. 17 * If bfcache is enabled, session history goes forward, but the 18 * BroadcastChannel in the page isn't closed. Then sending the message to go 19 * back again should evict the bfcached page. 20 * Close message is sent and window closed and test finishes. 21 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 var bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("evict_from_bfcache"); 25 var pageshowCount = 0; 26 bc.onmessage = function(event) { 27 if (event.data.type == "pageshow") { 28 ++pageshowCount; 29 info("pageshow " + pageshowCount); 30 if (pageshowCount == 1) { 31 bc.postMessage("nextpage"); 32 } else if (pageshowCount == 2) { 33 bc.postMessage("back"); 34 } else if (pageshowCount == 3) { 35 if (!event.data.persisted) { 36 ok(true, "BFCache isn't enabled."); 37 bc.postMessage("close"); 38 } else { 39 bc.postMessage("forward"); 40 } 41 } else if (pageshowCount == 4) { 42 bc.postMessage("back"); 43 } else if (pageshowCount == 5) { 44 ok(!event.data.persisted, 45 "The page should have been evicted from BFCache"); 46 bc.postMessage("close"); 47 } 48 } else if (event.data == "closed") { 49 SimpleTest.finish(); 50 } 51 } 52 53 function runTest() { 54 window.open("file_evict_from_bfcache.html", "", "noopener"); 55 } 56 </script> 57 </head> 58 <body onload="runTest()"> 59 <p id="display"></p> 60 <div id="content" style="display: none"></div> 61 <pre id="test"></pre> 62 </body> 63 </html>