tor-browser

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

test_sanitize.html (2660B)


      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 1080109 - Clear ServiceWorker registrations for all domains</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 
     18  function start() {
     19    const Cc = SpecialPowers.Cc;
     20    const Ci = SpecialPowers.Ci;
     21 
     22    function testNotIntercepted() {
     23      testFrame("sanitize/frame.html").then(function(body) {
     24        is(body, "FAIL", "Expected frame to not be controlled");
     25        // No need to unregister since that already happened.
     26        navigator.serviceWorker.getRegistration("sanitize/foo").then(function(reg) {
     27          ok(reg === undefined, "There should no longer be a valid registration");
     28        }, function(e) {
     29          ok(false, "getRegistration() should not error");
     30        }).then(function(e) {
     31          SimpleTest.finish();
     32        });
     33      });
     34    }
     35 
     36    registerSW().then(function() {
     37      return testFrame("sanitize/frame.html").then(function(body) {
     38        is(body, "intercepted", "Expected serviceworker to intercept request");
     39      });
     40    }).then(function() {
     41      return navigator.serviceWorker.getRegistration("sanitize/foo");
     42    }).then(function(reg) {
     43      reg.active.onstatechange = function(e) {
     44        e.target.onstatechange = null;
     45        is(e.target.state, "redundant", "On clearing data, serviceworker should become redundant");
     46        testNotIntercepted();
     47      };
     48    }).then(function() {
     49      SpecialPowers.removeAllServiceWorkerData();
     50    });
     51  }
     52 
     53  function testFrame(src) {
     54    return new Promise(function(resolve, reject) {
     55      var iframe = document.createElement("iframe");
     56      iframe.src = src;
     57      window.onmessage = function(message) {
     58        window.onmessage = null;
     59        iframe.src = "about:blank";
     60        document.body.removeChild(iframe);
     61        iframe = null;
     62        SpecialPowers.exactGC(function() {
     63          resolve(message.data);
     64        });
     65      };
     66      document.body.appendChild(iframe);
     67    });
     68  }
     69 
     70  function registerSW() {
     71    return testFrame("sanitize/register.html");
     72  }
     73 
     74  SimpleTest.waitForExplicitFinish();
     75 
     76  SpecialPowers.pushPrefEnv({"set": [
     77    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     78    ["dom.serviceWorkers.enabled", true],
     79    ["dom.serviceWorkers.testing.enabled", true],
     80  ]}, function() {
     81    start();
     82  });
     83 </script>
     84 </pre>
     85 </body>
     86 </html>