test_bug1741132.html (2805B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test form restoration for no-store pages</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 <script> 9 // The number of entries which we keep in the BFCache (see nsSHistory.h). 10 const VIEWER_WINDOW = 3; 11 12 SimpleTest.waitForExplicitFinish(); 13 14 async function runTest() { 15 let bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1741132"); 16 17 // Setting the pref to 0 should evict all content viewers. 18 let load = SpecialPowers.pushPrefEnv({ 19 set: [["browser.sessionhistory.max_total_viewers", 0]], 20 }).then(() => { 21 // Set the pref to VIEWER_WINDOW + 2 now, to be sure we 22 // could fit all entries. 23 SpecialPowers.pushPrefEnv({ 24 set: [["browser.sessionhistory.max_total_viewers", VIEWER_WINDOW + 2]], 25 }); 26 }).then(() => { 27 return new Promise(resolve => { 28 bc.addEventListener("message", resolve, { once: true }); 29 window.open("file_bug1741132.html", "", "noopener"); 30 }); 31 }); 32 // We want to try to keep one entry too many in the BFCache, 33 // so we ensure that there's at least VIEWER_WINDOW + 2 34 // entries in session history (with one for the displayed 35 // page). 36 for (let i = 0; i < VIEWER_WINDOW + 2; ++i) { 37 load = load.then(() => { 38 return new Promise((resolve) => { 39 bc.addEventListener("message", resolve, { once: true }); 40 bc.postMessage({ cmd: "load", arg: `file_bug1741132.html?${i}` }); 41 }); 42 }); 43 } 44 load.then(() => { 45 return new Promise((resolve) => { 46 bc.addEventListener("message", ({ data: persisted }) => { 47 resolve(persisted); 48 }, { once: true }); 49 // Go back past the first entry that should be in the BFCache. 50 bc.postMessage({ cmd: "go", arg: -(VIEWER_WINDOW + 1) }); 51 }); 52 }).then((persisted) => { 53 ok(!persisted, "Only 3 pages should be kept in the BFCache"); 54 }).then(() => { 55 return new Promise((resolve) => { 56 bc.addEventListener("message", ({ data: persisted }) => { 57 resolve(persisted); 58 }, { once: true }); 59 // Go forward to the first entry that should be in the BFCache. 60 bc.postMessage({ cmd: "go", arg: 1 }); 61 }); 62 }).then((persisted) => { 63 ok(persisted, "3 pages should be kept in the BFCache"); 64 65 bc.postMessage("close"); 66 67 bc.close(); 68 69 SimpleTest.finish(); 70 }); 71 } 72 </script> 73 </head> 74 <body onload="runTest();"> 75 <p id="display"></p> 76 <div id="content" style="display: none"></div> 77 <pre id="test"></pre> 78 </body> 79 </html>