tor-browser

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

test_https_synth_fetch_from_cached_sw.html (2541B)


      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 1156847 - test fetch event generating a synthesized response in HTTPS origins from a cached SW</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" tyle="display: none">
     15 <iframe></iframe>
     16 </div>
     17 <pre id="test"></pre>
     18 <script class="testbody" type="text/javascript">
     19 
     20  var iframe;
     21  function runTest() {
     22    iframe = document.querySelector("iframe");
     23    iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/https/register.html";
     24    var ios;
     25    window.onmessage = function(e) {
     26      if (e.data.status == "ok") {
     27        ok(e.data.result, e.data.message);
     28      } else if (e.data.status == "registrationdone") {
     29        ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
     30                           .getService(SpecialPowers.Ci.nsIIOService);
     31        ios.offline = true;
     32 
     33        // In order to load synth.html from a cached service worker, we first
     34        // remove the existing window that is keeping the service worker alive,
     35        // and do a GC to ensure that the SW is destroyed.  This way, when we
     36        // load synth.html for the second time, we will first recreate the
     37        // service worker from the cache.  This is intended to test that we
     38        // properly store and retrieve the security info from the cache.
     39        iframe.remove();
     40        iframe = null;
     41        SpecialPowers.exactGC(function() {
     42          iframe = document.createElement("iframe");
     43          iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/https/synth.html";
     44          document.body.appendChild(iframe);
     45        });
     46      } else if (e.data.status == "done-synth") {
     47        ios.offline = false;
     48        iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/https/unregister.html";
     49      } else if (e.data.status == "unregistrationdone") {
     50        window.onmessage = null;
     51        ok(true, "Test finished successfully");
     52        SimpleTest.finish();
     53      }
     54    };
     55  }
     56 
     57  SimpleTest.waitForExplicitFinish();
     58  onload = function() {
     59    SpecialPowers.pushPrefEnv({"set": [
     60      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     61      ["dom.serviceWorkers.enabled", true],
     62      ["dom.serviceWorkers.testing.enabled", true],
     63    ]}, runTest);
     64  };
     65 </script>
     66 </pre>
     67 </body>
     68 </html>