tor-browser

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

test_match_all.html (2348B)


      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 982726 - test match_all not crashing</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  // match_all_worker will call matchAll until the worker shuts down.
     19  // Test passes if the browser doesn't crash on leaked promise objects.
     20  var registration;
     21  var content;
     22  var iframe;
     23 
     24  function simpleRegister() {
     25    return navigator.serviceWorker.register("match_all_worker.js",
     26                                            { scope: "./sw_clients/" })
     27      .then((swr) => {
     28        registration = swr;
     29        return waitForState(swr.installing, 'activated', swr);
     30      });
     31  }
     32 
     33  function closeAndUnregister() {
     34    content.removeChild(iframe);
     35 
     36    return registration.unregister().then(function(result) {
     37      ok(result, "Unregister should return true.");
     38    }, function(e) {
     39      dump("Unregistering the SW failed with " + e + "\n");
     40    });
     41  }
     42 
     43  function openClient() {
     44    var p = new Promise(function(resolve, reject) {
     45      window.onmessage = function(e) {
     46        if (e.data === "READY") {
     47          resolve();
     48        }
     49      }
     50    });
     51 
     52    content = document.getElementById("content");
     53    ok(content, "Parent exists.");
     54 
     55    iframe = document.createElement("iframe");
     56    iframe.setAttribute('src', "sw_clients/simple.html");
     57    content.appendChild(iframe);
     58 
     59    return p;
     60  }
     61 
     62  function runTest() {
     63    simpleRegister()
     64      .then(openClient)
     65      .then(closeAndUnregister)
     66      .catch(function(e) {
     67        ok(false, "Some test failed with error " + e);
     68      }).then(function() {
     69        ok(true, "Didn't crash on resolving matchAll promises while worker shuts down.");
     70        SimpleTest.finish();
     71      });
     72  }
     73 
     74  SimpleTest.waitForExplicitFinish();
     75  SpecialPowers.pushPrefEnv({"set": [
     76    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     77    ["dom.serviceWorkers.enabled", true],
     78    ["dom.serviceWorkers.testing.enabled", true]
     79  ]}, runTest);
     80 </script>
     81 </pre>
     82 </body>
     83 </html>