tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_serviceworker_not_sharedworker.html (2189B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <head>
      8  <title>Bug 1141274 - test that service workers and shared workers are separate</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 <iframe></iframe>
     16 </div>
     17 <pre id="test"></pre>
     18 <script class="testbody" type="text/javascript">
     19 
     20  var iframe;
     21  const SCOPE = "http://mochi.test:8888/tests/dom/serviceworkers/test/";
     22  function runTest() {
     23    navigator.serviceWorker.ready.then(setupSW);
     24    navigator.serviceWorker.register("serviceworker_not_sharedworker.js",
     25                                     {scope: SCOPE});
     26  }
     27 
     28  var sw, worker;
     29  function setupSW(registration) {
     30    sw = registration.waiting || registration.active;
     31    worker = new SharedWorker("serviceworker_not_sharedworker.js", SCOPE);
     32    worker.port.start();
     33    iframe = document.querySelector("iframe");
     34    iframe.src = "message_receiver.html";
     35    iframe.onload = function() {
     36      window.onmessage = function(e) {
     37        is(e.data.result, "serviceworker", "We should be talking to a service worker");
     38        window.onmessage = null;
     39        worker.port.onmessage = function(msg) {
     40          is(msg.data.result, "sharedworker", "We should be talking to a shared worker");
     41          registration.unregister().then(function(success) {
     42            ok(success, "unregister should succeed");
     43            SimpleTest.finish();
     44          }, function(ex) {
     45            dump("Unregistering the SW failed with " + ex + "\n");
     46            SimpleTest.finish();
     47          });
     48        };
     49        worker.port.postMessage({msg: "whoareyou"});
     50      };
     51      sw.postMessage({msg: "whoareyou"});
     52    };
     53  }
     54 
     55  SimpleTest.waitForExplicitFinish();
     56  onload = function() {
     57    SpecialPowers.pushPrefEnv({"set": [
     58      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     59      ["dom.serviceWorkers.enabled", true],
     60      ["dom.serviceWorkers.testing.enabled", true]
     61    ]}, runTest);
     62  };
     63 </script>
     64 </pre>
     65 </body>
     66 </html>