tor-browser

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

test_match_all_advanced.html (2882B)


      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 matchAll with multiple clients</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 client_iframes = [];
     19  var registration;
     20 
     21  function start() {
     22    return navigator.serviceWorker.register("match_all_advanced_worker.js",
     23                                            { scope: "./sw_clients/" }).then(function(swr) {
     24      registration = swr;
     25      return waitForState(swr.installing, 'activated');
     26    }).then(_ => {
     27      window.onmessage = function (e) {
     28        if (e.data === "READY") {
     29          ok(registration.active, "Worker is active.");
     30          registration.active.postMessage("RUN");
     31        }
     32      }
     33    });
     34  }
     35 
     36  function unregister() {
     37    return registration.unregister().then(function(result) {
     38      ok(result, "Unregister should return true.");
     39    }, function(e) {
     40      dump("Unregistering the SW failed with " + e + "\n");
     41    });
     42  }
     43 
     44 
     45  function testMatchAll() {
     46    var p = new Promise(function(res, rej) {
     47      navigator.serviceWorker.onmessage = function (e) {
     48        ok(e.data === client_iframes.length, "MatchAll returned the correct number of clients.");
     49        res();
     50      }
     51    });
     52 
     53    content = document.getElementById("content");
     54    ok(content, "Parent exists.");
     55 
     56    iframe = document.createElement("iframe");
     57    iframe.setAttribute('src', "sw_clients/service_worker_controlled.html");
     58    content.appendChild(iframe);
     59 
     60    client_iframes.push(iframe);
     61    return p;
     62  }
     63 
     64  function removeAndTest() {
     65    content = document.getElementById("content");
     66    ok(content, "Parent exists.");
     67 
     68    content.removeChild(client_iframes.pop());
     69    content.removeChild(client_iframes.pop());
     70 
     71    return testMatchAll();
     72  }
     73 
     74  function runTest() {
     75    start()
     76      .then(testMatchAll)
     77      .then(testMatchAll)
     78      .then(testMatchAll)
     79      .then(removeAndTest)
     80      .then(function(e) {
     81        content = document.getElementById("content");
     82        while (client_iframes.length) {
     83          content.removeChild(client_iframes.pop());
     84        }
     85      }).then(unregister).catch(function(e) {
     86        ok(false, "Some test failed with error " + e);
     87      }).then(function() {
     88        SimpleTest.finish();
     89      });
     90 
     91  }
     92 
     93  SimpleTest.waitForExplicitFinish();
     94  SpecialPowers.pushPrefEnv({"set": [
     95    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     96    ["dom.serviceWorkers.enabled", true],
     97    ["dom.serviceWorkers.testing.enabled", true]
     98  ]}, runTest);
     99 </script>
    100 </pre>
    101 </body>
    102 </html>