test_strongworker.html (1571B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 5 6 <script> 7 SimpleTest.waitForExplicitFinish(); 8 9 async function run() { 10 // Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5) 11 // Acquire storage access permission here so that the BroadcastChannel used to 12 // communicate with the opened windows works in xorigin tests. Otherwise, 13 // the iframe containing this page is isolated from first-party storage access, 14 // which isolates BroadcastChannel communication. 15 if (isXOrigin) { 16 SpecialPowers.wrap(document).notifyUserGestureActivation(); 17 await SpecialPowers.addPermission( 18 "storageAccessAPI", 19 true, 20 window.location.href 21 ); 22 await SpecialPowers.wrap(document).requestStorageAccess(); 23 } 24 const channel = new BroadcastChannel("strongworker"); 25 await navigator.locks.request("exclusive", async () => { 26 await new Promise(resolve => { 27 let worker = new Worker("./file_strongworker.js"); 28 worker.onmessage = resolve; // onload 29 }); 30 const query = await navigator.locks.query(); 31 is(query.pending.length, 1, "Pending request exists"); 32 33 // Garbage collect the worker 34 SpecialPowers.DOMWindowUtils.garbageCollect(); 35 }); 36 37 channel.onmessage = async () => { 38 const query = await navigator.locks.query(); 39 is(query.pending.length, 0, "No pending request"); 40 SimpleTest.finish(); 41 }; 42 } 43 run(); 44 </script>