test_form_restoration.html (2426B)
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 function waitForMessage(aBroadcastChannel) { 10 return new Promise(resolve => { 11 aBroadcastChannel.addEventListener("message", ({ data }) => { 12 resolve(data); 13 }, { once: true }); 14 }); 15 } 16 17 function postMessageAndWait(aBroadcastChannel, aMsg) { 18 let promise = waitForMessage(aBroadcastChannel); 19 aBroadcastChannel.postMessage(aMsg); 20 return promise; 21 } 22 23 async function startTest(aTestFun) { 24 let bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("form_restoration"); 25 26 let promise = waitForMessage(bc); 27 window.open("file_form_restoration_no_store.html", "", "noopener"); 28 await promise; 29 30 // test steps 31 await aTestFun(bc); 32 33 // close broadcast channel and window 34 bc.postMessage("close"); 35 bc.close(); 36 } 37 38 /* Test for bug1740517 */ 39 add_task(async function history_back() { 40 await startTest(async (aBroadcastChannel) => { 41 // update form data 42 aBroadcastChannel.postMessage("enter_data"); 43 44 // navigate 45 await postMessageAndWait(aBroadcastChannel, "navigate"); 46 47 // history back 48 let { persisted, formData } = await postMessageAndWait(aBroadcastChannel, "back"); 49 50 // check form data 51 ok(!persisted, "Page with a no-store header shouldn't be bfcached."); 52 is(formData, "initial", "We shouldn't restore form data when going back to a page with a no-store header."); 53 }); 54 }); 55 56 /* Test for bug1752250 */ 57 add_task(async function location_reload() { 58 await startTest(async (aBroadcastChannel) => { 59 // update form data 60 aBroadcastChannel.postMessage("enter_data"); 61 62 // reload 63 let { persisted, formData } = await postMessageAndWait(aBroadcastChannel, "reload"); 64 65 // check form data 66 ok(!persisted, "Page with a no-store header shouldn't be bfcached."); 67 is(formData, "initial", "We shouldn't restore form data when reload a page with a no-store header."); 68 }); 69 }); 70 </script> 71 </head> 72 <body> 73 <p id="display"></p> 74 <div id="content" style="display: none"></div> 75 <pre id="test"></pre> 76 </body> 77 </html>