tor-browser

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

test_file_blob_response.html (2259B)


      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 1253777 - Test interception using file blob response body</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 registration;
     19  var scope = './file_blob_response/';
     20  function start() {
     21    return navigator.serviceWorker.register("file_blob_response_worker.js",
     22                                            { scope })
     23      .then(function(swr) {
     24        registration = swr;
     25        return new waitForState(swr.installing, 'activated');
     26      });
     27  }
     28 
     29  function unregister() {
     30    return registration.unregister().then(function(result) {
     31      ok(result, "Unregister should return true.");
     32    }, function(e) {
     33      ok(false, "Unregistering the SW failed with " + e + "\n");
     34    });
     35  }
     36 
     37  function withFrame(url) {
     38    return new Promise(function(resolve, reject) {
     39      var content = document.getElementById("content");
     40      ok(content, "Parent exists.");
     41 
     42      var frame = document.createElement("iframe");
     43      frame.setAttribute('src', url);
     44      content.appendChild(frame);
     45 
     46      frame.addEventListener('load', function(evt) {
     47        resolve(frame);
     48      }, {once: true});
     49    });
     50  }
     51 
     52  function runTest() {
     53    start()
     54      .then(function() {
     55        return withFrame(scope + 'dummy.txt');
     56      })
     57      .then(function(frame) {
     58        var result = JSON.parse(frame.contentWindow.document.body.textContent);
     59        frame.remove();
     60        is(result.value, 'success');
     61      })
     62      .catch(function(e) {
     63        ok(false, "Some test failed with error " + e);
     64      })
     65      .then(unregister)
     66      .then(SimpleTest.finish);
     67  }
     68 
     69  SimpleTest.waitForExplicitFinish();
     70  SpecialPowers.pushPrefEnv({"set": [
     71    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     72    ["dom.serviceWorkers.enabled", true],
     73    ["dom.serviceWorkers.testing.enabled", true]
     74  ]}, runTest);
     75 </script>
     76 </pre>
     77 </body>
     78 </html>