tor-browser

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

test_workerupdatefoundevent.html (2560B)


      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 1131327 - Test ServiceWorkerRegistration.onupdatefound on ServiceWorker</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"></div>
     15 <pre id="test"></pre>
     16 <script src="utils.js"></script>
     17 <script class="testbody" type="text/javascript">
     18  var registration;
     19  var promise;
     20 
     21  async function start() {
     22    registration = await navigator.serviceWorker.register("worker_updatefoundevent.js",
     23                                                          { scope: "./updatefoundevent.html" })
     24    await waitForState(registration.installing, 'activated');
     25 
     26    content = document.getElementById("content");
     27    iframe = document.createElement("iframe");
     28    content.appendChild(iframe);
     29    iframe.setAttribute("src", "./updatefoundevent.html");
     30 
     31    await new Promise(function(resolve) { iframe.onload = resolve; });
     32    ok(iframe.contentWindow.navigator.serviceWorker.controller, "Controlled client.");
     33 
     34    return Promise.resolve();
     35 
     36  }
     37 
     38  function startWaitForUpdateFound() {
     39    registration.onupdatefound = function(e) {
     40    }
     41 
     42    promise = new Promise(function(resolve, reject) {
     43      window.onmessage = function(e) {
     44 
     45        if (e.data == "finish") {
     46          ok(true, "Received updatefound");
     47          resolve();
     48        }
     49      }
     50    });
     51 
     52    return Promise.resolve();
     53  }
     54 
     55  function registerNext() {
     56    return navigator.serviceWorker.register("worker_updatefoundevent2.js",
     57                                            { scope: "./updatefoundevent.html" });
     58  }
     59 
     60  function waitForUpdateFound() {
     61    return promise;
     62  }
     63 
     64  function unregister() {
     65    window.onmessage = null;
     66    return registration.unregister().then(function(result) {
     67      ok(result, "Unregister should return true.");
     68    });
     69  }
     70 
     71  function runTest() {
     72     start()
     73      .then(startWaitForUpdateFound)
     74      .then(registerNext)
     75      .then(waitForUpdateFound)
     76      .then(unregister)
     77      .catch(function(e) {
     78        ok(false, "Some test failed with error " + e);
     79      }).then(SimpleTest.finish);
     80  }
     81 
     82  SimpleTest.waitForExplicitFinish();
     83  SpecialPowers.pushPrefEnv({"set": [
     84    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     85    ["dom.serviceWorkers.enabled", true],
     86    ["dom.serviceWorkers.testing.enabled", true],
     87  ]}, runTest);
     88 </script>
     89 </pre>
     90 </body>
     91 </html>