tor-browser

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

test_workerUpdate.html (1787B)


      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 1065366 - Test ServiceWorkerGlobalScope.update</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 <div id="container"></div>
     14 <script src="utils.js"></script>
     15 <script class="testbody" type="text/javascript">
     16 
     17  function simpleRegister() {
     18    return navigator.serviceWorker.register("worker_update.js", { scope: "workerUpdate/" })
     19      .then(swr => waitForState(swr.installing, 'activated', swr));
     20  }
     21 
     22  var registration;
     23  function waitForMessages(sw) {
     24    registration = sw;
     25    var p = new Promise(function(resolve, reject) {
     26      window.onmessage = function(e) {
     27        if (e.data === "FINISH") {
     28          ok(true, "The worker has updated itself");
     29          resolve();
     30        } else if (e.data === "FAIL") {
     31          ok(false, "The worker failed to update itself");
     32          resolve();
     33        }
     34      }
     35    });
     36 
     37    var frame = document.createElement("iframe");
     38    frame.setAttribute("src", "workerUpdate/update.html");
     39    document.body.appendChild(frame);
     40 
     41    return p;
     42  }
     43 
     44  function runTest() {
     45    simpleRegister().then(waitForMessages).catch(function(e) {
     46      ok(false, "Something went wrong.");
     47    }).then(function() {
     48      return registration.unregister();
     49    }).then(function() {
     50      SimpleTest.finish();
     51    });
     52  }
     53 
     54  SimpleTest.waitForExplicitFinish();
     55  SpecialPowers.pushPrefEnv({"set": [
     56    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     57    ["dom.serviceWorkers.enabled", true],
     58    ["dom.serviceWorkers.testing.enabled", true]
     59  ]}, runTest);
     60 </script>
     61 </pre>
     62 </body>
     63 </html>