no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / docshell / test / mochitest / test_form_restoration.html
blobb9292367701ef707556b275e03b1b99a8e463f52
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 });
17 function postMessageAndWait(aBroadcastChannel, aMsg) {
18 let promise = waitForMessage(aBroadcastChannel);
19 aBroadcastChannel.postMessage(aMsg);
20 return promise;
23 async function startTest(aTestFun) {
24 let bc = new BroadcastChannel("form_restoration");
26 let promise = waitForMessage(bc);
27 window.open("file_form_restoration_no_store.html", "", "noopener");
28 await promise;
30 // test steps
31 await aTestFun(bc);
33 // close broadcast channel and window
34 bc.postMessage("close");
35 bc.close();
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");
44 // navigate
45 await postMessageAndWait(aBroadcastChannel, "navigate");
47 // history back
48 let { persisted, formData } = await postMessageAndWait(aBroadcastChannel, "back");
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 });
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");
62 // reload
63 let { persisted, formData } = await postMessageAndWait(aBroadcastChannel, "reload");
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>