tor-browser

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

test_skip_waiting.html (2467B)


      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 1131352 - Add ServiceWorkerGlobalScope skipWaiting()</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"></div>
     15 <pre id="test"></pre>
     16 <script src="utils.js"></script>
     17 <script class="testbody" type="text/javascript">
     18  var registration, iframe, content;
     19 
     20  function start() {
     21    return navigator.serviceWorker.register("worker.js",
     22                                            {scope: "./skip_waiting_scope/"});
     23  }
     24 
     25  async function waitForActivated(swr) {
     26    registration = swr;
     27    await waitForState(registration.installing, "activated")
     28 
     29    iframe = document.createElement("iframe");
     30    iframe.setAttribute("src", "skip_waiting_scope/index.html");
     31 
     32    content = document.getElementById("content");
     33    content.appendChild(iframe);
     34 
     35    await new Promise(resolve => iframe.onload = resolve);
     36  }
     37 
     38  function checkWhetherItSkippedWaiting() {
     39    var promise = new Promise(function(resolve, reject) {
     40      window.onmessage = function (evt) {
     41        if (evt.data.event === "controllerchange") {
     42          ok(evt.data.controllerScriptURL.match("skip_waiting_installed_worker"),
     43             "The controller changed after skiping the waiting step");
     44          resolve();
     45        } else {
     46          ok(false, "Wrong value. Somenting went wrong");
     47          resolve();
     48        }
     49      };
     50    });
     51 
     52    navigator.serviceWorker.register("skip_waiting_installed_worker.js",
     53                                     {scope: "./skip_waiting_scope/"})
     54      .then(swr => {
     55        registration = swr;
     56    });
     57 
     58    return promise;
     59  }
     60 
     61  function clean() {
     62    content.removeChild(iframe);
     63 
     64    return registration.unregister();
     65  }
     66 
     67  function runTest() {
     68    start()
     69      .then(waitForActivated)
     70      .then(checkWhetherItSkippedWaiting)
     71      .then(clean)
     72      .catch(function(e) {
     73        ok(false, "Some test failed with error " + e);
     74      }).then(SimpleTest.finish);
     75  }
     76 
     77  SimpleTest.waitForExplicitFinish();
     78  SpecialPowers.pushPrefEnv({"set": [
     79    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     80    ["dom.serviceWorkers.enabled", true],
     81    ["dom.serviceWorkers.testing.enabled", true]
     82  ]}, runTest);
     83 </script>
     84 </pre>
     85 </body>
     86 </html>