tor-browser

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

test_claim_oninstall.html (2326B)


      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 1130684 - Test service worker clients.claim oninstall</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 class="testbody" type="text/javascript">
     17  var registration;
     18 
     19  function register() {
     20    return navigator.serviceWorker.register("claim_oninstall_worker.js",
     21                                            { scope: "./" })
     22      .then((swr) => registration = swr);
     23  }
     24 
     25 
     26  function unregister() {
     27    return registration.unregister().then(function(result) {
     28      ok(result, "Unregister should return true.");
     29    });
     30  }
     31 
     32  function testClaim() {
     33    ok(registration.installing, "Worker should be in installing state");
     34 
     35    navigator.serviceWorker.oncontrollerchange = function() {
     36      ok(false, "Claim should not succeed when the worker is not active.");
     37    }
     38 
     39    var p = new Promise(function(res, rej) {
     40      var worker = registration.installing;
     41      worker.onstatechange = function(e) {
     42        if (worker.state === 'installed') {
     43          is(worker, registration.waiting, "Worker should be in waiting state");
     44        } else if (worker.state === 'activated') {
     45          // The worker will become active only if claim will reject inside the
     46          // install handler.
     47          is(worker, registration.active,
     48             "Claim should reject if the worker is not active");
     49          ok(navigator.serviceWorker.controller === null, "Client is not controlled.");
     50          e.target.onstatechange = null;
     51          res();
     52        }
     53      }
     54    });
     55 
     56    return p;
     57  }
     58 
     59  function runTest() {
     60    register()
     61      .then(testClaim)
     62      .then(unregister)
     63      .catch(function(e) {
     64        ok(false, "Some test failed with error " + e);
     65      }).then(SimpleTest.finish);
     66  }
     67 
     68  SimpleTest.waitForExplicitFinish();
     69  SpecialPowers.pushPrefEnv({"set": [
     70    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     71    ["dom.serviceWorkers.enabled", true],
     72    ["dom.serviceWorkers.testing.enabled", true]
     73  ]}, runTest);
     74 </script>
     75 </pre>
     76 </body>
     77 </html>