tor-browser

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

test_cache_restart.html (2056B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2   - http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!DOCTYPE HTML>
      4 <html>
      5 <head>
      6  <title>Test Cache with QuotaManager Restart</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <script class="testbody" type="text/javascript">
     12 function setupTestIframe() {
     13  return new Promise(function(resolve) {
     14    var iframe = document.createElement("iframe");
     15    iframe.src = "empty.html";
     16    iframe.onload = function() {
     17      window.caches = iframe.contentWindow.caches;
     18      resolve();
     19    };
     20    document.body.appendChild(iframe);
     21  });
     22 }
     23 
     24 function resetStorage() {
     25  return new Promise(function(resolve) {
     26    var qms = SpecialPowers.Services.qms;
     27    var principal = SpecialPowers.wrap(document).nodePrincipal;
     28    var request = qms.resetStoragesForPrincipal(principal);
     29    var cb = SpecialPowers.wrapCallback(resolve);
     30    request.callback = cb;
     31  });
     32 }
     33 
     34 SimpleTest.waitForExplicitFinish();
     35 SpecialPowers.pushPrefEnv({
     36  "set": [["dom.caches.testing.enabled", true],
     37          ["dom.quotaManager.testing", true]],
     38 }, function() {
     39  var name = "foo";
     40  var url = "./test_cache_add.js";
     41  var cache;
     42  setupTestIframe().then(function() {
     43    return caches.open(name);
     44  }).then(function(c) {
     45    cache = c;
     46    return cache.add(url);
     47  }).then(function() {
     48    return resetStorage();
     49  }).then(function() {
     50    return cache.match(url).then(function() {
     51      ok(false, "old cache reference should not work after reset");
     52    }).catch(function() {
     53      ok(true, "old cache reference should not work after reset");
     54    });
     55  }).then(function() {
     56    return caches.open(name);
     57  }).then(function(c) {
     58    cache = c;
     59    return cache.match(url);
     60  }).then(function(resp) {
     61    ok(!!resp, "cache should work after QM reset");
     62    return caches.delete(name);
     63  }).then(function(success) {
     64    ok(success, "cache should be deleted");
     65    SimpleTest.finish();
     66  });
     67 });
     68 </script>
     69 </body>
     70 </html>