test_sessionstorage_across_coop.html (1851B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1790666 5 --> 6 <head> 7 <title>Test for Bug 1790666</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1790666">Mozilla Bug 1790666</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 async function singleTest(testValue, description) { 20 info(`Starting test: ${description}`); 21 22 let bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("testChannel"); 23 let promise = new Promise(resolve => { 24 bc.addEventListener("message", event => { 25 info(`received message from testChannel: ${event.data}`); 26 resolve(event.data); 27 }, { once: true }); 28 }); 29 30 info("Opening pop-up"); 31 let popup = window.open("", "_blank"); 32 popup.sessionStorage.setItem("testItem", testValue); 33 34 info("Navigating pop-up to COOP page"); 35 popup.location = new URL("file_sessionstorage_across_coop.html", window.location); 36 37 let newValue = await promise; 38 is(newValue, testValue, "Value matches expected value"); 39 } 40 41 add_task(async function() { 42 // Cross-Origin-Opener-Policy is only supported in secure contexts, so 43 // make the test a secure context. 44 await SpecialPowers.pushPrefEnv({ 45 "set": [["dom.securecontext.allowlist", "mochi.test"]], 46 }); 47 48 await singleTest("short test value", "short test value"); 49 50 let longValue = "A".repeat(SpecialPowers.getIntPref("browser.sessionstore.dom_storage_limit") * 2); 51 await singleTest(longValue, "long test value"); 52 }); 53 </script> 54 </pre> 55 </body> 56 </html>